dgraph-io/dgraph · error

ID value was null

Error message

ID value was null

What it means

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.

Source

Thrown at graphql/resolve/mutation_rewriter.go:1170

	return extractMutated(result, mutation.Name())
}

// RewriteQueries on deleteRewriter does not return any queries. queries to check
// existence of nodes are not needed as part of Delete Mutation.
// The function generates VarGen and XidMetadata which are used in Rewrite function.
func (drw *deleteRewriter) RewriteQueries(
	ctx context.Context,
	m schema.Mutation) ([]*dql.GraphQuery, []string, error) {

	drw.VarGen = NewVariableGenerator()

	return []*dql.GraphQuery{}, []string{}, nil
}

func asUID(val interface{}) (uint64, error) {
	if val == nil {
		return 0, errors.Errorf("ID value was null")
	}

	id, ok := val.(string)
	uid, err := strconv.ParseUint(id, 0, 64)

	if !ok || err != nil {
		return 0, errors.Errorf("ID argument (%s) was not able to be parsed", id)
	}

	return uid, nil
}

func addAuthSelector(t schema.Type) *schema.RuleNode {
	auth := t.AuthRules()
	if auth == nil || auth.Rules == nil {
		return nil
	}

View on GitHub (pinned to 759e242be6)

Solutions

  1. Provide a non-null id argument in the delete mutation
  2. Make the schema declare the id argument non-null (ID!) so GraphQL rejects nulls earlier
  3. Validate variables client-side before sending (id != null)
  4. Check that variables are correctly bound and not dropped in transit

Example fix

// before
deletePost(id: null)
// after
deletePost(id: "0x1234")
Defensive patterns

Strategy: type-guard

Validate before calling

if (id == null) throw new Error('ID value was null');

Type guard

function isProvidedId(v) { return v != null && typeof v === 'string'; }

Try / catch

try {
  await deletePost({ id });
} catch (err) {
  if (err.message === 'ID value was null') {
    // fix variables: id is required and non-null
  }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01). Data as JSON: /api/errors/17b319fa993a06a5. Report an issue: GitHub.