dgraph-io/dgraph · error

type %s requires a value for field %s, but no value present

Error message

type %s requires a value for field %s, but no value present

What it means

EnsureNonNulls validates that an object satisfies all non-null fields of its GraphQL type (excluding ID fields, fields with defaults, the excluded field, and fields with custom directives). This error fires when a required non-null field has no value (missing key or explicit null) in the object being validated.

Source

Thrown at graphql/schema/wrappers.go:2800

//	}
//
// but GraphQL doesn't allow union types in input, so best we can do is
//
//	input PostRef {
//		id: ID
//		title: String
//		text: String
//		author: AuthorRef
//	}
//
// and then check ourselves that either there's an ID, or there's all the bits to
// satisfy a valid post.
func (t *astType) EnsureNonNulls(obj map[string]interface{}, exclusion string) error {
	for _, fld := range t.inSchema.schema.Types[t.Name()].Fields {
		if fld.Type.NonNull && !isID(fld) && !hasDefault(fld) && fld.Name != exclusion &&
			t.inSchema.customDirectives[t.Name()][fld.Name] == nil {
			if val, ok := obj[fld.Name]; !ok || val == nil {
				return errors.Errorf(
					"type %s requires a value for field %s, but no value present",
					t.Name(), fld.Name)
			}
		}
	}
	return nil
}

func getAsPathParamValue(val interface{}) string {
	switch v := val.(type) {
	case json.RawMessage:
		var temp interface{}
		_ = Unmarshal(v, &temp) // this can't error, as it was marshalled earlier
		return getAsPathParamValue(temp)
	case string:
		return v
	case []interface{}:
		return getAsInterfaceSliceInPath(v)

View on GitHub (pinned to 759e242be6)

Solutions

  1. Provide a value for the named field in the input object
  2. Mark the field optional or give it a default in the schema if it's genuinely optional
  3. Use a custom directive on the field if your tooling supports exempting it
  4. Update client payloads after schema changes that introduced new non-null fields

Example fix

// before
{"title":"Post title"} // missing required 'author'
// after
{"title":"Post title","author":"user-123"}
Defensive patterns

Strategy: validation

Validate before calling

required := []string{"title","author"} // non-null fields from schema
for _, f := range required {
  if v, ok := obj[f]; !ok || v == nil {
    return fmt.Errorf("missing required field %s", f)
  }
}

Prevention

When it happens

Trigger: Calling EnsureNonNulls (via mutation/input object construction) with a map missing a non-null schema field, or providing null for it, while the field has no default and no custom directive override.

Common situations: Partial PATCH-style payloads sent where full objects are required, schema changes adding new required fields not reflected in client code, or migrations producing incomplete records.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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