{"record":{"id":"c0b6fa7d4ded007d","repo":"dgraph-io/dgraph","slug":"only-one-node-is-allowed-in-the-filter-while-updat","errorCode":null,"errorMessage":"only one node is allowed in the filter while updating fields with @id directive","messagePattern":"only one node is allowed in the filter while updating fields with @id directive","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"graphql/resolve/mutation.go","lineNumber":459,"sourceCode":"\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 {\n\t\t\t\t\treturn emptyResult(\n\t\t\t\t\t\t\tschema.GQLWrapf(errors.Errorf(\"only one node is allowed in\"+\n\t\t\t\t\t\t\t\t\" the filter while updating fields with @id directive\"),\n\t\t\t\t\t\t\t\t\"mutation %s failed\", mutation.Name())),\n\t\t\t\t\t\tresolverFailed\n\t\t\t\t}\n\t\t\t\treturn emptyResult(\n\t\t\t\t\t\tschema.GQLWrapf(errors.Errorf(\"GraphQL debug: only one node is\"+\n\t\t\t\t\t\t\t\" allowed in the filter while updating fields with @id directive\"),\n\t\t\t\t\t\t\t\"mutation %s failed\", mutation.Name())),\n\t\t\t\t\tresolverFailed\n\n\t\t\t}\n\t\t}\n\n\t\tcopyTypeMap(upsert.NewNodes, newNodes)\n\t}\n\tmutationTimer.Stop()\n\n\tauthErr := authorizeNewNodes(ctx, mutation, mutResp.Uids, newNodes, mr.executor, mutResp.Txn)","sourceCodeStart":441,"sourceCodeEnd":477,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/graphql/resolve/mutation.go#L441-L477","documentation":"When updating a field with the @id directive, an upsert query is run first to locate the target node. If that query returns more than one node, the update cannot proceed unambiguously, so this error is thrown. The non-debug variant is returned when no query auth selector (queryAuthSelector) is configured for the mutated type.","triggerScenarios":"An update mutation touching an @id field whose filter matches multiple existing nodes (xidsPresent && len(result[name]) > 1), with no auth query rule defined for that type.","commonSituations":"Duplicate nodes with the same @id value from legacy imports; missing @auth(query: ...) rule so the system cannot disambiguate via auth; filter too broad (e.g. matching all nodes) when updating an @id field.","solutions":["Clean up duplicate nodes so the filter matches exactly one node","Narrow the update filter to match a single node (unique @id value)","Add an @auth query rule for the type so queryAuthSelector is non-nil (enables the debug variant/other path)","Run the GraphQL debug variant to see which nodes matched"],"exampleFix":"// before\nupdateUser(input: { filter: { name: { eq: \"Bob\" } }, set: { email: \"...\" } }) // 2 Bobs\n// after\nupdateUser(input: { filter: { xid: { eq: \"user-42\" } }, set: { email: \"...\" } })","handlingStrategy":"validation","validationCode":"const nodes = await query({ filter });\nif (xidsPresent && nodes.length > 1) {\n  throw new Error('only one node is allowed in the filter while updating fields with @id directive');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await updateMutation(input);\n} catch (err) {\n  if (err.message.includes('only one node is allowed in the filter')) {\n    // dedupe or narrow the filter\n  }\n}","preventionTips":["Filter @id updates by a unique value","Deduplicate XIDs in data","Define @auth query rules for types updated via @id","Test update flows against data containing duplicate XIDs"],"tags":["graphql","mutation","id-directive","uniqueness"],"backgroundTag":"multiple-nodes-matched","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}