Skip to content

Commit a7ed440

Browse files
committed
Fix indirect interface implementation from SDL
1 parent 821ca53 commit a7ed440

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

lib/graphql/schema/addition.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ def update_type_owner(owner, type)
107107
if !pt.include?(owner) && owner.is_a?(Class)
108108
pt << owner
109109
end
110+
int.interfaces.each do |indirect_int|
111+
if indirect_int.is_a?(LateBoundType) && (indirect_int_type = get_type(indirect_int.graphql_name))
112+
update_type_owner(owner, indirect_int_type)
113+
end
114+
end
110115
end
111116
end
112117
when nil

spec/graphql/schema/build_from_definition_spec.rb

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,4 +1525,44 @@ def self.parse(string)
15251525
assert_equal expected_definition, schema.to_definition, "UnreachableType is excluded"
15261526
end
15271527
end
1528+
1529+
it "works with indirect interface implementation" do
1530+
schema_string = <<~GRAPHQL
1531+
type Query {
1532+
entities: [Entity!]!
1533+
person: Person
1534+
}
1535+
1536+
type Person implements NamedEntity {
1537+
id: ID!
1538+
name: String
1539+
nationality: String
1540+
}
1541+
1542+
type Product implements NamedEntity {
1543+
id: ID!
1544+
name: String
1545+
amount: Int
1546+
}
1547+
1548+
interface NamedEntity implements Entity {
1549+
id: ID!
1550+
name: String
1551+
}
1552+
1553+
type Payment implements Entity {
1554+
id: ID!
1555+
amount: Int
1556+
}
1557+
1558+
interface Entity {
1559+
id: ID!
1560+
}
1561+
GRAPHQL
1562+
1563+
schema = GraphQL::Schema.from_definition(schema_string)
1564+
1565+
assert_equal ["amount", "id"], schema.types.fetch("Payment").fields.keys.sort
1566+
assert_equal ["id", "name", "nationality"], schema.types.fetch("Person").fields.keys.sort
1567+
end
15281568
end

0 commit comments

Comments
 (0)