Skip to content

nelson-ai/sort-graphql-schema

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sort GraphQL Schema

npm version Build Status Coverage Status PRs Welcome

Sort JSON GraphQL schemas for commit consistency. Useful when using Relay with non-deterministically auto-generated schemas.

Installation

Runs on Node v6 or higher.

npm install sort-graphql-schema --save-dev

or install globally for CLI usage:

npm install -g sort-graphql-schema

Usage

API:

const fs = require('fs')
const { graphql } = require('graphql');
const { introspectionQuery } = require('graphql/utilities');
const sortSchema = require('sort-graphql-schema');
const schema = require('./path/to/schema');

graphql(schema, introspectionQuery)
.then(result => {
  fs.writeFileSync('/path/to/output.json', JSON.stringify(sortSchema(result), null, 2));

  console.log('Done!');
});

CLI:

sort-graphql-schema schema.json

Contributing

Yes, thank you. Please lint, update/write tests and add your name to the package.json file before you PR.

License

MIT