diff --git a/graphql/e2e/common/fragment.go b/graphql/e2e/common/fragment.go index 24a9c96c17d..4c566a6c8d3 100644 --- a/graphql/e2e/common/fragment.go +++ b/graphql/e2e/common/fragment.go @@ -568,5 +568,45 @@ func fragmentInQueryOnObject(t *testing.T) { JSONEqGraphQL(t, queryCharacterExpected, string(gqlResponse.Data)) + query2HumanParams := &GraphQLParams{ + Query: `query { + queryHuman() { + id + starships { + id + } + ...HumanFrag + } + } + + fragment HumanFrag on Human { + starships { + ... { + __typename + id + name + length + } + } + }`, + } + gqlResponse2 := query2HumanParams.ExecuteAsPost(t, GraphqlURL) + + RequireNoGQLErrors(t, gqlResponse2) + queryCharacterExpected2 := fmt.Sprintf(` + + {"queryHuman":[ + {"id":"%s", + "starships":[ + {"id":"%s", + "__typename":"Starship", + "name":"Millennium Falcon", + "length":2.000000}] + } + ] + } + `, humanID, newStarship.ID) + JSONEqGraphQL(t, queryCharacterExpected2, string(gqlResponse2.Data)) + cleanupStarwars(t, newStarship.ID, humanID, "") } diff --git a/graphql/schema/request.go b/graphql/schema/request.go index 385ad3edd79..5ccdf242501 100644 --- a/graphql/schema/request.go +++ b/graphql/schema/request.go @@ -203,6 +203,9 @@ func recursivelyExpandFragmentSelections(field *ast.Field, op *operation) { }, field.SelectionSet, satisfies) field.SelectionSet = make([]ast.Selection, 0, len(collectedFields)) for _, collectedField := range collectedFields { + if len(collectedField.Selections) > 0 { + collectedField.Field.SelectionSet = collectedField.Selections + } field.SelectionSet = append(field.SelectionSet, collectedField.Field) }