{"id":"02bcb6d12e43ca69","repo":"prettier/prettier","slug":"unexpected-graphql-node-kind-node-kind","errorCode":null,"errorMessage":"Unexpected Graphql node kind: ${node.kind}.","messagePattern":"Unexpected Graphql node kind: (.+?)\\.","errorType":"exception","errorClass":"UnexpectedNodeError","httpStatus":null,"severity":"error","filePath":"src/language-graphql/printer-graphql.js","lineNumber":438,"sourceCode":"    case \"ScalarTypeExtension\":\n    case \"ScalarTypeDefinition\":\n      return [\n        printDescription(path, options, print),\n        node.kind === \"ScalarTypeExtension\" ? \"extend \" : \"\",\n        \"scalar \",\n        print(\"name\"),\n        printDirectives(path, print),\n      ];\n\n    case \"NonNullType\":\n      return [print(\"type\"), \"!\"];\n\n    case \"ListType\":\n      return [\"[\", print(\"type\"), \"]\"];\n\n    default:\n      /* c8 ignore next */\n      throw new UnexpectedNodeError(node, \"Graphql\", \"kind\");\n  }\n}\n\nfunction canAttachComment(node /* , ancestors */) {\n  return node.kind !== \"Comment\";\n}\n\nfunction printComment({ node: comment }) {\n  if (comment.kind === \"Comment\") {\n    return \"#\" + comment.value.trimEnd();\n  }\n\n  /* c8 ignore next */\n  throw new Error(\"Not a comment: \" + JSON.stringify(comment));\n}\n\nfunction hasPrettierIgnore(path) {\n  const { node } = path;","sourceCodeStart":420,"sourceCodeEnd":456,"githubUrl":"https://github.com/prettier/prettier/blob/315f28198200d7678dadd3fd5eece499b127ff2a/src/language-graphql/printer-graphql.js#L420-L456","documentation":"Thrown by the GraphQL printer's default case as `new UnexpectedNodeError(node, 'Graphql', 'kind')`, yielding `Unexpected Graphql node kind: <kind>.`. GraphQL ASTs use a `kind` field (not `type`), hence the third argument. The `c8 ignore` marks it as unreachable, so encountering it means the parser produced a node kind the printer does not handle.","triggerScenarios":"Formatting a `.graphql` file whose AST contains a `kind` absent from the printer's switch (e.g. a newly introduced GraphQL syntax node, a custom AST from a third-party parser, or version skew between `graphql` package and Prettier's printer).","commonSituations":"GraphQL schema/query using newer spec features not yet supported; mismatched `graphql` and Prettier versions in a monorepo; editor integration using a different GraphQL parser; corrupted or hand-crafted AST input via the API.","solutions":["Upgrade Prettier (and the bundled `graphql` dependency) to the latest stable release.","Pin a compatible `graphql` version across the workspace.","Reduce the failing GraphQL snippet and report it upstream with a minimal repro.","Temporarily skip the file with `.prettierignore` or `# prettier-ignore`."],"exampleFix":"# before - newer directive syntax the printer doesn't know\nquery @experimental { foo }\n# after - ignore directive until upgrade\n# prettier-ignore\nquery @experimental { foo }","handlingStrategy":"try-catch","validationCode":"import { parse } from 'graphql';\ntry { parse(graphqlText); } catch (e) { /* skip formatting */ }","typeGuard":null,"tryCatchPattern":"try {\n  await prettier.format(sdl, { parser: 'graphql' });\n} catch (err) {\n  if (/Unexpected Graphql node kind/.test(err.message)) {\n    console.warn('Unsupported GraphQL node; consider upgrading prettier.', err.message);\n  } else throw err;\n}","preventionTips":["Pin compatible `graphql` and Prettier versions across the workspace.","Avoid bleeding-edge GraphQL spec features until Prettier adds support.","For tooling, treat unformattable GraphQL as a soft failure (warn + skip)."],"tags":["graphql","ast","parser","unexpected-node"],"analyzedSha":"315f28198200d7678dadd3fd5eece499b127ff2a","analyzedAt":"2026-08-03T19:59:41.458Z","schemaVersion":2}