A Babel plugin (v2.8.1) that enables importing .graphql and .gql files directly in JavaScript/TypeScript code, converting them into GraphQL AST objects via graphql-tag. Supports schema files with #import syntax, operation/fragment files with all import variants, and emits .d.ts declarations. Requires graphql >=0.9.6 and graphql-tag >=2.1.0 as peer dependencies. Commonly used in Apollo projects to avoid string literals and manual parsing. Active but with infrequent updates (last release January 2021).
npm install babel-plugin-import-graphqlVerified import paths — ran on the pinned version, not inferred.
Shows basic setup: Babel plugin configuration, a GraphQL query file, and import/use in a React Apollo component.
Prepend your start script with 'rm -rf ./node_modules/.cache/babel-loader' or use --reset-cache for React Native.
Replace 'babel-plugin-inline-import-graphql-ast' with 'babel-plugin-import-graphql' in package.json and Babel config; minimum version 2.4.4.
Use 'rimraf' or another cross-platform command to delete node_modules/.cache/babel-loader.
Upgrade to v2.8.0 or later for Node v12+ compatibility.
Store each type in a separate file if selective imports are needed.
Add 'import-graphql' to Babel plugins in your webpack config (typically via .babelrc or babel.config.js).
Install graphql-tag: npm install graphql-tag
Ensure you are importing the default export from the .graphql file, not a named export unless the plugin does not support named exports for that file type.
Use 'plugins': ['import-graphql'] in babel.config.js or .babelrc; ensure @babel/core is installed.