{"record":{"id":"5373a4e109761f98","repo":"gatsbyjs/gatsby","slug":"babelpluginremovegraphqlqueries-string-interpolat","errorCode":null,"errorMessage":"BabelPluginRemoveGraphQLQueries: String interpolations are not allowed in graphql fragments. Included fragments should be referenced as `...MyModule_foo`.","messagePattern":"BabelPluginRemoveGraphQLQueries: String interpolations are not allowed in graphql fragments\\. Included fragments should be referenced as `\\.\\.\\.MyModule_foo`\\.","errorType":"exception","errorClass":"StringInterpolationNotAllowedError","httpStatus":null,"severity":"error","filePath":"packages/babel-plugin-remove-graphql-queries/src/index.ts","lineNumber":256,"sourceCode":"  }\n  if (importPath.isIdentifier()) {\n    removeVariableDeclaration(importPath)\n  }\n}\n\nfunction getGraphQLTag(\n  path: NodePath<TaggedTemplateExpression>,\n  tagName: string = `graphql`\n): IGraphQLTag {\n  const tag: NodePath = path.get(`tag`) as NodePath\n  const isGlobal: boolean = isGlobalIdentifier(tag, tagName)\n\n  if (!isGlobal && !isGraphqlTag(tag, tagName)) return {} as IGraphQLTag\n\n  const quasis: Array<TemplateElement> = path.node.quasi.quasis\n\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 }","sourceCodeStart":238,"sourceCodeEnd":274,"githubUrl":"https://github.com/gatsbyjs/gatsby/blob/8b06340921ffdf23125a365b9c9923690cb62ce6/packages/babel-plugin-remove-graphql-queries/src/index.ts#L238-L274","documentation":"Thrown by `StringInterpolationNotAllowedError` in babel-plugin-remove-graphql-queries (index.ts:256). The plugin extracts graphql template literals; if the template has more than one `quasi` (`quasis.length !== 1`) it means the developer used `${...}` interpolation inside the tag. Gatsby pre-compiles queries statically, so runtime interpolation is forbidden — fragments must be referenced via the `...Name` spread syntax and the graphql tag must contain only literal text.","triggerScenarios":"Writing `graphql`query { ${field} }``; interpolating a fragment string into a graphql tag; building a query dynamically with template expressions; mistakenly using `${variable}` where a fragment spread was intended.","commonSituations":"Trying to share query fragments by string concatenation; porting Apollo Client code that used interpolation; refactoring and accidentally leaving a `${}` inside a graphql tag.","solutions":["Replace `${MyFragment}` with the fragment spread `...MyFragment` inside the literal.","Ensure the graphql tag contains only literal text — move any dynamic parts out of the query.","Define the fragment with `graphql`fragment X on Y { ... }`` and reference it via spread."],"exampleFix":"// before\nconst query = graphql`\n  query {\n    ${userFragment}\n  }\n`\n\n// after\nconst query = graphql`\n  query {\n    ...UserFields\n  }\n`\nconst frag = graphql`\n  fragment UserFields on User { id name }\n`","handlingStrategy":"validation","validationCode":"function graphqlTagHasNoInterpolation(quasis) {\n  return quasis.length === 1\n}","typeGuard":"function isPureTemplateLiteral(node) {\n  return node.quasis.length === 1 && node.expressions.length === 0\n}","tryCatchPattern":"try {\n  getGraphQLTag(path)\n} catch (e) {\n  if (e instanceof StringInterpolationNotAllowedError) { /* convert ${x} -> ...X spread */ }\n}","preventionTips":["Never interpolate inside a graphql`...` tag.","Reference fragments via `...FragmentName` spread.","Lint for template expressions inside graphql tags."],"tags":["babel","graphql","interpolation","fragments"],"backgroundTag":null,"analyzedSha":"8b06340921ffdf23125a365b9c9923690cb62ce6","analyzedAt":"2026-08-13T02:36:21.405Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}