{"record":{"id":"c063312a2dabccaf","repo":"gatsbyjs/gatsby","slug":"babelpluginremovegraphqlqueries-unexpected-empty","errorCode":null,"errorMessage":"BabelPluginRemoveGraphQLQueries: Unexpected empty graphql tag.","messagePattern":"BabelPluginRemoveGraphQLQueries: Unexpected empty graphql tag\\.","errorType":"exception","errorClass":"EmptyGraphQLTagError","httpStatus":null,"severity":"error","filePath":"packages/babel-plugin-remove-graphql-queries/src/index.ts","lineNumber":272,"sourceCode":"\n  if (quasis.length !== 1) {\n    throw new StringInterpolationNotAllowedError(\n      quasis[0].loc?.end,\n      quasis[1].loc?.start\n    )\n  }\n\n  const text: string = quasis[0].value.raw\n  const normalizedText: string = graphql.stripIgnoredCharacters(text)\n\n  const hash: number = murmurhash(normalizedText, 0)\n  const location = quasis[0].loc as SourceLocation | null\n\n  try {\n    const ast = graphql.parse(text)\n\n    if (ast.definitions.length === 0) {\n      throw new EmptyGraphQLTagError(location)\n    }\n    return { ast, text: normalizedText, hash, isGlobal }\n  } catch (err) {\n    throw new GraphQLSyntaxError(text, err, location)\n  }\n}\n\nfunction isUseStaticQuery(path: NodePath<CallExpression>): boolean {\n  const callee = path.node.callee\n  if (callee.type === `MemberExpression`) {\n    const property = callee.property as Identifier\n    if (property.name === `useStaticQuery`) {\n      return (path.get(`callee`).get(`object`) as NodePath).referencesImport(\n        `gatsby`,\n        ``\n      )\n    }\n    return false","sourceCodeStart":254,"sourceCodeEnd":290,"githubUrl":"https://github.com/gatsbyjs/gatsby/blob/8b06340921ffdf23125a365b9c9923690cb62ce6/packages/babel-plugin-remove-graphql-queries/src/index.ts#L254-L290","documentation":"Thrown by `EmptyGraphQLTagError` (index.ts:272). After successfully parsing the graphql template literal, if `ast.definitions.length === 0` the tag contained no operation or fragment — just whitespace/comments. Gatsby has nothing to compile, so the build aborts. The error attaches `templateLoc` for source mapping.","triggerScenarios":"Writing `graphql``` or `graphql`   ``; leaving a placeholder graphql tag while scaffolding; accidentally stripping the query body during a refactor.","commonSituations":"Scaffolding a page/StaticQuery and forgetting to fill in the query; commenting out the query body but leaving the tag; copy-paste leaving an empty tag.","solutions":["Add a real query or fragment body inside the graphql tag.","Remove the empty graphql tag if it is unused.","Check the `templateLoc` attached to the error to find the offending file/line."],"exampleFix":"// before\nconst data = useStaticQuery(graphql``)\n\n// after\nconst data = useStaticQuery(graphql`\n  query SiteTitle {\n    site { siteMetadata { title } }\n  }\n`)","handlingStrategy":"validation","validationCode":"function graphqlTagHasBody(rawText) {\n  return rawText.trim().length > 0 && graphql.parse(rawText).definitions.length > 0\n}","typeGuard":"function isNonEmptyGraphqlTag(raw) {\n  const ast = graphql.parse(raw)\n  return ast.definitions.length > 0\n}","tryCatchPattern":"try {\n  getGraphQLTag(path)\n} catch (e) {\n  if (e instanceof EmptyGraphQLTagError) { /* remove or fill the tag */ }\n}","preventionTips":["Fill in graphql tags before committing scaffolds.","Use the templateLoc on the error to jump to the offending tag.","Add an ESLint rule to flag empty graphql```` tags."],"tags":["babel","graphql","empty-query"],"backgroundTag":null,"analyzedSha":"8b06340921ffdf23125a365b9c9923690cb62ce6","analyzedAt":"2026-08-13T02:36:21.405Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}