broccoli-cashay-schema

0.4.0 • Public • Published

broccoli-cashay-schema

CircleCI

Convert a server graphql schema into a client-safe schema to use with Cashay.

Compatible with graphql ^0.8.2 and cashay ^0.22.1. (You must install them yourself)

npm i --save graphql
npm i --save cashay

Installation

npm i --save broccoli-cashay-schema

Quick Start

Create a server schema, e.g.:

// server/schema-builder.js
 
import {
  GraphQLSchema,
  GraphQLObjectType,
  GraphQLString
} from 'graphql';
 
const query = new GraphQLObjectType({
  name: 'RootQueryType',
  fields: {
    hello: {
      type: GraphQLString,
      resolve() {
        return 'world';
      }
    }
  }
});
 
export default new GraphQLSchema({ query });

broccoli-cashay-schema will convert the schema into a new client-safe schema, and then write it back out to a path that you specify.

Usage

Note: You must bring your own graphql and cashay

var cashaySchemaGenerator = require('broccoli-cashay-schema');
var cashay = require('cashay');
var graphql = require('graphql');
 
// The plugin will look for a schema.js file in the node you provide
//   You can override with the option `serverSchemaPath`
var node = cashaySchemaGenerator(inputNode, {
  cashay: cashay,
  graphql: graphql,
  clientSchemaPath: 'client/schema.js'
});

ES6 Syntax

If you are (likely) using ES6 (ECMAScript 2015), you will need to transpile the schema file before passing it to broccoli-cashay-schema.

This can be done easily with broccoli-babel-transpiler:

var esTranspiler = require('broccoli-babel-transpiler');
 
var node = cashaySchemaGenerator(esTranspiler(inputNode), {
  cashay: cashay,
  graphql: graphql,
  clientSchemaPath: 'client/schema.js'
});

License

This project is distributed under the MIT license

Readme

Keywords

Package Sidebar

Install

npm i broccoli-cashay-schema

Weekly Downloads

2

Version

0.4.0

License

MIT

Last publish

Collaborators

  • dustinfarris