{"record":{"id":"b253465e396694ad","repo":"dgraph-io/dgraph","slug":"unable-to-extract-value-for-key-field-s-from-d","errorCode":null,"errorMessage":"unable to extract value for key field `%s` from %dth item in the `_representations` argument","messagePattern":"unable to extract value for key field `(.+?)` from (.+?)th item in the `_representations` argument","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"graphql/schema/wrappers.go","lineNumber":1768,"sourceCode":"\tfor i, rep := range representations {\n\t\trepresentation, ok = rep.(map[string]interface{})\n\t\tif !ok {\n\t\t\treturn nil, fmt.Errorf(\"error parsing %dth item in the `_representations` argument\", i)\n\t\t}\n\n\t\ttypename, ok = representation[Typename].(string)\n\t\tif !ok {\n\t\t\treturn nil, fmt.Errorf(\"unable to extract __typename from %dth item in the\"+\n\t\t\t\t\" `_representations` argument\", i)\n\t\t}\n\t\tif typename != entityReprs.TypeDefn.Name() {\n\t\t\treturn nil, fmt.Errorf(\"expected only one unique typename in `_representations`\"+\n\t\t\t\t\" argument, got: [%s, %s]\", entityReprs.TypeDefn.Name(), typename)\n\t\t}\n\n\t\tkeyVal, ok := representation[keyFldName]\n\t\tif !ok {\n\t\t\treturn nil, fmt.Errorf(\"unable to extract value for key field `%s` from %dth item in\"+\n\t\t\t\t\" the `_representations` argument\", keyFldName, i)\n\t\t}\n\t\tentityReprs.KeyVals = append(entityReprs.KeyVals, keyVal)\n\t\tentityReprs.KeyValToRepresentation[fmt.Sprint(keyVal)] = representation\n\t}\n\n\treturn entityReprs, nil\n}\n\nfunc (q *query) AuthFor(jwtVars map[string]interface{}) Query {\n\t// copy the template, so that multiple queries can run rewriting for the rule.\n\treturn &query{\n\t\tfield: (*field)(q).field,\n\t\top: &operation{op: q.op.op,\n\t\t\tquery:    q.op.query,\n\t\t\tdoc:      q.op.doc,\n\t\t\tinSchema: q.op.inSchema,\n\t\t\tvars:     jwtVars,","sourceCodeStart":1750,"sourceCodeEnd":1786,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/graphql/schema/wrappers.go#L1750-L1786","documentation":"After validating __typename, the parser extracts the entity's key field value (e.g. `upc` for Product) from each representation. This error fires when the representation map lacks the key field named by the @key directive on the type at index i.","triggerScenarios":"A representation object with correct __typename but missing the key field (e.g. no `upc` for a Product keyed on upc), or the key field present with value nil where the map lookup via keyFldName fails.","commonSituations":"Partial representations produced by gateways dropping key fields, renamed fields after schema change, or clients constructing representations manually without reading the @key directive.","solutions":["Include the key field defined by the type's @key directive in every representation","Check the subgraph schema for the exact key field name (e.g. upc vs sku)","Regenerate client types after schema changes so key fields stay in sync"],"exampleFix":"// before\n{\"__typename\":\"Product\"}\n// after\n{\"__typename\":\"Product\",\"upc\":\"1\"}","handlingStrategy":"validation","validationCode":"keyFields := map[string]string{\"Product\":\"upc\",\"Review\":\"id\"}\nfor i, rep := range representations {\n  tn := rep[\"__typename\"].(string)\n  if _, ok := rep[keyFields[tn]]; !ok {\n    return fmt.Errorf(\"rep %d missing key field %s\", i, keyFields[tn])\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Read the @key directive for each entity type and include those fields","Keep client representation builders in sync with schema key changes","Test _entities payloads against the schema in CI"],"tags":["graphql","federation","entity-keys"],"backgroundTag":"missing-entity-key-field","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}