diff --git a/README.md b/README.md index 4a05490..d3e7f1c 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,13 @@ Convert a server graphql schema into a client-safe schema to use with [Cashay][]. +Compatible with graphql ^0.7.1 and cashay ^0.22.0. (You must install them yourself) + +``` +npm i --save graphql +npm i --save cashay +``` + ## Installation @@ -49,15 +56,17 @@ path that you specify. ## Usage -Note: You must bring your own graphql +Note: You must bring your own graphql and cashay ```js 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' }); @@ -75,6 +84,7 @@ This can be done easily with [broccoli-babel-transpiler](https://github.com/babe var esTranspiler = require('broccoli-babel-transpiler'); var node = cashaySchemaGenerator(esTranspiler(inputNode), { + cashay: cashay, graphql: graphql, clientSchemaPath: 'client/schema.js' }); diff --git a/index.js b/index.js index 1aa3355..e5ddf61 100644 --- a/index.js +++ b/index.js @@ -6,13 +6,24 @@ var Filter = require('broccoli-filter'); var fs = require('fs'); var mkdirp = require('mkdirp'); var path = require('path'); -var transformSchema = require('cashay').transformSchema; module.exports = CashaySchema; CashaySchema.prototype = Object.create(Filter.prototype); CashaySchema.constructor = CashaySchema; +function checkOptions(options) { + if (!options.graphql) { + throw new Error( + 'You must provide the graphql package to broccoli-cashay-schema'); + } + + if (!options.cashay) { + throw new Error( + 'You must provide the cashay package to broccoli-cashay-schema'); + } +} + function CashaySchema(inputNode, _options) { var options = _options || {}; @@ -20,14 +31,14 @@ function CashaySchema(inputNode, _options) { return new CashaySchema(inputNode, options); } - if (!options.graphql) { - throw new Error('You must provide the graphql package'); - } + checkOptions(options); Filter.call(this, inputNode, { annotation: options.annotation }); + // Cashay package + this.cashay = options.cashay; // GraphQL package this.graphql = options.graphql; // Server schema path relative to `inputNode` @@ -53,7 +64,7 @@ CashaySchema.prototype.processFile = function(srcDir, destDir, relativePath) { var rootSchema = require(fullPath)(this.graphql); // Generate a client-safe schema - return transformSchema(rootSchema, this.graphql.graphql). + return this.cashay.transformSchema(rootSchema, this.graphql.graphql). then(function(clientSchema) { var content = 'export default ' + JSON.stringify(clientSchema); mkdirp.sync(path.dirname(outputPath)); diff --git a/package.json b/package.json index 853f344..4e11099 100644 --- a/package.json +++ b/package.json @@ -21,11 +21,14 @@ "homepage": "https://github.com/dustinfarris/broccoli-cashay-schema#readme", "dependencies": { "broccoli-filter": "^1.2.4", - "cashay": "^0.22.0", "mkdirp": "^0.5.1", "string.prototype.startswith": "^0.2.0" }, "devDependencies": { "eslint": "^3.10.2" + }, + "peerDependencies": { + "cashay": "^0.22.0", + "graphql": "^0.7.1" } }