{"record":{"id":"ddf9fbcefca7b77a","repo":"dgraph-io/dgraph","slug":"error-parsing-dth-item-in-the-representations","errorCode":null,"errorMessage":"error parsing %dth item in the `_representations` argument","messagePattern":"error parsing (.+?)th item in the `_representations` argument","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"graphql/schema/wrappers.go","lineNumber":1720,"sourceCode":"func (q *query) CompleteAlias(buf *bytes.Buffer) {\n\t(*field)(q).CompleteAlias(buf)\n}\n\nfunc (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{","sourceCodeStart":1702,"sourceCodeEnd":1738,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/graphql/schema/wrappers.go#L1702-L1738","documentation":"After confirming the representations list, RepresentationsArg parses the first item and requires it to be a map (object). This error is thrown when representations[0] is not an object (e.g. a scalar or null).","triggerScenarios":"_entities query where the first element of `representations` is a non-object value such as a string, number, or null.","commonSituations":"Malformed hand-written _entities queries; a buggy gateway serializing representations incorrectly.","solutions":["Make each representation a JSON object containing `__typename`","Validate the payload the gateway sends to the subgraph","Republish the supergraph if the gateway is producing malformed representations"],"exampleFix":"// before\nrepresentations: [\"product-1\"]\n// after\nrepresentations: [{__typename: \"Product\", id: \"product-1\"}]","handlingStrategy":"type-guard","validationCode":"for _, r := range reps {\n\tif _, ok := r.(map[string]interface{}); !ok {\n\t\treturn fmt.Errorf(\"each representation must be an object\")\n\t}\n}","typeGuard":"func isRepresentation(v interface{}) bool {\n\t_, ok := v.(map[string]interface{})\n\treturn ok\n}","tryCatchPattern":"entity, err := q.RepresentationsArg()\nif err != nil && strings.Contains(err.Error(), \"_representations argument\") {\n\treturn nil, fmt.Errorf(\"malformed representation item: %w\", err)\n}","preventionTips":["Ensure representations are JSON objects, never scalars or null","Add gateway-side serialization tests for representation payloads","Validate the entities payload shape at the gateway before forwarding"],"tags":["graphql","federation","arguments","type-error"],"backgroundTag":"federation-representations-invalid","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}