dgraph-io/dgraph · error
expected only one unique typename in `_representations` argu
Error message
expected only one unique typename in `_representations` argument, got: [%s, %s]
What it means
Federation requires all representations in one `_entities` call to belong to the same entity type (this implementation enforces a single unique typename). This error fires when the `__typename` of the item at index i differs from the typename established for the batch, reporting both names.
Source
Thrown at graphql/schema/wrappers.go:1762
KeyVals: make([]interface{}, 0, len(representations)),
KeyValToRepresentation: make(map[string]map[string]interface{}),
}
entityReprs.KeyField = entityReprs.TypeDefn.Field(keyFldName)
// iterate over all the representations and parse
for i, rep := range representations {
representation, ok = rep.(map[string]interface{})
if !ok {
return nil, fmt.Errorf("error parsing %dth item in the `_representations` argument", i)
}
typename, ok = representation[Typename].(string)
if !ok {
return nil, fmt.Errorf("unable to extract __typename from %dth item in the"+
" `_representations` argument", i)
}
if typename != entityReprs.TypeDefn.Name() {
return nil, fmt.Errorf("expected only one unique typename in `_representations`"+
" argument, got: [%s, %s]", entityReprs.TypeDefn.Name(), typename)
}
keyVal, ok := representation[keyFldName]
if !ok {
return nil, fmt.Errorf("unable to extract value for key field `%s` from %dth item in"+
" the `_representations` argument", keyFldName, i)
}
entityReprs.KeyVals = append(entityReprs.KeyVals, keyVal)
entityReprs.KeyValToRepresentation[fmt.Sprint(keyVal)] = representation
}
return entityReprs, nil
}
func (q *query) AuthFor(jwtVars map[string]interface{}) Query {
// copy the template, so that multiple queries can run rewriting for the rule.
return &query{View on GitHub (pinned to 759e242be6)
Solutions
- Split the call so each `_entities` request contains representations of only one type
- Filter the representations array by __typename before batching
- Check upstream code that aggregates representations to avoid cross-type mixing
Example fix
// before
[{"__typename":"Product","upc":"1"},{"__typename":"Review","id":"2"}]
// after
[{"__typename":"Product","upc":"1"}] // separate call for Review Defensive patterns
Strategy: validation
Validate before calling
types := map[string]bool{}
for _, rep := range representations {
types[rep["__typename"].(string)] = true
}
if len(types) > 1 { return errors.New("_representations must contain a single typename") } Prevention
- Group representations by __typename and issue one _entities call per type
- Never batch heterogeneous entity types together
- Enforce single-typename batching in gateway code
When it happens
Trigger: Passing representations of two different entity types (e.g. Product and Review) in a single `_representations` array.
Common situations: Bundling entities from multiple resolvers into one _entities call, or a gateway merging representations from different types into one batch.
Related errors
- error parsing `representations` argument
- expecting at least one item in `representations` argument
- error parsing %dth item in the `_representations` argument
- unable to extract __typename from %dth item in the `_represe
- type %s not found in the schema
AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01).
Data as JSON: /api/errors/e8865785b5886ca3.
Report an issue: GitHub.