Skip to content

Latest commit

 

History

History
50 lines (38 loc) · 1.49 KB

README.md

File metadata and controls

50 lines (38 loc) · 1.49 KB

graphqlgen-webpack-plugin

Runs graphqlgen as part of the Webpack compilation process. It will run before type-checkers like fork-ts-checker-webpack-plugin.

Usage

graphqlgen-webpack-plugin takes the same options as graphqlgen. While graphqlgen's options are specified in the file graphqlgen.yml, graphqlgen-webpack-plugin instead takes options directly through the plugin constructor, like other Webpack plugins. This plugin does NOT read graphqlgen.yml.

Install as a dev dependency:

npm install --save-dev graphqlgen-webpack-plugin

Then, add the plugin to the plugins array in your Webpack config:

const GraphqlgenWebpackPlugin = require("graphqlgen-webpack-plugin");

// ....

plugins: [
    new GraphqlgenWebpackPlugin({
        language: "typescript",
        schema: path.join(__dirname, "src/schema.graphql"),
        context: path.join(__dirname, "src/types.ts:GraphQLContext"),
        output: path.join(__dirname, "src/generated/graphql.ts"),
        models: {
            files: [
                path.join(__dirname, "src/models/**/*.ts")
            ]
        }
    })
]

This is equivalent to a graphqlgen.yml file that looks like this:

language: typescript
schema: ./src/schema.graphql
context: ./src/types.ts:GraphQLContext
output: ./src/generated/graphql.ts
models:
  files:
    - ./src/models/**/*.ts

Read the graphqlgen documentation for more details about options.