{"record":{"id":"c48a6a04d4bb23bc","repo":"payloadcms/payload","slug":"typename-cannot-represent-value-print-ast","errorCode":null,"errorMessage":"${typeName} cannot represent value: ${print(ast)}","messagePattern":"(.+?) cannot represent value: (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/graphql/src/packages/graphql-type-json/index.ts","lineNumber":42,"sourceCode":"\nfunction parseLiteral(typeName, ast, variables) {\n  switch (ast.kind) {\n    case Kind.BOOLEAN:\n    case Kind.STRING:\n      return ast.value\n    case Kind.FLOAT:\n    case Kind.INT:\n      return parseFloat(ast.value)\n    case Kind.LIST:\n      return ast.values.map((n) => parseLiteral(typeName, n, variables))\n    case Kind.NULL:\n      return null\n    case Kind.OBJECT:\n      return parseObject(typeName, ast, variables)\n    case Kind.VARIABLE:\n      return variables ? variables[ast.name.value] : undefined\n    default:\n      throw new TypeError(`${typeName} cannot represent value: ${print(ast)}`)\n  }\n}\n\n// This named export is intended for users of CommonJS. Users of ES modules\n//  should instead use the default export.\nexport const GraphQLJSON = new GraphQLScalarType({\n  name: 'JSON',\n  description:\n    'The `JSON` scalar type represents JSON values as specified by [ECMA-404](http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf).',\n  parseLiteral: (ast, variables) => parseLiteral('JSON', ast, variables),\n  parseValue: identity,\n  serialize: identity,\n  specifiedByURL: 'http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf',\n})\n\nexport const GraphQLJSONObject = new GraphQLScalarType({\n  name: 'JSONObject',\n  description:","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/graphql/src/packages/graphql-type-json/index.ts#L24-L60","documentation":"The default branch of `parseLiteral` in the vendored GraphQL JSON scalar. It throws when the AST node passed as a literal argument is a kind the parser does not explicitly handle (the handled kinds are STRING, BOOLEAN, FLOAT, INT, LIST, NULL, OBJECT, VARIABLE, and ENUM implicitly missing). Any other AST kind triggers this generic 'cannot represent value' error with the printed AST. It is a parser-completeness guard, not a normal validation path.","triggerScenarios":"Sending a GraphQL literal of an unexpected/unsupported kind as a `JSON` argument directly inline in the query (rare — usually means a custom AST kind or a malformed/generated query). More commonly hit when a query-building library emits an unusual node type for a `JSON` argument.","commonSituations":"Custom GraphQL clients or codegen producing non-standard AST; using the scalar with a GraphQL server version whose `Kind` enum includes types this vendored parser predates; malformed hand-crafted queries.","solutions":["Pass the JSON value as a `$variable` rather than an inline literal — variables route through `parseValue` (identity), bypassing `parseLiteral`.","Ensure the inline literal is one of: string, number, boolean, null, array, or object.","Upgrade the vendored graphql-type-json copy to a version whose `parseLiteral` covers the AST kind in use."],"exampleFix":"// before — inline unusual literal\nmutation { set(meta: <weird>) { id } }\n\n// after — use a variable\nmutation SetMeta($meta: JSON) { set(meta: $meta) { id } }","handlingStrategy":"try-catch","validationCode":"const ALLOWED = ['string','boolean','float','int','list','null','object','variable']\n// Prefer variables over inline literals for JSON scalar arguments:\nclient.request(query, { meta: jsonValue })","typeGuard":null,"tryCatchPattern":"try {\n  await client.request(mutation, { meta: jsonValue }) // use a variable\n} catch (e) {\n  if (e instanceof TypeError && /cannot represent value/.test(e.message)) {\n    // switch the argument from an inline literal to a $variable\n  }\n  throw e\n}","preventionTips":["Pass JSON scalar values as GraphQL variables, not inline literals.","Keep the vendored graphql-type-json up to date if you rely on inline literals.","Validate generated queries against supported AST kinds in tests."],"tags":["graphql","json","scalar","ast","parse-literal"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}