Skip to content

Commit

Permalink
Fix fragment elimination checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucian Jones committed Sep 30, 2021
1 parent 5a9eca0 commit ee3f3d8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
24 changes: 23 additions & 1 deletion execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,28 @@ func TestFederatedQueryFragmentSpreads(t *testing.T) {
f.checkSuccess(t)
})

t.Run("with non abstract fragment", func(t *testing.T) {
f := &queryExecutionFixture{
services: []testService{serviceA, serviceB},
query: `
query Foo {
snapshot(id: "GIZMO1") {
... on Snapshot {
name
}
}
}`,
expected: `
{
"snapshot": {
"name": "foo"
}
}`,
}

f.checkSuccess(t)
})

t.Run("with named fragment spread", func(t *testing.T) {
f := &queryExecutionFixture{
services: []testService{serviceA, serviceB},
Expand Down Expand Up @@ -1029,7 +1051,7 @@ func TestQueryExecutionNamespaceAndFragmentSpread(t *testing.T) {
"movies": [
{"title": "The Big Blue"}
],
"__typename": "Person"
"__typename": "Director"
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions query_execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ func buildTypenameResponseMap(selectionSet ast.SelectionSet, parentTypeName stri
return result, nil
}

func fragmentImplementsAbstractType(schema *ast.Schema, fragmentTypeDefinition, abstractObjectTypename string) bool {
func fragmentImplementsAbstractType(schema *ast.Schema, abstractObjectTypename, fragmentTypeDefinition string) bool {
for _, def := range schema.Implements[fragmentTypeDefinition] {
if def.Name == abstractObjectTypename {
return true
Expand Down Expand Up @@ -849,7 +849,7 @@ func unionAndTrimSelectionSetRec(objectTypename string, schema *ast.Schema, sele
}

if fragment.ObjectDefinition.IsAbstractType() &&
fragmentImplementsAbstractType(schema, objectTypename, fragment.ObjectDefinition.Name) &&
fragmentImplementsAbstractType(schema, fragment.ObjectDefinition.Name, fragment.TypeCondition) &&
objectTypenameMatchesDifferentFragment(objectTypename, fragment) {
continue
}
Expand Down

0 comments on commit ee3f3d8

Please sign in to comment.