Skip to content

Commit

Permalink
Fix hydration of boundaries with abstract types (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasmarshall authored Apr 7, 2024
1 parent 7ed8d32 commit b1184fe
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
3 changes: 2 additions & 1 deletion lib/graphql/stitching/supergraph.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def from_definition(schema, executables:)
kwargs = directive.arguments.keyword_arguments
boundary_map[type_name] ||= []
boundary_map[type_name] << Boundary.new(
type_name: type_name,
type_name: kwargs.fetch(:type_name, type_name),
location: kwargs[:location],
key: kwargs[:key],
field: kwargs[:field],
Expand Down Expand Up @@ -134,6 +134,7 @@ def to_definition
end

type.directive(ResolverDirective, **{
type_name: (boundary.type_name if boundary.type_name != type_name),
location: boundary.location,
key: boundary.key,
field: boundary.field,
Expand Down
1 change: 1 addition & 0 deletions lib/graphql/stitching/supergraph/resolver_directive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class Supergraph
class ResolverDirective < GraphQL::Schema::Directive
graphql_name "resolver"
locations OBJECT, INTERFACE, UNION
argument :type_name, String, required: false
argument :location, String, required: true
argument :key, String, required: true
argument :field, String, required: true
Expand Down
14 changes: 9 additions & 5 deletions test/graphql/stitching/supergraph_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,9 @@ def test_route_type_to_locations_returns_nil_for_unreachable_locations
describe "#to_definition / #from_definition" do
def setup
alpha = %|
type T { id:ID! a:String }
type Query { a(id:ID!):T @stitch(key: "id") }
type T implements A { id:ID! a:String }
interface A { id:ID! }
type Query { a(id:ID!):A @stitch(key: "id") }
|
bravo = %|
type T { id:ID! b:String }
Expand All @@ -331,13 +332,16 @@ def test_to_definition_annotates_schema
assert @schema_sdl.include?("directive @resolver")
assert @schema_sdl.include?("directive @source")
assert @schema_sdl.include?(squish_string(%|
type T @resolver(location: "alpha", key: "id", field: "a", arg: "id")
@resolver(location: "bravo", key: "id", field: "b", arg: "id") {
interface A @resolver(location: "alpha", key: "id", field: "a", arg: "id") {
|))
assert @schema_sdl.include?(squish_string(%|
type T implements A @resolver(location: "bravo", key: "id", field: "b", arg: "id")
@resolver(typeName: "A", location: "alpha", key: "id", field: "a", arg: "id") {
|))
assert @schema_sdl.include?(%|id: ID! @source(location: "alpha") @source(location: "bravo")|)
assert @schema_sdl.include?(%|a: String @source(location: "alpha")|)
assert @schema_sdl.include?(%|b: String @source(location: "bravo")|)
assert @schema_sdl.include?(%|a(id: ID!): T @source(location: "alpha")|)
assert @schema_sdl.include?(%|a(id: ID!): A @source(location: "alpha")|)
assert @schema_sdl.include?(%|b(id: ID!): T @source(location: "bravo")|)
end

Expand Down

0 comments on commit b1184fe

Please sign in to comment.