graphql-codegen-webpack-plugin

A webpack plugin for GraphQL Code Generator.

Usage no npm install needed!

<script type="module">
  import graphqlCodegenWebpackPlugin from 'https://cdn.skypack.dev/graphql-codegen-webpack-plugin';
</script>

README

GraphQL Code Generator webpack plugin

A webpack plugin for GraphQL Code Generator.

Getting started

npm install graphql-codegen-webpack-plugin
# or
yarn add graphql-codegen-webpack-plugin

Create a configuration file for GraphQL Code Generator:

# codegen.yml
schema: 'path/to/schema/**/*.gql'
documents: 'path/to/documents/**/*.tsx'
generates:
  schema.ts:
    plugins:
      - typescript

Refer to the Config Reference when writing the configuration.

Finally, add the plugin to your webpack configuration:

// webpack.config.js
const {
  GraphQLCodegenWebpackPlugin,
} = require('graphql-codegen-webpack-plugin')

module.exports = {
  plugins: [
    new GraphQLCodegenWebpackPlugin({
      configPath: './graphql-codegen.yml',
    }),
  ],
}