{"record":{"id":"8e36cfe33835c1d0","repo":"dgraph-io/dgraph","slug":"graphql-debug-only-one-node-is-allowed-in-the-fil","errorCode":null,"errorMessage":"GraphQL debug: only one node is allowed in the filter while updating fields with @id directive","messagePattern":"GraphQL debug: 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":465,"sourceCode":"\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)\n\tif authErr != nil {\n\t\treturn emptyResult(schema.GQLWrapf(authErr, \"mutation failed\")), resolverFailed\n\t}\n\n\tvar dgQuery []*dql.GraphQuery\n\tdgQuery, err = mr.mutationRewriter.FromMutationResult(ctx, mutation, mutResp.GetUids(), result)","sourceCodeStart":447,"sourceCodeEnd":483,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/graphql/resolve/mutation.go#L447-L483","documentation":"Identical to the non-debug variant: an update on an @id field matched multiple nodes via the upsert query. This version is returned when queryAuthSelector(mutatedType) IS defined (auth/debug context), and prefixes the message with 'GraphQL debug:' so the client can trace which nodes conflicted.","triggerScenarios":"Update mutation on a type with an @auth query rule where the @id-based upsert filter resolves to more than one node (xidsPresent && result length > 1).","commonSituations":"Duplicated XIDs in data; @auth query rules on types whose filters match several nodes; running with GraphQL debug enabled surfaces this prefixed variant.","solutions":["Deduplicate nodes sharing the @id value","Tighten the filter to a unique @id value","Fix the @auth query rule if it is overly permissive and matching multiple nodes","Investigate how duplicates were created (pre-@id imports, concurrent adds) and prevent recurrence"],"exampleFix":"// before\n# filter matching several nodes via @auth rule\n// after\n# use unique @id value so upsert returns exactly one node","handlingStrategy":"validation","validationCode":"const nodes = await upsertQuery({ filter });\nif (xidsPresent && nodes.length > 1) {\n  console.error('GraphQL debug: multiple nodes matched for @id update', nodes);\n  throw new Error('narrow the filter to a single node');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await updateMutation(input);\n} catch (err) {\n  if (err.message.includes('GraphQL debug: only one node is allowed')) {\n    // inspect auth rule/filter, dedupe matched nodes\n  }\n}","preventionTips":["Keep @auth query rules selective so debug filters match one node","Run with GraphQL debug in staging to catch multi-match filters","Deduplicate nodes sharing @id values","Prefer UID-based filters over broad XID filters for updates"],"tags":["graphql","mutation","id-directive","debug"],"backgroundTag":"multiple-nodes-matched","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}