diff --git a/graphql/e2e/common/common.go b/graphql/e2e/common/common.go index 1aa4b854fef..a9ee1e79261 100644 --- a/graphql/e2e/common/common.go +++ b/graphql/e2e/common/common.go @@ -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) diff --git a/graphql/e2e/common/mutation.go b/graphql/e2e/common/mutation.go index a253fcdcb0b..41704e8c32b 100644 --- a/graphql/e2e/common/mutation.go +++ b/graphql/e2e/common/mutation.go @@ -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 { @@ -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) +} diff --git a/graphql/resolve/mutation.go b/graphql/resolve/mutation.go index e17927c220b..77d4267dd51 100644 --- a/graphql/resolve/mutation.go +++ b/graphql/resolve/mutation.go @@ -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{}