Skip to content

Commit

Permalink
Merge pull request #91 from gmac/abstract-typename-hints
Browse files Browse the repository at this point in the history
Always add __typename to abstract types
  • Loading branch information
Nicolas Maquet authored Nov 8, 2021
2 parents 265237f + 2c776bd commit ea63dca
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
.vscode
.history
.idea
.DS_Store
coverage.out
5 changes: 5 additions & 0 deletions plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,11 @@ func extractSelectionSet(ctx *PlanningContext, insertionPoint []string, parentTy
break
}
}
selectionSetResult = append(selectionSetResult, &ast.Field{
Alias: "__typename",
Name: "__typename",
Definition: &ast.FieldDefinition{Name: "__typename", Type: ast.NamedType("String", nil)},
})
// Otherwise, add an id selection to boundary types where the result
// will be merged with another step (i.e.: has children or is a child step).
} else if parentType != queryObjectName &&
Expand Down
4 changes: 3 additions & 1 deletion plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ func TestQueryPlanExpandAbstractTypesWithPossibleBoundaryIds(t *testing.T) {
"name",
"... on Lion { _id: id }",
"... on Snake { _id: id }",
"__typename",
}
PlanTestFixture3.CheckUnorderedRootFieldSelections(t, query, rootFieldSelections)
}
Expand All @@ -519,6 +520,7 @@ func TestQueryPlanInlineFragmentSpreadOfInterface(t *testing.T) {
"... on Snake { _id: id }",
"... on Lion { maneColor __typename }",
"... on Snake { _id: id __typename }",
"__typename",
}
PlanTestFixture3.CheckUnorderedRootFieldSelections(t, query, rootFieldSelections)
}
Expand Down Expand Up @@ -638,7 +640,7 @@ func TestQueryPlanSupportsUnions(t *testing.T) {
{
"ServiceURL": "A",
"ParentType": "Query",
"SelectionSet": "{ animals { ... on Dog { name __typename } ... on Cat { name __typename } ... on Snake { name __typename } } }",
"SelectionSet": "{ animals { ... on Dog { name __typename } ... on Cat { name __typename } ... on Snake { name __typename } __typename } }",
"InsertionPoint": null,
"Then": null
}
Expand Down

0 comments on commit ea63dca

Please sign in to comment.