Exemplo n.º 1
0
    def should_detect_if_a_required_field_is_added_to_an_input_type():
        old_schema = build_schema("""
            input InputType1 {
              field1: String
            }

            type Query {
              field1: String
            }
            """)

        new_schema = build_schema("""
            input InputType1 {
                field1: String
                requiredField: Int!
                optionalField1: Boolean
                optionalField2: Boolean! = false
            }

            type Query {
                field1: String
            }
            """)

        assert find_fields_that_changed_type_on_input_object_types(
            old_schema, new_schema
        ).breaking_changes == [(
            BreakingChangeType.REQUIRED_INPUT_FIELD_ADDED,
            "A required field requiredField on input type InputType1 was added.",
        )]
Exemplo n.º 2
0
    def should_detect_if_a_nullable_field_was_added_to_an_input():
        old_schema = build_schema("""
            input InputType1 {
                field1: String
            }

            type Query {
                field1: String
            }
            """)

        new_schema = build_schema("""
            input InputType1 {
              field1: String
              field2: Int
            }

            type Query {
              field1: String
            }
            """)

        expected_field_changes = [
            (DangerousChangeType.NULLABLE_INPUT_FIELD_ADDED,
             'A nullable field field2 on input type InputType1 was added.')
        ]

        assert find_fields_that_changed_type_on_input_object_types(
            old_schema, new_schema).dangerous_changes == expected_field_changes
Exemplo n.º 3
0
    def should_detect_if_an_optional_field_was_added_to_an_input():
        old_schema = build_schema("""
            input InputType1 {
                field1: String
            }

            type Query {
                field1: String
            }
            """)

        new_schema = build_schema("""
            input InputType1 {
              field1: String
              field2: Int
            }

            type Query {
              field1: String
            }
            """)

        assert find_fields_that_changed_type_on_input_object_types(
            old_schema, new_schema).dangerous_changes == [(
                DangerousChangeType.OPTIONAL_INPUT_FIELD_ADDED,
                "An optional field field2 on input type InputType1 was added.",
            )]
Exemplo n.º 4
0
    def should_detect_if_a_non_null_field_is_added_to_an_input_type():
        old_schema = build_schema("""
            input InputType1 {
              field1: String
            }

            type Query {
              field1: String
            }
            """)

        new_schema = build_schema("""
            input InputType1 {
                field1: String
                requiredField: Int!
                optionalField: Boolean
            }

            type Query {
                field1: String
            }
            """)

        expected_field_changes = [
            (BreakingChangeType.NON_NULL_INPUT_FIELD_ADDED,
             'A non-null field requiredField on input type'
             ' InputType1 was added.')
        ]

        assert find_fields_that_changed_type_on_input_object_types(
            old_schema, new_schema).breaking_changes == expected_field_changes
Exemplo n.º 5
0
    def should_detect_if_fields_on_input_types_changed_kind_or_were_removed():
        old_schema = build_schema("""
            input InputType1 {
              field1: String
              field2: Boolean
              field3: [String]
              field4: String!
              field5: String
              field6: [Int]
              field7: [Int]!
              field8: Int
              field9: [Int]
              field10: [Int!]
              field11: [Int]
              field12: [[Int]]
              field13: Int!
              field14: [[Int]!]
              field15: [[Int]!]
            }

            type Query {
              field1: String
            }""")

        new_schema = build_schema("""
            input InputType1 {
              field1: Int
              field3: String
              field4: String
              field5: String!
              field6: [Int]!
              field7: [Int]
              field8: [Int]!
              field9: [Int!]
              field10: [Int]
              field11: [[Int]]
              field12: [Int]
              field13: [Int]!
              field14: [[Int]]
              field15: [[Int!]!]
            }

            type Query {
              field1: String
            }
            """)

        assert find_fields_that_changed_type_on_input_object_types(
            old_schema, new_schema
        ).breaking_changes == [
            (
                BreakingChangeType.FIELD_CHANGED_KIND,
                "InputType1.field1 changed type from String to Int.",
            ),
            (BreakingChangeType.FIELD_REMOVED,
             "InputType1.field2 was removed."),
            (
                BreakingChangeType.FIELD_CHANGED_KIND,
                "InputType1.field3 changed type from [String] to String.",
            ),
            (
                BreakingChangeType.FIELD_CHANGED_KIND,
                "InputType1.field5 changed type from String to String!.",
            ),
            (
                BreakingChangeType.FIELD_CHANGED_KIND,
                "InputType1.field6 changed type from [Int] to [Int]!.",
            ),
            (
                BreakingChangeType.FIELD_CHANGED_KIND,
                "InputType1.field8 changed type from Int to [Int]!.",
            ),
            (
                BreakingChangeType.FIELD_CHANGED_KIND,
                "InputType1.field9 changed type from [Int] to [Int!].",
            ),
            (
                BreakingChangeType.FIELD_CHANGED_KIND,
                "InputType1.field11 changed type from [Int] to [[Int]].",
            ),
            (
                BreakingChangeType.FIELD_CHANGED_KIND,
                "InputType1.field12 changed type from [[Int]] to [Int].",
            ),
            (
                BreakingChangeType.FIELD_CHANGED_KIND,
                "InputType1.field13 changed type from Int! to [Int]!.",
            ),
            (
                BreakingChangeType.FIELD_CHANGED_KIND,
                "InputType1.field15 changed type from [[Int]!] to [[Int!]!].",
            ),
        ]