{"record":{"id":"3715c634af38b8f8","repo":"facebook/relay","slug":"babelpluginrelay-unexpected-empty-graphql-tag","errorCode":null,"errorMessage":"BabelPluginRelay: Unexpected empty graphql tag.","messagePattern":"BabelPluginRelay: Unexpected empty graphql tag\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/babel-plugin-relay/getValidGraphQLTag.js","lineNumber":44,"sourceCode":"  if (!tag.isIdentifier({name: 'graphql'})) {\n    return null;\n  }\n\n  const quasis = path.node.quasi.quasis;\n\n  if (quasis.length !== 1) {\n    throw new Error(\n      'BabelPluginRelay: Substitutions are not allowed in graphql fragments. ' +\n        'Included fragments should be referenced as `...MyModule_propName`.',\n    );\n  }\n\n  const text = quasis[0].value.raw;\n\n  const ast = GraphQL.parse(text, {experimentalFragmentVariables: true});\n\n  if (ast.definitions.length === 0) {\n    throw new Error('BabelPluginRelay: Unexpected empty graphql tag.');\n  }\n\n  return ast;\n}\n\nmodule.exports = getValidGraphQLTag;\n","sourceCodeStart":26,"sourceCodeEnd":51,"githubUrl":"https://github.com/facebook/relay/blob/668b1b85e06261aa3b58dabfc51f8b5524a70955/packages/babel-plugin-relay/getValidGraphQLTag.js#L26-L51","documentation":"getValidGraphQLTag parses the tag's raw text and throws if the resulting document has zero definitions — i.e. the graphql`` tag is empty or contains only whitespace/comments. Relay cannot compile an empty document, and an empty tag is almost certainly a coding mistake.","triggerScenarios":"graphql`` or graphql`   ` with no GraphQL text; a tag whose contents were deleted/commented out leaving nothing parseable; conditional string building that ended up empty (before the interpolation check).","commonSituations":"Refactoring that emptied a tag temporarily; git merge conflicts resolved leaving a blank tag; auto-generated code where the template string source is empty.","solutions":["Add a valid fragment or operation to the graphql tag","Remove the unused empty graphql tag and its variable if it is dead code","Restore the deleted document if it was removed accidentally (check version control)"],"exampleFix":"// before\nconst frag = graphql``;\n\n// after\nconst frag = graphql`fragment F on User { id }`;","handlingStrategy":"validation","validationCode":"function assertNonEmptyTag(text) {\n  const trimmed = text.trim();\n  if (!trimmed) throw new Error('graphql tag must not be empty');\n  const { parse } = require('graphql');\n  if (parse(trimmed).definitions.length === 0) {\n    throw new Error('graphql tag parsed to zero definitions');\n  }\n}","typeGuard":"const isNonEmptyGraphQL = (text) =>\n  typeof text === 'string' && text.trim().length > 0;","tryCatchPattern":null,"preventionTips":["Never commit empty or placeholder graphql`` tags; comment out the whole usage instead","Check merge conflicts for leftover empty template literals","Compile with the Relay compiler in CI to fail fast on empty documents"],"tags":["babel","build-time","graphql","relay"],"backgroundTag":"invalid-graphql-tag","analyzedSha":"668b1b85e06261aa3b58dabfc51f8b5524a70955","analyzedAt":"2026-09-02T19:57:20.783Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}