{"record":{"id":"49fbd7006ba15943","repo":"dgraph-io/dgraph","slug":"field-with-value-type-object-must-specify-the-name","errorCode":null,"errorMessage":"Field with value type OBJECT must specify the name of the object type","messagePattern":"Field with value type OBJECT must specify the name of the object type","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"worker/mutation.go","lineNumber":826,"sourceCode":"\t\t\t\treturn errors.Errorf(\n\t\t\t\t\t\"Schema does not contain a matching predicate for field %s in type %s\",\n\t\t\t\t\tfield.Predicate, t.TypeName)\n\t\t\t}\n\t\t}\n\t}\n\n\treturn nil\n}\n\n// typeSanityCheck performs basic sanity checks on the given type update.\nfunc typeSanityCheck(t *pb.TypeUpdate) error {\n\tfor _, field := range t.Fields {\n\t\tif x.ParseAttr(field.Predicate) == \"\" {\n\t\t\treturn errors.Errorf(\"Field in type definition must have a name\")\n\t\t}\n\n\t\tif field.ValueType == pb.Posting_OBJECT && field.ObjectTypeName == \"\" {\n\t\t\treturn errors.Errorf(\n\t\t\t\t\"Field with value type OBJECT must specify the name of the object type\")\n\t\t}\n\n\t\tif field.Directive != pb.SchemaUpdate_NONE {\n\t\t\treturn errors.Errorf(\"Field in type definition cannot have a directive\")\n\t\t}\n\n\t\tif len(field.Tokenizer) > 0 {\n\t\t\treturn errors.Errorf(\"Field in type definition cannot have tokenizers\")\n\t\t}\n\t}\n\n\treturn nil\n}\n\n// CommitOverNetwork makes a proxy call to Zero to commit or abort a transaction.\nfunc CommitOverNetwork(ctx context.Context, tc *api.TxnContext) (uint64, error) {\n\tctx, span := otel.Tracer(\"\").Start(ctx, \"worker.CommitOverNetwork\")","sourceCodeStart":808,"sourceCodeEnd":844,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/worker/mutation.go#L808-L844","documentation":"In Dgraph's type system, a type definition field declared with value type OBJECT represents a nested object edge and must name the concrete type it points to. typeSanityCheck (worker/mutation.go) validates every field of every type definition submitted via an Alter/type-verification request and rejects OBJECT fields whose ObjectTypeName is empty. Without the target type name, the object value cannot be resolved or validated, so the definition is refused.","triggerScenarios":"Submitting a type definition (via /alter with schema containing type blocks, or the Go/HTTP alter API) where a field has `object` as its value type but no target type is named, e.g. field generated from GraphQL-to-Dgraph conversion or hand-written JSON schema with ValueType OBJECT and ObjectTypeName \"\".","commonSituations":"Hand-authoring Dgraph schema JSON where nested object fields are declared but the referenced type name is omitted; programmatic schema generation that maps a field to Posting_OBJECT without filling ObjectTypeName; partial schema migrations that drop the object type reference.","solutions":["Set the ObjectTypeName (or in DQL schema, the bracketed type like `friend: [Person] .`) for every OBJECT-valued field in the type definition","Validate the type payload client-side before sending the alter request: for each field with ObjectType OBJECT assert ObjectTypeName != \"\"","Check that any tool generating the schema (GraphQL schema converter, migration script) emits the referenced type name and that the referenced type itself is defined"],"exampleFix":"// before\n{\"fields\":[{\"predicate\":\"address\",\"valueType\":\"OBJECT\"}]}\n// after\n{\"fields\":[{\"predicate\":\"address\",\"valueType\":\"OBJECT\",\"objectTypeName\":\"Address\"}]}","handlingStrategy":"validation","validationCode":"for _, f := range typeDef.Fields {\n    if f.ValueType == pb.Posting_OBJECT && f.ObjectTypeName == \"\" {\n        return fmt.Errorf(\"field %q: OBJECT value type requires objectTypeName\", f.Predicate)\n    }\n}","typeGuard":"func objectTypeNameSet(f *pb.SchemaUpdate) bool {\n    return f.ValueType != pb.Posting_OBJECT || f.ObjectTypeName != \"\"\n}","tryCatchPattern":null,"preventionTips":["Never leave ObjectTypeName empty when emitting Posting_OBJECT fields from schema generators","Define referenced object types in the same alter request","Lint DQL type blocks for object fields lacking a bracketed target type"],"tags":["dgraph","schema","type-definition","validation"],"backgroundTag":"schema-validation-failed","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}