dgraph-io/dgraph · error
type %s not found in the schema
Error message
type %s not found in the schema
What it means
Error returned during federated entity resolution in graphql/schema/wrappers.go when the __typename supplied in a representation does not correspond to any type defined in the GraphQL schema. Fix by referencing an existing type name or updating the schema.
Source
Thrown at graphql/schema/wrappers.go:1729
representations, ok := q.ArgValue("representations").([]interface{})
if !ok {
return nil, fmt.Errorf("error parsing `representations` argument")
}
if len(representations) == 0 {
return nil, fmt.Errorf("expecting at least one item in `representations` argument")
}
representation, ok := representations[0].(map[string]interface{})
if !ok {
return nil, fmt.Errorf("error parsing %dth item in the `_representations` argument", 0)
}
typename, ok := representation[Typename].(string)
if !ok {
return nil, fmt.Errorf("unable to extract __typename from %dth item in the"+
" `_representations` argument", 0)
}
typ := q.op.inSchema.schema.Types[typename]
if typ == nil {
return nil, fmt.Errorf("type %s not found in the schema", typename)
}
keyDir := typ.Directives.ForName(apolloKeyDirective)
if keyDir == nil {
return nil, fmt.Errorf("type %s doesn't have a key Directive", typename)
}
keyFldName := keyDir.Arguments[0].Value.Raw
// initialize the struct to return
entityReprs := &EntityRepresentations{
TypeDefn: &astType{
typ: &ast.Type{NamedType: typename},
inSchema: q.op.inSchema,
dgraphPredicate: q.op.inSchema.dgraphPredicate,
},
KeyVals: make([]interface{}, 0, len(representations)),
KeyValToRepresentation: make(map[string]map[string]interface{}),
}
entityReprs.KeyField = entityReprs.TypeDefn.Field(keyFldName)View on GitHub (pinned to 759e242be6)
Solutions
- Correct the __typename to a type defined in the subgraph schema
- Redeploy/synchronize the subgraph schema with the gateway supergraph
- Run a schema check to find removed/renamed types referenced by federation
Example fix
// before
representations: [{__typename: "Produkt", id: "1"}]
// after
representations: [{__typename: "Product", id: "1"}] Defensive patterns
Strategy: validation
Validate before calling
types := schema.Types() // from the deployed subgraph schema
if !types[rep["__typename"].(string)] {
return fmt.Errorf("type %v not in subgraph schema", rep["__typename"])
} Type guard
func typeInSchema(typename string, schema *ast.Schema) bool {
return schema != nil && schema.Types[typename] != nil
} Try / catch
entity, err := q.RepresentationsArg()
if err != nil && strings.Contains(err.Error(), "not found in the schema") {
return nil, fmt.Errorf("unknown entity type: %w", err)
} Prevention
- Run schema checks in CI to catch renamed/removed types referenced by the supergraph
- Deploy subgraph and supergraph schemas atomically
- Validate __typename values against the current schema in gateway middleware
When it happens
Trigger: _entities query with a representation whose __typename refers to a type absent from the subgraph schema (typo, removed type, or schema deployed before the query source updated).
Common situations: Schema drift between gateway and subgraph after a deploy; renaming a type without updating all federation configs; stale supergraph referencing an old subgraph type.
Related errors
- type %s doesn't have a key Directive
- encountered an XID %s with %s that isn'tallowed as Xid
- Unable to find the type %s on the remote schema
- Not resolving subscription because schema doesn't have any f
- while parsing GraphQL schema
AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01).
Data as JSON: /api/errors/8e32adbc7ff25694.
Report an issue: GitHub.