{"record":{"id":"c66272ebf7772326","repo":"dgraph-io/dgraph","slug":"type-s-requires-a-value-for-field-s-but-no-valu","errorCode":null,"errorMessage":"type %s requires a value for field %s, but no value present","messagePattern":"type (.+?) requires a value for field (.+?), but no value present","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"graphql/schema/wrappers.go","lineNumber":2800,"sourceCode":"//\t}\n//\n// but GraphQL doesn't allow union types in input, so best we can do is\n//\n//\tinput PostRef {\n//\t\tid: ID\n//\t\ttitle: String\n//\t\ttext: String\n//\t\tauthor: AuthorRef\n//\t}\n//\n// and then check ourselves that either there's an ID, or there's all the bits to\n// satisfy a valid post.\nfunc (t *astType) EnsureNonNulls(obj map[string]interface{}, exclusion string) error {\n\tfor _, fld := range t.inSchema.schema.Types[t.Name()].Fields {\n\t\tif fld.Type.NonNull && !isID(fld) && !hasDefault(fld) && fld.Name != exclusion &&\n\t\t\tt.inSchema.customDirectives[t.Name()][fld.Name] == nil {\n\t\t\tif val, ok := obj[fld.Name]; !ok || val == nil {\n\t\t\t\treturn errors.Errorf(\n\t\t\t\t\t\"type %s requires a value for field %s, but no value present\",\n\t\t\t\t\tt.Name(), fld.Name)\n\t\t\t}\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc getAsPathParamValue(val interface{}) string {\n\tswitch v := val.(type) {\n\tcase json.RawMessage:\n\t\tvar temp interface{}\n\t\t_ = Unmarshal(v, &temp) // this can't error, as it was marshalled earlier\n\t\treturn getAsPathParamValue(temp)\n\tcase string:\n\t\treturn v\n\tcase []interface{}:\n\t\treturn getAsInterfaceSliceInPath(v)","sourceCodeStart":2782,"sourceCodeEnd":2818,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/graphql/schema/wrappers.go#L2782-L2818","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\n{\"title\":\"Post title\"} // missing required 'author'\n// after\n{\"title\":\"Post title\",\"author\":\"user-123\"}","handlingStrategy":"validation","validationCode":"required := []string{\"title\",\"author\"} // non-null fields from schema\nfor _, f := range required {\n  if v, ok := obj[f]; !ok || v == nil {\n    return fmt.Errorf(\"missing required field %s\", f)\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["graphql","validation","non-null"],"backgroundTag":"missing-required-argument","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}