Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(GraphQL): fix lambda querying a lambda field in case of no data. #7610

Merged
merged 4 commits into from
Mar 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions graphql/e2e/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,7 @@ func RunAll(t *testing.T) {
t.Run("lambda on interface field", lambdaOnInterfaceField)
t.Run("lambda on query using dql", lambdaOnQueryUsingDql)
t.Run("lambda on mutation using graphql", lambdaOnMutationUsingGraphQL)
t.Run("lambda on query with no unique parents", lambdaOnQueryWithNoUniqueParents)
t.Run("query lambda field in a mutation with duplicate @id", lambdaInMutationWithDuplicateId)
t.Run("lambda with apollo federation", lambdaWithApolloFederation)
}
Expand Down
18 changes: 18 additions & 0 deletions graphql/e2e/common/lambda.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,24 @@ func lambdaOnMutationUsingGraphQL(t *testing.T) {
deleteAuthors(t, []string{addResp.AuthorID}, nil)
}

func lambdaOnQueryWithNoUniqueParents(t *testing.T) {
queryBookParams := &GraphQLParams{Query: `
query{
getBook(bookId: 1){
name
desc
summary
}
}
`}

resp := queryBookParams.ExecuteAsPost(t, GraphqlURL)
RequireNoGQLErrors(t, resp)
testutil.CompareJSON(t, `{
"getBook": null
}`, string(resp.Data))
}

// See: https://discuss.dgraph.io/t/slash-graphql-lambda-bug/12233
func lambdaInMutationWithDuplicateId(t *testing.T) {
addStudentParams := &GraphQLParams{Query: `
Expand Down
6 changes: 5 additions & 1 deletion query/outputnode_graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ func (genc *graphQLEncoder) processCustomFields(field gqlSchema.Field, n fastJso
// * a linear search to find the correct fastJson node for a custom field, or
// * first fix the order of custom fastJson nodes and then continue the encoding, or
// * create a map from custom fastJson node attr to the custom fastJson node,
// so that whenever a custom field in encountered in the selection set,
// so that whenever a custom field is encountered in the selection set,
// just use the map to find out the fastJson node for that field.
// The last option seems better.

Expand Down Expand Up @@ -836,6 +836,10 @@ func (genc *graphQLEncoder) resolveCustomField(childField gqlSchema.Field,
}
}

if len(uniqueParents) == 0 {
return
}

switch fconf.Mode {
case gqlSchema.SINGLE:
// In SINGLE mode, we can consider steps 2-5 as a single isolated unit of computation,
Expand Down