graphql-tag.macro is a Babel macro that inlines GraphQL query parsing at build time, replacing the runtime call to graphql-tag's gql tag function with the pre-parsed AST. Version 2.0.1 is current, with TypeScript definitions added in 2.1.0. It requires babel-plugin-macros and works with any Babel-based build system. Unlike runtime graphql-tag, this macro eliminates parsing overhead in production bundles. It supports fragment interpolation and is primarily used in GraphQL client projects (Apollo, URQL). Release cadence is low; last major version bumped deps for compatibility.
npm install graphql-tag.macroVerified import paths — ran on the pinned version, not inferred.
Shows installation, Babel macro setup, and usage of gql tag from the macro to inline parsed AST.
Use import gql from 'graphql-tag.macro'
Add .default to the require() result
Update babel-plugin-macros to >=2.0.0
npm install --save-dev graphql-tag.macro
Use import gql from 'graphql-tag.macro' or require('graphql-tag.macro').defaultAdd 'macros' to Babel plugins: { "plugins": ["macros"] }