0.3.0 • Published 8 years ago

@shopify/graphql-js-schema v0.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
8 years ago

Circle CI

graphql-js-schema

Transforms the JSON representation of a GraphQL schema into a set of ES6 type modules.

Table Of Contents

Installation

$ npm install @shopify/graphql-js-schema

Examples

To transform a GraphQL schema file (as json) into a set of ES6 consumable modules, run the following command.

graphql-js-schema --schema-file ./schema.json --outdir schema --schema-bundle-name="Schema"

This will create a directory called schema, and a root module called Schema in the file schema/schema.js. It wall also collect all the non-scalar types in schema/types, and export them. The top level bundle exists for convenience, but you can consume these modules however you like.

API

Exports one function that transforms a schema object into a list of files and their associated bodies.

import graphqlJsSchema from 'graphql-js-schema';

graphqlJsSchema(schemaHash, "BundleName").then((files) => {
  // Do stuff with hashes in the format:
  // {
  //   path: 'types/product.js',
  //   body: '...'
  // }
});

Schema Modules

import Schema from 'schema/schema';

Schema.Product.name // => Product
Schema.Product.implementsNode // => true

// Types are separated into scalars, objects and connections.

// Scalars:
Schema.Product.scalars
Schema.Product.scalars.handle
Schema.Product.scalars.handle.type // => String
Schema.Product.scalars.handle.kind // => SCALAR
Schema.Product.scalars.handle.isList // => false
Schema.Product.scalars.handle.args // => []

// Objects
Schema.Product.objects.images
Schema.Product.objects.images.type // => Image
Schema.Product.objects.images.kind // => OBJECT
Schema.Product.objects.images.isList // => true
Schema.Product.objects.images.args // => ["first", "maxWidth", "maxHeight", "crop", "scale"]

// Connections
Schema.Product.connections.collections
Schema.Product.connections.collections.type // => CollectionConnection
Schema.Product.connections.collections.kind // => OBJECT
Schema.Product.connections.collections.isList // => false
Schema.Product.connections.collections.args // => ["first", "after", "reverse"]

License

MIT, see LICENSE.md for details.

0.3.0

8 years ago

0.2.3

9 years ago

0.2.2

9 years ago

0.2.1

9 years ago

0.2.0

9 years ago

0.1.0

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago