Skip to content

mventnor/graphqlgen-webpack-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Runs graphqlgen as part of the Webpack process

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published