2.2.2 • Published 5 years ago

graphschematojson v2.2.2

Weekly downloads
7
License
ISC
Repository
github
Last release
5 years ago

graphSchemaToJson

Convert graphQL Schema to readable Javascript/JSON/Typescript Objects

Install

npm i -D graphschematojson

Example usage CLI

npx graphschematojson file=./examples/author.graphql outFile=./output.js

CLI options

OptionRequiredDefaultDescription
fileNo.graphql or .gql file to use
dirNoDirectory to find graphql files. Specified only if file is not used
outFileYesOutput file may end in .js .json or .ts depending on preference.

Example usage Code

import fs from 'fs'
import { toSchema } from 'graphschematojson/dist'

const schema = fs.readFileSync('./test.graphql', 'utf8')

fs.writeFileSync('./output.json', JSON.stringify(toSchema(schema), null, 4))

Example output from running npx graphqlschematojson dir=./examples outFile=./output.js

export default {
    types: {
        Author: {
            fields: {
                name: {
                    isNullable: false,
                    isList: false,
                    directives: {},
                    type: 'String'
                },
                Books: {
                    isNullable: true,
                    isList: true,
                    directives: {
                        Bar: {
                            baz: 'bleh'
                        }
                    },
                    type: 'Book'
                }
            },
            directives: {
                Foo: {}
            },
            interfaces: []
        },
        Book: {
            fields: {
                title: {
                    isNullable: false,
                    isList: false,
                    directives: {},
                    type: 'String'
                },
                Authors: {
                    isNullable: false,
                    isList: false,
                    directives: {},
                    type: 'Author'
                }
            },
            directives: {
                Bar: {}
            },
            interfaces: []
        }
    },
    unions: {},
    interfaces: {}
}
2.2.2

5 years ago

2.2.1

5 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.0

5 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago