diff --git a/packages/gatsby-cli/src/structured-errors/error-map.ts b/packages/gatsby-cli/src/structured-errors/error-map.ts index d50a619207669..9151f8e218811 100644 --- a/packages/gatsby-cli/src/structured-errors/error-map.ts +++ b/packages/gatsby-cli/src/structured-errors/error-map.ts @@ -257,6 +257,12 @@ export const errorMap = { type: Type.GRAPHQL, level: Level.ERROR, }, + "85927": { + text: (context): string => + `There was an error in your GraphQL query:\n\n${context.sourceMessage}\n\nSee if ${context.variable} has a typo or ${context.operation} doesn't actually require this variable.`, + type: Type.GRAPHQL, + level: Level.ERROR, + }, // Config errors "10123": { text: (context): string => diff --git a/packages/gatsby/src/query/error-parser.js b/packages/gatsby/src/query/error-parser.js index 066fb63f0cc09..bc834187eec00 100644 --- a/packages/gatsby/src/query/error-parser.js +++ b/packages/gatsby/src/query/error-parser.js @@ -97,6 +97,19 @@ const errorParser = ({ } }, }, + { + regex: /Variable "(.+)" is never used in operation "(.+)".*/ms, + cb: match => { + return { + id: `85927`, + context: { + sourceMessage: match[0], + variable: match[1], + operation: match[2], + }, + } + }, + }, // Match anything with a generic catch-all error handler { regex: /[\s\S]*/gm,