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): fixes panic in update mutation without set & remove (#6073) #6160

Merged
merged 1 commit into from
Aug 11, 2020
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 @@ -313,6 +313,7 @@ func RunAll(t *testing.T) {
t.Run("mutations have extensions", mutationsHaveExtensions)
t.Run("alias works for mutations", mutationsWithAlias)
t.Run("three level deep", threeLevelDeepMutation)
t.Run("update mutation without set & remove", updateMutationWithoutSetRemove)

// error tests
t.Run("graphql completion on", graphQLCompletionOn)
Expand Down
30 changes: 29 additions & 1 deletion graphql/e2e/common/mutation.go
Original file line number Diff line number Diff line change
Expand Up @@ -2908,7 +2908,6 @@ func threeLevelDeepMutation(t *testing.T) {
}

gqlResponse := postExecutor(t, graphqlURL, addStudentParams)
fmt.Println(string(gqlResponse.Data))
RequireNoGQLErrors(t, gqlResponse)

var actualResult struct {
Expand Down Expand Up @@ -3175,3 +3174,32 @@ func mutationsWithAlias(t *testing.T) {

require.JSONEq(t, multiMutationExpected, string(gqlResponse.Data))
}

func updateMutationWithoutSetRemove(t *testing.T) {
country := addCountry(t, postExecutor)

updateCountryParams := &GraphQLParams{
Query: `mutation updateCountry($id: ID!){
updateCountry(input: {filter: {id: [$id]}}) {
numUids
country {
id
name
}
}
}`,
Variables: map[string]interface{}{"id": country.ID},
}
gqlResponse := updateCountryParams.ExecuteAsPost(t, graphqlURL)
RequireNoGQLErrors(t, gqlResponse)

require.JSONEq(t, `{
"updateCountry": {
"numUids": 0,
"country": []
}
}`, string(gqlResponse.Data))

// cleanup
deleteCountry(t, map[string]interface{}{"id": []string{country.ID}}, 1, nil)
}
12 changes: 12 additions & 0 deletions graphql/resolve/mutation.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,18 @@ func (mr *dgraphResolver) rewriteAndExecute(ctx context.Context,
return emptyResult(schema.GQLWrapf(err, "couldn't rewrite mutation %s", mutation.Name())),
resolverFailed
}
if len(upserts) == 0 {
return &Resolved{
Data: map[string]interface{}{
mutation.Name(): map[string]interface{}{
schema.NumUid: 0,
mutation.QueryField().Name(): nil,
}},
Field: mutation,
Err: nil,
Extensions: ext,
}, resolverSucceeded
}

result := make(map[string]interface{})
req := &dgoapi.Request{}
Expand Down