rollup-plugin-graphql-tag

raw JSON →
0.1.0 verified Mon Apr 27 auth: no javascript maintenance

Rollup plugin that imports GraphQL files (.graphql, .gql) and compiles them into JavaScript modules using graphql-tag. Supports Apollo-style type definitions and fragment imports. Version 0.1.0, stable but no recent updates. Suitable for bundling GraphQL schemas with Rollup, alternative to raw loader plugins. Requires graphql as peer dependency. Not compatible with GraphQL v15+. Converts graphql files into transpiled query/mutation/subscription documents.

error Error: Cannot find module 'rollup-plugin-graphql-tag'
cause Package not installed or missing in node_modules
fix
npm install rollup-plugin-graphql-tag --save-dev
error Error: Could not resolve './schema.graphql' from src/index.js
cause Rollup cannot resolve the .graphql file without the plugin
fix
Add rollup-plugin-graphql-tag to plugins array in rollup.config.js
error Error: Cannot use import statement outside a module
cause Using ES modules in a CommonJS context (e.g., require() in rollup.config.js)
fix
Use rollup.config.mjs or set type: module in package.json, or use dynamic import
gotcha Plugin does not support GraphQL v15+ peer dependency. Install graphql@14 or below.
fix npm install graphql@14
deprecated Plugin is no longer actively maintained. Consider alternatives like @rollup/plugin-graphql.
fix Migrate to @rollup/plugin-graphql: npm install @rollup/plugin-graphql
gotcha Import path must match a file with .graphql or .gql extension, or configure options.include.
fix Ensure the import path ends with .graphql or .gql, or use include/exclude options.
breaking Exports graphql-tag compiled AST, not the raw string. Using toString() on imported document will fail.
fix Use the imported document directly with Apollo Client or graphql-tag's print function.
npm install rollup-plugin-graphql-tag
yarn add rollup-plugin-graphql-tag
pnpm add rollup-plugin-graphql-tag

Shows how to configure Rollup to import .graphql files using the plugin, and use the compiled schema in Apollo Server.

// rollup.config.js
import gql from 'rollup-plugin-graphql-tag';

export default {
  input: 'src/index.js',
  output: {
    dir: 'dist',
    format: 'esm'
  },
  plugins: [
    gql({
      // Options:
      // include: '**/*.graphql',
      // exclude: 'node_modules/**',
      // strip: true  // Remove whitespace to reduce bundle size
    })
  ]
};

// src/index.js
import { ApolloServer } from 'apollo-server';
import typeDefs from './schema.graphql';

const server = new ApolloServer({ typeDefs });