def should_detect_if_a_type_was_added_to_a_union_type(): old_schema = build_schema( """ type Type1 type Type2 union UnionType1 = Type1 """ ) new_schema = build_schema( """ type Type1 type Type2 union UnionType1 = Type1 | Type2 """ ) assert find_dangerous_changes(old_schema, new_schema) == [ ( DangerousChangeType.TYPE_ADDED_TO_UNION, "Type2 was added to union type UnionType1.", ) ]
def should_ignore_changes_in_field_order_of_default_value(): old_schema = build_schema(""" input Input1 { a: String b: String c: String } type Type1 { field1( arg1: Input1 = { a: "a", b: "b", c: "c" } ): String } """) new_schema = build_schema(""" input Input1 { a: String b: String c: String } type Type1 { field1( arg1: Input1 = { c: "c", b: "b", a: "a" } ): String } """) assert find_dangerous_changes(old_schema, new_schema) == []
def should_detect_interfaces_added_to_interfaces(): old_schema = build_schema( """ interface OldInterface interface NewInterface interface Interface1 implements OldInterface """ ) new_schema = build_schema( """ interface OldInterface interface NewInterface interface Interface1 implements OldInterface & NewInterface """ ) assert find_dangerous_changes(old_schema, new_schema) == [ ( DangerousChangeType.IMPLEMENTED_INTERFACE_ADDED, "NewInterface added to interfaces implemented by Interface1.", ) ]
def should_detect_if_a_value_was_added_to_an_enum_type(): old_schema = build_schema( """ enum EnumType1 { VALUE0 VALUE1 } """ ) new_schema = build_schema( """ enum EnumType1 { VALUE0 VALUE1 VALUE2 } """ ) assert find_dangerous_changes(old_schema, new_schema) == [ ( DangerousChangeType.VALUE_ADDED_TO_ENUM, "VALUE2 was added to enum type EnumType1.", ) ]
def should_find_all_dangerous_changes(): old_schema = build_schema( """ enum EnumType1 { VALUE0 VALUE1 } type Type1 { field1(argThatChangesDefaultValue: String = "test"): String } interface Interface1 type TypeThatGainsInterface1 type TypeInUnion1 union UnionTypeThatGainsAType = TypeInUnion1 """ ) new_schema = build_schema( """ enum EnumType1 { VALUE0 VALUE1 VALUE2 } type Type1 { field1(argThatChangesDefaultValue: String = "Test"): String } interface Interface1 type TypeThatGainsInterface1 implements Interface1 type TypeInUnion1 type TypeInUnion2 union UnionTypeThatGainsAType = TypeInUnion1 | TypeInUnion2 """ ) assert find_dangerous_changes(old_schema, new_schema) == [ ( DangerousChangeType.TYPE_ADDED_TO_UNION, "TypeInUnion2 was added to union type UnionTypeThatGainsAType.", ), ( DangerousChangeType.VALUE_ADDED_TO_ENUM, "VALUE2 was added to enum type EnumType1.", ), ( DangerousChangeType.ARG_DEFAULT_VALUE_CHANGE, "Type1.field1 arg argThatChangesDefaultValue has changed defaultValue.", ), ( DangerousChangeType.INTERFACE_ADDED_TO_OBJECT, "Interface1 added to interfaces implemented" " by TypeThatGainsInterface1.", ), ]
def should_detect_if_an_optional_field_argument_was_added(): old_schema = build_schema(""" type Type1 { field1(arg1: String): String } """) new_schema = build_schema(""" type Type1 { field1(arg1: String, arg2: String): String } """) assert find_dangerous_changes(old_schema, new_schema) == [( DangerousChangeType.OPTIONAL_ARG_ADDED, "An optional arg arg2 on Type1.field1 was added.", )]
def should_detect_if_an_optional_field_was_added_to_an_input(): old_schema = build_schema(""" input InputType1 { field1: String } """) new_schema = build_schema(""" input InputType1 { field1: String field2: Int } """) assert find_dangerous_changes(old_schema, new_schema) == [( DangerousChangeType.OPTIONAL_INPUT_FIELD_ADDED, "An optional field field2 on input type InputType1 was added.", )]
def should_detect_if_an_arguments_default_value_has_changed(): old_schema = build_schema( """ type Type1 { field1(name: String = "test"): String } """ ) new_schema = build_schema( """ type Type1 { field1(name: String = "Test"): String } """ ) assert find_dangerous_changes(old_schema, new_schema) == [ ( DangerousChangeType.ARG_DEFAULT_VALUE_CHANGE, "Type1.field1 arg name has changed defaultValue.", ) ]
def should_detect_if_a_default_value_changed_on_an_argument(): old_sdl = """ input Input1 { innerInputArray: [Input2] } input Input2 { arrayField: [Int] } type Type1 { field1( withDefaultValue: String = "TO BE DELETED" stringArg: String = "test" emptyArray: [Int!] = [] valueArray: [[String]] = [["a", "b"], ["c"]] complexObject: Input1 = { innerInputArray: [{ arrayField: [1, 2, 3] }] } ): String } """ old_schema = build_schema(old_sdl) copy_of_old_schema = build_schema(old_sdl) assert find_dangerous_changes(old_schema, copy_of_old_schema) == [] new_schema = build_schema(""" input Input1 { innerInputArray: [Input2] } input Input2 { arrayField: [Int] } type Type1 { field1( withDefaultValue: String stringArg: String = "Test" emptyArray: [Int!] = [7] valueArray: [[String]] = [["b", "a"], ["d"]] complexObject: Input1 = { innerInputArray: [{ arrayField: [3, 2, 1] }] } ): String } """) assert find_dangerous_changes(old_schema, new_schema) == [ ( DangerousChangeType.ARG_DEFAULT_VALUE_CHANGE, "Type1.field1 arg withDefaultValue defaultValue was removed.", ), ( DangerousChangeType.ARG_DEFAULT_VALUE_CHANGE, "Type1.field1 arg stringArg has changed defaultValue" ' from "test" to "Test".', ), ( DangerousChangeType.ARG_DEFAULT_VALUE_CHANGE, "Type1.field1 arg emptyArray has changed defaultValue from [] to [7].", ), ( DangerousChangeType.ARG_DEFAULT_VALUE_CHANGE, "Type1.field1 arg valueArray has changed defaultValue" ' from [["a", "b"], ["c"]] to [["b", "a"], ["d"]].', ), ( DangerousChangeType.ARG_DEFAULT_VALUE_CHANGE, "Type1.field1 arg complexObject has changed defaultValue" " from {innerInputArray: [{arrayField: [1, 2, 3]}]}" " to {innerInputArray: [{arrayField: [3, 2, 1]}]}.", ), ]
def should_find_all_dangerous_changes(): old_schema = build_schema(""" enum EnumType1 { VALUE0 VALUE1 } type Type1 { field1(name: String = "test"): String } type TypeThatGainsInterface1 { field1: String } type TypeInUnion1 { field1: String } union UnionTypeThatGainsAType = TypeInUnion1 type Query { field1: String } """) new_schema = build_schema(""" enum EnumType1 { VALUE0 VALUE1 VALUE2 } interface Interface1 { field1: String } type TypeThatGainsInterface1 implements Interface1 { field1: String } type Type1 { field1(name: String = "Test"): String } type TypeInUnion1 { field1: String } type TypeInUnion2 { field1: String } union UnionTypeThatGainsAType = TypeInUnion1 | TypeInUnion2 type Query { field1: String } """) expected_dangerous_changes = [ (DangerousChangeType.ARG_DEFAULT_VALUE_CHANGE, 'Type1.field1 arg name has changed defaultValue'), (DangerousChangeType.VALUE_ADDED_TO_ENUM, 'VALUE2 was added to enum type EnumType1.'), (DangerousChangeType.INTERFACE_ADDED_TO_OBJECT, 'Interface1 added to interfaces implemented' ' by TypeThatGainsInterface1.'), (DangerousChangeType.TYPE_ADDED_TO_UNION, 'TypeInUnion2 was added to union type UnionTypeThatGainsAType.') ] assert find_dangerous_changes(old_schema, new_schema) == expected_dangerous_changes