Skip to content

Commit

Permalink
fix(fragment): merge the nested fragments fields (#8075) (#8435)
Browse files Browse the repository at this point in the history
<!--
 Change Github PR Title 

 Your title must be in the following format: 
 - `topic(Area): Feature`
- `Topic` must be one of
`build|ci|docs|feat|fix|perf|refactor|chore|test`

 Sample Titles:
 - `feat(Enterprise)`: Backups can now get credentials from IAM
 - `fix(Query)`: Skipping floats that cannot be Marshalled in JSON
 - `perf: [Breaking]` json encoding is now 35% faster if SIMD is present
 - `chore`: all chores/tests will be excluded from the CHANGELOG
 -->

## Problem
Fixes
https://discuss.dgraph.io/t/graphql-field-collection-does-not-work-with-dgraph/15646
 <!--
 Please add a description with these things:
 1. Explain the problem by providing a good description.
 2. If it fixes any GitHub issues, say "Fixes #GitHubIssue".
 3. If it corresponds to a Jira issue, say "Fixes DGRAPH-###".
4. If this is a breaking change, please prefix `[Breaking]` in the
title. In the description, please put a note with exactly who these
changes are breaking for.
 -->

## Solution
 <!--
 Please add a description with these things:
 1. Explain the solution to make it easier to review the PR.
2. Make it easier for the reviewer by describing complex sections with
comments.
 -->

Co-authored-by: Naman Jain <naman@dgraph.io>
  • Loading branch information
dshekhar95 and NamanJain8 authored Nov 23, 2022
1 parent 4f3420d commit 409d30c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
40 changes: 40 additions & 0 deletions graphql/e2e/common/fragment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "")
}
3 changes: 3 additions & 0 deletions graphql/schema/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit 409d30c

Please sign in to comment.