Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/graphql/schema/build_from_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ def build(schema_superclass, document, default_resolve:, using: {}, base_types:
# It's possible that this was already loaded by the directives
prev_type = types[definition.name]
if prev_type.nil? || prev_type.is_a?(Schema::LateBoundType)
if definition.is_a?(GraphQL::Language::Nodes::ObjectTypeDefinition) || definition.is_a?(Language::Nodes::InterfaceTypeDefinition)
interface_names = definition.interfaces.map(&:name)
transitive_names = interface_names.map { |n| document.definitions.find { |d| d.respond_to?(:name) && d.name == n }&.interfaces&.map(&:name) }
transitive_names.flatten!
transitive_names.compact!
if !(missing_transitive_interfaces = transitive_names - interface_names).empty?
raise GraphQL::Schema::InvalidDocumentError, "type #{definition.name} is missing one or more transitive interface names: #{missing_transitive_interfaces.join(", ")}. Add them to the type's `implements` list and try again."
end
end

types[definition.name] = build_definition_from_node(definition, type_resolver, default_resolve, base_types)
end
end
Expand Down
27 changes: 25 additions & 2 deletions spec/graphql/schema/build_from_definition_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,29 @@ def assert_schema_and_compare_output(definition)
assert_schema_and_compare_output(schema)
end

it "requires transitive dependencies to be named" do
schema_str = <<~GRAPHQL
interface A implements B {
s: String
}

interface B {
s: String
}

type Query implements A & B {
s: String
}
GRAPHQL

assert_schema_and_compare_output(schema_str)

invalid_schema_str = schema_str.sub("A & B", "A")
assert_raises GraphQL::Schema::InvalidDocumentError do
GraphQL::Schema.from_definition(invalid_schema_str)
end
end

it "supports interfaces that implement interfaces" do
schema = <<-SCHEMA
interface Named implements Node {
Expand Down Expand Up @@ -1542,13 +1565,13 @@ def self.parse(string)
person: Person
}

type Person implements NamedEntity {
type Person implements NamedEntity & Entity {
id: ID!
name: String
nationality: String
}

type Product implements NamedEntity {
type Product implements NamedEntity & Entity {
id: ID!
name: String
amount: Int
Expand Down
Loading