rollup-plugin-graphql-schema v1.0.4
rollup-plugin-graphql-schema
š£ A Rollup plugin which converts .graphql files to ES6 modules.
Requirements
This plugin requires an LTS Node version (v8.0.0+) and Rollup v1.20.0+.
Install
Using npm:
npm install rollup-plugin-graphql-schema --save-dev
Usage
Create a rollup.config.js
configuration file and import the plugin:
import graphql from 'rollup-plugin-graphql-schema';
export default {
input: 'src/index.js',
output: {
dir: 'output',
format: 'cjs'
},
plugins: [graphql()]
};
Then call rollup
either via the CLI or the API.
With an accompanying file src/index.js
, the local schema.graphql
file would now be importable as seen below:
// src/index.js
import express from 'express';
import { graphqlHTTP } from 'express-graphql';
// import schema.graphql file
import schema from './schema.graphql';
var root = { hello: () => 'Hello world!' };
var app = express();
app.use('/graphql', graphqlHTTP({
schema: schema,
rootValue: root,
graphiql: true,
}));
app.listen(4000, () => console.log('Now browse to localhost:4000/graphql'));
You can also use imports in .graphql files to modularize them:
# import Post from "posts.graphql"
type Query {
posts: [Post]
}
For more information about imports, see Using #import expression.
Options
exclude
Type: String
| Array[...String]
Default: null
A minimatch pattern, or array of patterns, which specifies the files in the build the plugin should ignore. By default no files are ignored.
include
Type: String
| Array[...String]
Default: null
A minimatch pattern, or array of patterns, which specifies the files in the build the plugin should operate on. By default all files are targeted.
exportAST
Type: boolean
Default: false (null)
The plugin will export GraphQLSchema object by default, but you can enable exportAST to export AST schema instead.