Git Product home page Git Product logo

graphql-to-json's Introduction

graphql-to-json

A Node.js module to generate a JSON representation of your GraphQL schema

Why

If you are using Facebook's Relay, you know (or will soon find out) that you need to provide a JSON version of your GraphQL schema to the Babel Relay Plugin. This very simple module allows you to generate the JSON representation very easily. The module does what is described in the related section of Relay's documentation.

Installation

If you want to use graphql-to-json as a CLI tool, install it globally with npm:

npm install -g graphql-to-json

If you want to use it as module, install it locally:

npm install --save graphql-to-json

Usage

As a module

graphqlToJson({input: String, [output: String]}, [callback]);

Parameters

  • input String : relative or absolute path to a node module which exports a GraphQLSchema. instance
  • output String (optional) : relative or absolute path where you want to create the file containing the JSON version of your schema. If this parameter is not provided, no file is created.
  • callback Function (optional) : a function to execute when the schema is generated. The function is called with the JSON schema as its first parameter.

Returns

  • Promise : a promise which is resolved with the JSON schema.

As a CLI tool

graphql-to-json INPUT [OUTPUT]

See above for more information about the parameters.

NB : the CLI just calls the function exported by the module, but if no output is provided, a file called schema.json is created where the command is executed.

Examples

As a module, with no callback

// index.js
// the file that creates your GraphQLSchema is located at ./data/schema.js
const graphqlToJson = require('graphql-to-json');
graphqlToJson({input: './data/schema.js', output: './data/schema.json'});

As a module, with a callback and no output parameter

const graphqlToJson = require('graphql-to-json');
graphqlToJson({input: './data/schema.js'}, (schema) => console.log(schema));
// no output file is created

As a module, with a promise and an output parameter

const graphqlToJson = require('graphql-to-json');
graphqlToJson({
  input: './data/schema.js',
  output: './data/schema.json'
}).then((schema) => console.log(schema));
// schema.json is created in ./data

As a CLI tool

$ graphql-to-json ./data/schema.js ./data/schema.json

License

MIT License

Copyright (c) 2016 Waldo Jeffers

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

graphql-to-json's People

Contributors

waldojeffers avatar

Watchers

Tejesh Mehta avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.