{"record":{"id":"4026c4171daace3d","repo":"dgraph-io/dgraph","slug":"unable-to-extract-typename-from-dth-item-in-the","errorCode":null,"errorMessage":"unable to extract __typename from %dth item in the `_representations` argument","messagePattern":"unable to extract __typename from (.+?)th item in the `_representations` argument","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"graphql/schema/wrappers.go","lineNumber":1724,"sourceCode":"func (q *query) GetAuthMeta() *authorization.AuthMeta {\n\treturn (*field)(q).GetAuthMeta()\n}\n\nfunc (q *query) RepresentationsArg() (*EntityRepresentations, error) {\n\trepresentations, ok := q.ArgValue(\"representations\").([]interface{})\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"error parsing `representations` argument\")\n\t}\n\tif len(representations) == 0 {\n\t\treturn nil, fmt.Errorf(\"expecting at least one item in `representations` argument\")\n\t}\n\trepresentation, ok := representations[0].(map[string]interface{})\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"error parsing %dth item in the `_representations` argument\", 0)\n\t}\n\ttypename, ok := representation[Typename].(string)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"unable to extract __typename from %dth item in the\"+\n\t\t\t\" `_representations` argument\", 0)\n\t}\n\ttyp := q.op.inSchema.schema.Types[typename]\n\tif typ == nil {\n\t\treturn nil, fmt.Errorf(\"type %s not found in the schema\", typename)\n\t}\n\tkeyDir := typ.Directives.ForName(apolloKeyDirective)\n\tif keyDir == nil {\n\t\treturn nil, fmt.Errorf(\"type %s doesn't have a key Directive\", typename)\n\t}\n\tkeyFldName := keyDir.Arguments[0].Value.Raw\n\n\t// initialize the struct to return\n\tentityReprs := &EntityRepresentations{\n\t\tTypeDefn: &astType{\n\t\t\ttyp:             &ast.Type{NamedType: typename},\n\t\t\tinSchema:        q.op.inSchema,\n\t\t\tdgraphPredicate: q.op.inSchema.dgraphPredicate,","sourceCodeStart":1706,"sourceCodeEnd":1742,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/graphql/schema/wrappers.go#L1706-L1742","documentation":"Error returned when resolving a federated entities query in graphql/schema/wrappers.go when the __typename field cannot be extracted from the item at the given index within the `_representations` argument. Fix by ensuring each representation object includes a valid __typename.","triggerScenarios":"_entities query whose first representation object omits `__typename` or sets it to a non-string (e.g. null).","commonSituations":"Hand-crafted federation queries forgetting __typename; custom gateways not injecting __typename into representations.","solutions":["Add `__typename` as a string to every representation object","Ensure the gateway includes __typename when building representations","Check client @client-field handling isn't stripping __typename"],"exampleFix":"// before\nrepresentations: [{id: \"1\"}]\n// after\nrepresentations: [{__typename: \"Product\", id: \"1\"}]","handlingStrategy":"type-guard","validationCode":"rep := reps[0].(map[string]interface{})\ntn, ok := rep[\"__typename\"].(string)\nif !ok || tn == \"\" { return fmt.Errorf(\"representation missing __typename\") }","typeGuard":"func hasTypename(v interface{}) bool {\n\tm, ok := v.(map[string]interface{})\n\tif !ok { return false }\n\ts, ok := m[\"__typename\"].(string)\n\treturn ok && s != \"\"\n}","tryCatchPattern":"entity, err := q.RepresentationsArg()\nif err != nil && strings.Contains(err.Error(), \"__typename\") {\n\treturn nil, fmt.Errorf(\"representation missing __typename: %w\", err)\n}","preventionTips":["Always include __typename in every representation object","Configure the gateway to inject __typename into representations","Add a contract test asserting __typename presence in entity payloads"],"tags":["graphql","federation","arguments"],"backgroundTag":"federation-representations-invalid","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}