0.1.5 • Published 5 years ago

graphqlgen-webpack-plugin v0.1.5

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

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.