Skip to content

Commit

Permalink
shrink diff.
Browse files Browse the repository at this point in the history
  • Loading branch information
gmac committed Nov 5, 2021
1 parent 463d678 commit 3d74958
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 6 additions & 0 deletions plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ func extractSelectionSet(ctx *PlanningContext, insertionPoint []string, parentTy
if err != nil {
return nil, nil, err
}
if !selectionSetHasFieldNamed(selectionSet, "__typename") {
selectionSet = append(selectionSet, &ast.Field{Alias: "__typename", Name: "__typename", Definition: &ast.FieldDefinition{Name: "__typename", Type: ast.NamedType("String", nil)}})
}
inlineFragment := *selection
inlineFragment.SelectionSet = selectionSet
selectionSetResult = append(selectionSetResult, &inlineFragment)
Expand All @@ -190,6 +193,9 @@ func extractSelectionSet(ctx *PlanningContext, insertionPoint []string, parentTy
if err != nil {
return nil, nil, err
}
if !selectionSetHasFieldNamed(selectionSet, "__typename") {
selectionSet = append(selectionSet, &ast.Field{Alias: "__typename", Name: "__typename", Definition: &ast.FieldDefinition{Name: "__typename", Type: ast.NamedType("String", nil)}})
}
inlineFragment := ast.InlineFragment{
TypeCondition: selection.Definition.TypeCondition,
SelectionSet: selectionSet,
Expand Down
10 changes: 5 additions & 5 deletions plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func TestQueryPlanInlineFragment(t *testing.T) {
{
"ServiceURL": "A",
"ParentType": "Query",
"SelectionSet": "{ movies { ... on Movie { id title(language: French) } } }",
"SelectionSet": "{ movies { ... on Movie { id title(language: French) __typename } } }",
"InsertionPoint": null,
"Then": null
}
Expand Down Expand Up @@ -314,7 +314,7 @@ func TestQueryPlanInlineFragmentPlan(t *testing.T) {
{
"ServiceURL": "A",
"ParentType": "Query",
"SelectionSet": "{ movies { _id: id ... on Movie { id title(language: French) } } }",
"SelectionSet": "{ movies { _id: id ... on Movie { id title(language: French) __typename } } }",
"InsertionPoint": null,
"Then": [
{
Expand Down Expand Up @@ -347,7 +347,7 @@ func TestQueryPlanFragmentSpread1(t *testing.T) {
{
"ServiceURL": "A",
"ParentType": "Query",
"SelectionSet": "{ movies { ... on Movie { id title(language: French) } } }",
"SelectionSet": "{ movies { ... on Movie { id title(language: French) __typename } } }",
"InsertionPoint": null,
"Then": null
}
Expand Down Expand Up @@ -634,13 +634,13 @@ func TestQueryPlanSupportsAliasing(t *testing.T) {
}

func TestQueryPlanSupportsUnions(t *testing.T) {
PlanTestFixture4.Check(t, "{ animals { ... on Dog { name } ... on Cat { name } ... on Snake { name } } }", `
PlanTestFixture4.Check(t, "{ animals { ... on Dog { name } ... on Cat { name } ... on Snake { name } } }", `
{
"RootSteps": [
{
"ServiceURL": "A",
"ParentType": "Query",
"SelectionSet": "{ animals { ... on Dog { name } ... on Cat { name } ... 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 3d74958

Please sign in to comment.