dgraph-io/dgraph · error
Type name must be specified in type update
Error message
Type name must be specified in type update
What it means
verifyTypes validates the Types list of a mutation request before applying type updates. Every pb.TypeUpdate must carry a non-empty TypeName; this error is returned when an entry in m.Types has an empty type name, so Dgraph cannot identify which type definition the update applies to. It is a client-side request validation error, not a server fault.
Source
Thrown at worker/mutation.go:765
tctx.Preds = append(tctx.Preds, res.ctx.Preds...)
}
}
close(resCh)
return tctx, e
}
func verifyTypes(ctx context.Context, m *pb.Mutations) error {
// Create a set of all the predicates included in this schema request.
reqPredSet := make(map[string]struct{}, len(m.Schema))
for _, schemaUpdate := range m.Schema {
reqPredSet[schemaUpdate.Predicate] = struct{}{}
}
// Create a set of all the predicates already present in the schema.
var fields []string
for _, t := range m.Types {
if t.TypeName == "" {
return errors.Errorf("Type name must be specified in type update")
}
if err := typeSanityCheck(t); err != nil {
return err
}
for _, field := range t.Fields {
fieldName := field.Predicate
ns, attr := x.ParseNamespaceAttr(fieldName)
if attr[0] == '~' {
fieldName = x.NamespaceAttr(ns, attr[1:])
}
if _, ok := reqPredSet[fieldName]; !ok {
fields = append(fields, fieldName)
}
}
}View on GitHub (pinned to 759e242be6)
Solutions
- Give every type definition an explicit name: `type Person { name string }` instead of `type { name string }`
- In JSON mutations, ensure each object in the types array has a non-empty typeName field
- Audit generated or templated schema payloads for cases where the type name variable is empty or interpolated to ""
- Validate the full mutation payload (types included) client-side before calling MutateOverNetwork
Example fix
// before
type {
name
}
// after
type Person {
name
} Defensive patterns
Strategy: validation
Validate before calling
// Validate type updates before sending the mutation
for i, t := range mutation.Types {
if t.TypeName == "" {
return fmt.Errorf("types[%d] has empty typeName", i)
}
} Type guard
func hasTypeName(t *api.TypeUpdate) bool {
return t != nil && t.TypeName != ""
} Try / catch
// DQL/HTTP client: wrap the mutate call and inspect the message
_, err := txn.Mutate(ctx, mu)
if err != nil && strings.Contains(err.Error(), "Type name must be specified") {
return fmt.Errorf("malformed type definition in mutation payload: %w", err)
} Prevention
- Never emit anonymous `type { ... }` blocks in DQL
- Validate generated schema payloads against a template that requires a type name
- Lint DQL type definitions in CI before deploying schema changes
When it happens
Trigger: Calling MutateOverNetwork (or the HTTP /mutate or gRPC Mutate APIs) with a payload whose types block contains a type definition with no name — e.g. an empty DQL type block `type { ... }`, a JSON mutation with {"types":[{"fields":[...]}]} missing the typeName field, or a programmatically built pb.TypeUpdate with TypeName unset.
Common situations: Hand-written DQL where `type Person {` lost its name; template/code generators that emit an empty type name; schema migration scripts that copy type bodies but drop the header; partial edits that leave a dangling anonymous type block.
Related errors
- Schema does not contain a matching predicate for field %s in
- Field in type definition must have a name
- No value found
- while validating GraphQL schema
- item.Val
AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01).
Data as JSON: /api/errors/4f10fcbec2873976.
Report an issue: GitHub.