Skip to content

Commit

Permalink
fix: inherit Query type from schema superclass (Gusto#241)
Browse files Browse the repository at this point in the history
  • Loading branch information
jturkel authored and Kaytal committed Oct 1, 2024
1 parent 0a4234f commit 957115d
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/apollo-federation/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def query(new_query_object = nil)
@orig_query_object = new_query_object
else
if !@federation_query_object
@federation_query_object = federation_query(@orig_query_object)
@federation_query_object = federation_query(original_query)
@federation_query_object.define_entities_field(schema_entities)

super(@federation_query_object)
Expand All @@ -58,6 +58,10 @@ def query(new_query_object = nil)

private

def original_query
@orig_query_object || find_inherited_value(:original_query)
end

def federation_preamble
federation_namespace = ", as: \"#{link_namespace}\"" if link_namespace != DEFAULT_LINK_NAMESPACE

Expand Down
33 changes: 33 additions & 0 deletions spec/apollo-federation/service_field_v1_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,39 @@ def self.visible?(context)
)
end

it 'returns SDL that inherits the query type' do
product = Class.new(base_object) do
graphql_name 'Product'
extend_type

field :upc, String, null: false
end

query_obj = Class.new(base_object) do
graphql_name 'Query'

field :product, product, null: true
end

new_base_schema = Class.new(base_schema) do
query query_obj
end

schema = Class.new(new_base_schema)

expect(execute_sdl(schema)).to match_sdl(
<<~GRAPHQL,
type Product @extends {
upc: String!
}
type Query {
product: Product
}
GRAPHQL
)
end

context 'with context in schema generation' do
let(:schema) do
product = Class.new(base_object) do
Expand Down
37 changes: 37 additions & 0 deletions spec/apollo-federation/service_field_v2_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1946,6 +1946,43 @@ def self.visible?(context)
)
end

it 'returns SDL that inherits the query type' do
product = Class.new(base_object) do
graphql_name 'Product'
extend_type

field :upc, String, null: false
end

query_obj = Class.new(base_object) do
graphql_name 'Query'

field :product, product, null: true
end

new_base_schema = Class.new(base_schema) do
federation version: '2.0', link: { as: 'fed2' }
query query_obj
end

schema = Class.new(new_base_schema)

expect(execute_sdl(schema)).to match_sdl(
<<~GRAPHQL,
extend schema
@link(url: "https://specs.apollo.dev/federation/v2.3", as: "fed2", import: ["@inaccessible", "@tag"])
type Product @fed2__extends {
upc: String!
}
type Query {
product: Product
}
GRAPHQL
)
end

context 'with context in schema generation' do
let(:schema) do
product = Class.new(base_object) do
Expand Down

0 comments on commit 957115d

Please sign in to comment.