prettier/prettier · error · UnexpectedNodeError
Unexpected Graphql node kind: ${node.kind}.
Error message
Unexpected Graphql node kind: ${node.kind}. What it means
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.
Source
Thrown at src/language-graphql/printer-graphql.js:438
case "ScalarTypeExtension":
case "ScalarTypeDefinition":
return [
printDescription(path, options, print),
node.kind === "ScalarTypeExtension" ? "extend " : "",
"scalar ",
print("name"),
printDirectives(path, print),
];
case "NonNullType":
return [print("type"), "!"];
case "ListType":
return ["[", print("type"), "]"];
default:
/* c8 ignore next */
throw new UnexpectedNodeError(node, "Graphql", "kind");
}
}
function canAttachComment(node /* , ancestors */) {
return node.kind !== "Comment";
}
function printComment({ node: comment }) {
if (comment.kind === "Comment") {
return "#" + comment.value.trimEnd();
}
/* c8 ignore next */
throw new Error("Not a comment: " + JSON.stringify(comment));
}
function hasPrettierIgnore(path) {
const { node } = path;View on GitHub (pinned to 315f281982)
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`.
Example fix
# before - newer directive syntax the printer doesn't know
query @experimental { foo }
# after - ignore directive until upgrade
# prettier-ignore
query @experimental { foo } Defensive patterns
Strategy: try-catch
Validate before calling
import { parse } from 'graphql';
try { parse(graphqlText); } catch (e) { /* skip formatting */ } Try / catch
try {
await prettier.format(sdl, { parser: 'graphql' });
} catch (err) {
if (/Unexpected Graphql node kind/.test(err.message)) {
console.warn('Unsupported GraphQL node; consider upgrading prettier.', err.message);
} else throw err;
} Prevention
- 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).
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- Unexpected PostCSS node type: ${node.type}.
- Unexpected Handlebars node type: ${node.type}.
- Unexpected HTML node type: ${node.type}.
- Unexpected Angular node type: ${node.type}.
- Unexpected ESTree node type: ${node.type}.
AI-assisted analysis of prettier/prettier@315f281982 (2026-08-03).
Data as JSON: /data/errors/02bcb6d12e43ca69.json.
Report an issue: GitHub.