{"record":{"id":"17b319fa993a06a5","repo":"dgraph-io/dgraph","slug":"id-value-was-null","errorCode":null,"errorMessage":"ID value was null","messagePattern":"ID value was null","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"graphql/resolve/mutation_rewriter.go","lineNumber":1170,"sourceCode":"\n\treturn extractMutated(result, mutation.Name())\n}\n\n// RewriteQueries on deleteRewriter does not return any queries. queries to check\n// existence of nodes are not needed as part of Delete Mutation.\n// The function generates VarGen and XidMetadata which are used in Rewrite function.\nfunc (drw *deleteRewriter) RewriteQueries(\n\tctx context.Context,\n\tm schema.Mutation) ([]*dql.GraphQuery, []string, error) {\n\n\tdrw.VarGen = NewVariableGenerator()\n\n\treturn []*dql.GraphQuery{}, []string{}, nil\n}\n\nfunc asUID(val interface{}) (uint64, error) {\n\tif val == nil {\n\t\treturn 0, errors.Errorf(\"ID value was null\")\n\t}\n\n\tid, ok := val.(string)\n\tuid, err := strconv.ParseUint(id, 0, 64)\n\n\tif !ok || err != nil {\n\t\treturn 0, errors.Errorf(\"ID argument (%s) was not able to be parsed\", id)\n\t}\n\n\treturn uid, nil\n}\n\nfunc addAuthSelector(t schema.Type) *schema.RuleNode {\n\tauth := t.AuthRules()\n\tif auth == nil || auth.Rules == nil {\n\t\treturn nil\n\t}\n","sourceCodeStart":1152,"sourceCodeEnd":1188,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/graphql/resolve/mutation_rewriter.go#L1152-L1188","documentation":"asUID converts an ID argument value to a Dgraph UID (uint64). If the value is nil — the ID argument was not provided or was explicitly null — it returns 'ID value was null'. It is used by checkUIDExistsQuery and addDelete when resolving delete mutations.","triggerScenarios":"Calling a delete mutation (e.g. deletePost(id: null) or omitting the id argument so the map lookup yields nil) and passing the result to asUID.","commonSituations":"Client forgetting the required id field; GraphQL variables where id is null; serialization dropping the id key; constructing the input map programmatically without setting id.","solutions":["Provide a non-null id argument in the delete mutation","Make the schema declare the id argument non-null (ID!) so GraphQL rejects nulls earlier","Validate variables client-side before sending (id != null)","Check that variables are correctly bound and not dropped in transit"],"exampleFix":"// before\ndeletePost(id: null)\n// after\ndeletePost(id: \"0x1234\")","handlingStrategy":"type-guard","validationCode":"if (id == null) throw new Error('ID value was null');","typeGuard":"function isProvidedId(v) { return v != null && typeof v === 'string'; }","tryCatchPattern":"try {\n  await deletePost({ id });\n} catch (err) {\n  if (err.message === 'ID value was null') {\n    // fix variables: id is required and non-null\n  }\n}","preventionTips":["Declare id arguments as ID! (non-null) in the schema","Validate variables before executing mutations","Never build delete inputs without setting id","Enable client-side GraphQL variable validation"],"tags":["graphql","delete-mutation","null-value"],"backgroundTag":"null-required-argument","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}