diff --git a/lib/graphql/schema_comparator/diff/schema.rb b/lib/graphql/schema_comparator/diff/schema.rb index 1e9043d..f99b763 100644 --- a/lib/graphql/schema_comparator/diff/schema.rb +++ b/lib/graphql/schema_comparator/diff/schema.rb @@ -17,8 +17,8 @@ def diff changes = [] # Removed and Added Types - changes += removed_types.map { |type| Changes::TypeRemoved.new(type) } - changes += added_types.map { |type| Changes::TypeAdded.new(type) } + removed_types.each { |type| changes += changes_in_removed_type(type) } + added_types.each { |type| changes += changes_in_added_type(type) } # Type Diff for common types each_common_type do |old_type, new_type| @@ -34,6 +34,22 @@ def diff changes end + def changes_in_added_type(type) + changes = [Changes::TypeAdded.new(type)] + if type.graphql_definition.is_a?(GraphQL::ObjectType) + type.interfaces.each do |interface| + if old_types[interface.graphql_name] + changes << Changes::ObjectTypeInterfaceAdded.new(interface, type) + end + end + end + changes + end + + def changes_in_removed_type(type) + [Changes::TypeRemoved.new(type)] + end + def changes_in_type(old_type, new_type) changes = [] diff --git a/test/lib/graphql/schema_comparator/diff/schema_test.rb b/test/lib/graphql/schema_comparator/diff/schema_test.rb index 83c23d2..ae23d12 100644 --- a/test/lib/graphql/schema_comparator/diff/schema_test.rb +++ b/test/lib/graphql/schema_comparator/diff/schema_test.rb @@ -109,6 +109,13 @@ def setup type WithInterfaces implements AnInterface { a: String! } + interface ANewInterface { + c: Int + } + type AnotherWithInterfaces implements AnInterface, ANewInterface { + interfaceField: Int! + c: Int + } type WithArguments { a( # Description for a @@ -175,6 +182,9 @@ def test_changes_kitchensink "Field `b` was added to object type `AnotherInterface`", "`WithInterfaces` object type no longer implements `AnotherInterface` interface", "Field `anotherInterfaceField` was removed from object type `WithInterfaces`", + "Type `ANewInterface` was added", + "Type `AnotherWithInterfaces` was added", + "`AnotherWithInterfaces` object implements `AnInterface` interface", "Description for argument `a` on field `WithArguments.a` changed from `Meh` to `Description for a`", "Type for argument `b` on field `WithArguments.a` changed from `String` to `String!`", "Default value for argument `arg` on field `WithArguments.b` changed from `1` to `2`", @@ -192,7 +202,7 @@ def test_changes_kitchensink "Argument `willBeRemoved` was removed from directive `yolo`", "Description for argument `someArg` on directive `yolo` changed from `Included when true.` to `someArg does stuff`", "Type for argument `someArg` on directive `yolo` changed from `Boolean!` to `String!`", - ].sort, @differ.diff.map(&:message).sort + ].sort.join("\n"), @differ.diff.map(&:message).sort.join("\n") assert_equal [ "WillBeRemoved", @@ -220,6 +230,9 @@ def test_changes_kitchensink "AnotherInterface.b", "WithInterfaces", "WithInterfaces.anotherInterfaceField", + "ANewInterface", + "AnotherWithInterfaces", + "AnotherWithInterfaces", "WithArguments.a.a", "WithArguments.a.b", "WithArguments.b.arg", @@ -238,6 +251,6 @@ def test_changes_kitchensink "@yolo.someArg", "@yolo.someArg", "@yolo.anotherArg", - ].sort, @differ.diff.map(&:path).sort + ].sort.join("\n"), @differ.diff.map(&:path).sort.join("\n") end end