{"record":{"id":"b21af3a19481a1bf","repo":"dgraph-io/dgraph","slug":"not-able-to-find-set-args-in-update-mutation","errorCode":null,"errorMessage":"not able to find set args in update mutation","messagePattern":"not able to find set args in update mutation","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"graphql/resolve/mutation.go","lineNumber":439,"sourceCode":"\t\text.TouchedUids += mutResp.GetMetrics().GetNumUids()[touchedUidsKey]\n\t\tif req.Query != \"\" && len(mutResp.GetJson()) != 0 {\n\t\t\tif err := json.Unmarshal(mutResp.GetJson(), &result); err != nil {\n\t\t\t\treturn emptyResult(\n\t\t\t\t\t\tschema.GQLWrapf(err, \"Couldn't unmarshal response from Dgraph mutation\")),\n\t\t\t\t\tresolverFailed\n\t\t\t}\n\t\t}\n\t\t// for update mutation, if @id field is present in set then we check that\n\t\t// in filter only one node is selected. if there are multiple nodes selected,\n\t\t// then it's not possible to update all of them with same value of @id fields.\n\t\t// In that case we return error\n\t\tif mutation.MutationType() == schema.UpdateMutation {\n\t\t\tinp := mutation.ArgValue(schema.InputArgName).(map[string]interface{})\n\t\t\tsetArg := inp[\"set\"]\n\t\t\tobjSet, okSetArg := setArg.(map[string]interface{})\n\t\t\tif len(objSet) == 0 && okSetArg {\n\t\t\t\treturn emptyResult(\n\t\t\t\t\t\tschema.GQLWrapf(errors.Errorf(\"not able to find set args\"+\n\t\t\t\t\t\t\t\" in update mutation\"),\n\t\t\t\t\t\t\t\"mutation %s failed\", mutation.Name())),\n\t\t\t\t\tresolverFailed\n\t\t\t}\n\n\t\t\tmutatedType := mutation.MutatedType()\n\t\t\tvar xidsPresent bool\n\t\t\tif len(objSet) != 0 {\n\t\t\t\tfor _, xid := range mutatedType.XIDFields() {\n\t\t\t\t\tif xidVal, ok := objSet[xid.Name()]; ok && xidVal != nil {\n\t\t\t\t\t\txidsPresent = true\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t// if @id field is present in set and there are multiple nodes returned from\n\t\t\t// upsert query then we return error\n\t\t\tif xidsPresent && len(result[mutation.Name()].([]interface{})) > 1 {\n\t\t\t\tif queryAuthSelector(mutatedType) == nil {","sourceCodeStart":421,"sourceCodeEnd":457,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/graphql/resolve/mutation.go#L421-L457","documentation":"An UpdateMutation requires a 'set' argument containing the fields to update. rewriteAndExecute extracts inp[\"set\"] and, when it is absent/empty (len(objSet)==0, with the cast succeeding), fails the mutation because there is nothing to apply. This catches malformed update payloads where 'set' is an empty object.","triggerScenarios":"Sending an update mutation like updatePost(input: { filter: {...}, set: {} }) — an empty or missing set block; building the input programmatically and producing an empty map.","commonSituations":"Client templating bug that renders an empty set; filter-only update payloads copied from delete-style mutations; GraphQL variables passing an empty object for set.","solutions":["Include at least one field in the set argument of the update mutation","Validate the update payload client-side before sending (non-empty set object)","If you only meant to filter/query, use a query instead of an update mutation","Check GraphQL variables are actually populated (not {} due to serialization bug)"],"exampleFix":"// before\nupdatePost(input: { filter: { id: [\"0x1\"] }, set: {} })\n// after\nupdatePost(input: { filter: { id: [\"0x1\"] }, set: { title: \"new title\" } })","handlingStrategy":"validation","validationCode":"function validateUpdateInput(inp) {\n  if (!inp || !inp.set || typeof inp.set !== 'object' || Object.keys(inp.set).length === 0) {\n    throw new Error('update mutation requires a non-empty set argument');\n  }\n}","typeGuard":"function hasSetArg(inp) {\n  return inp != null && typeof inp === 'object' &&\n    inp.set != null && typeof inp.set === 'object' && Object.keys(inp.set).length > 0;\n}","tryCatchPattern":"try {\n  await client.mutate(UPDATE_MUTATION, { input });\n} catch (err) {\n  if (err.message.includes('not able to find set args')) {\n    // fix payload: add fields to set\n  }\n}","preventionTips":["Build update inputs from typed helpers that require set fields","Validate non-empty set before sending","Schema-check update payloads in tests","Avoid copying filter-only payloads into update mutations"],"tags":["graphql","mutation","input-validation"],"backgroundTag":"missing-mutation-argument","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}