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
- Provide a value for the named field in the input object
- Mark the field optional or give it a default in the schema if it's genuinely optional
- Use a custom directive on the field if your tooling supports exempting it
- 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
- Generate payloads from the schema so non-null fields are enforced at compile time
- Re-validate inputs after schema migrations add required fields
- Give defaults in the schema for genuinely optional fields
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
- given GraphQL operation is not a subscription
- POST method cannot have query parameters in url: %s
- remote schema doesn't have any queries.
- no query string supplied in request
- while validating GraphQL schema
AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01).
Data as JSON: /api/errors/c66272ebf7772326.
Report an issue: GitHub.