Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add supports for Type extention ("extend type" syntax) #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
14 changes: 13 additions & 1 deletion lib/graphql/autotest/query_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,20 @@ def generate
end

private def type_definition(name)
document.definitions.find { |f| f.name == name }
defs = document.definitions.select { |f| f.name == name }
return defs.first if defs.size <= 1

MergedDefinition.new(name, defs.flat_map(&:fields))
end
end

class MergedDefinition
attr_reader :name, :fields
def initialize(name, fields)
@name = name
@fields = fields
end
end
private_constant :MergedDefinition
end
end
24 changes: 24 additions & 0 deletions test/graphql/autotest/query_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,30 @@ def test_sub_field_argument_schema
GRAPHQL
end

def test_extended_type_schema
schema = <<~GRAPHQL
type Item {
title: String!
}
extend type Item {
price: Int!
}
type Query {
item: Item!
}
GRAPHQL
document = GraphQL::parse(schema)
fields = GraphQL::Autotest::QueryGenerator.generate(document: document)

assert_query [<<~GRAPHQL, '__typename'], fields
item {
price
title
__typename
}
GRAPHQL
end

private def generate(schema:, **kw)
GraphQL::Autotest::QueryGenerator.generate(document: schema.to_document, **kw)
end
Expand Down