{"record":{"id":"e64f1498509741be","repo":"gatsbyjs/gatsby","slug":"gatsbysortandaggrcodemod-graphql-syntax-error-in","errorCode":null,"errorMessage":"GatsbySortAndAggrCodemod: GraphQL syntax error in query:\n\n${query}\n\nmessage:\n\n${err}","messagePattern":"GatsbySortAndAggrCodemod: GraphQL syntax error in query:\n\n(.+?)\n\nmessage:\n\n(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/gatsby-codemods/src/transforms/sort-and-aggr-graphql.ts","lineNumber":305,"sourceCode":"                  kind: graphql.Kind.LIST,\n                  values: newObjects,\n                }\n              : newObjects[0]\n          hasChanged = true\n        } else if (node.name.value === `field`) {\n          if (node.value.kind !== graphql.Kind.ENUM) {\n            return\n          }\n\n          // @ts-ignore read-only ...\n          node.value = pathSegmentsToAst(node.value.value, `SELECT`)\n          hasChanged = true\n        }\n      },\n    })\n    return { ast, hasChanged }\n  } catch (err) {\n    throw new Error(\n      `GatsbySortAndAggrCodemod: GraphQL syntax error in query:\\n\\n${query}\\n\\nmessage:\\n\\n${err}`\n    )\n  }\n}\n","sourceCodeStart":287,"sourceCodeEnd":310,"githubUrl":"https://github.com/gatsbyjs/gatsby/blob/8b06340921ffdf23125a365b9c9923690cb62ce6/packages/gatsby-codemods/src/transforms/sort-and-aggr-graphql.ts#L287-L310","documentation":"Thrown by the sort-and-aggregation codemod when its graphql.parse/visit pass fails on a query. This transform rewrites deprecated `sort: { fields: [], order: [] }` and aggregation fields to the v4 syntax; any pre-existing GraphQL syntax error aborts the rewrite and surfaces the query plus the parse error.","triggerScenarios":"Running `npx gatsby-codemods --transform sort-and-aggr-graphql` over a file whose graphql tag literal is syntactically invalid; visiting an allX query with malformed arguments; partial edits left an unclosed selection set.","commonSituations":"Codemodding from Gatsby v2/v3 to v4 where the codebase has hand-written or generated queries with syntax errors; queries that built via string concatenation; old fragment definitions referencing removed types.","solutions":["Inspect the printed `query` to find the syntax error and its line/column.","Correct the GraphQL syntax, then re-run the codemod.","Run the transform on a smaller file subset to isolate which query fails.","Validate queries with `gatsby develop` or an independent graphql parser before codemodding."],"exampleFix":"// before: deprecated sort syntax plus a stray brace\nexport const q = graphql`query { allMdx(sort: {fields: [date], order: [DESC]}} { edges { node { id } } } `\n// after: v4 syntax, balanced braces\nexport const q = graphql`query { allMdx(sort: {fields: [date], order: [DESC]}) { edges { node { id } } } }`","handlingStrategy":"validation","validationCode":"const { parse } = require('graphql')\nfiles.forEach(f => { try { parse(extractQuery(f)) } catch (e) { console.warn(`${f}: ${e.message}`) } })","typeGuard":"const isParseableGraphQL = (q: string): boolean => { try { parse(q); return true } catch { return false } }","tryCatchPattern":"try {\n  await transform(file)\n} catch (e) {\n  if (/GatsbySortAndAggrCodemod: GraphQL syntax error/.test(e.message)) {\n    // skip file, fix query manually\n  } else throw e\n}","preventionTips":["Run the codemod on small file subsets to isolate failures.","Ensure queries are valid GraphQL before migrating.","Commit between codemod runs to bisect breakage."],"tags":["codemod","graphql","migration","gatsby-codemods"],"backgroundTag":null,"analyzedSha":"8b06340921ffdf23125a365b9c9923690cb62ce6","analyzedAt":"2026-08-13T02:36:21.405Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}