graphql-api-schema
TypeScript icon, indicating that this package has built-in type declarations

0.5.8 • Public • Published

graphql-api-schema

Generates a simple ApiSchema from GraphQLSchema to give simple way to navigate into with typescript.

Can generate and update a JSON file each time apiSchema is modified by a new graphQLSchema with apiSchema.setGraphQLSchema(graphQLSchema).

The JSON file hydrate apiSchema at initialisation time when graphQLSchema is not given.

Examples

With the static form :

import { apiSchema } from 'graphql-api-schema'

// List of directives
apiSchema.directives.keys[] // => [ 'include', 'skip', 'deprecated' ]

// Args of directive 'skip'
apiSchema.directives['skip'].args.keys() // => [ 'if' ]

apiSchema.directives.get('skip').args.get('if') gives :

 {
  name: 'if',
  description: 'Skipped when true.',
  type: {
    isList: false,
    isNullable: false,
    of: {
      kind: 'SCALAR',
      name: 'Boolean',
      description: 'The `Boolean` scalar type represents `true` or `false`.'
    }
  },
  defaultValue: null
}

Initialisation

For the static version :

import { GraphQLApiSchema } from 'graphql-api-schema'
GraphQLApiSchema.init({
  // From root of project
  dirName: 'src'
  // File not modified if not different
  fileName: 'apiSchema.json'
  // Same parameter as for JSON.stringify
  jsonSpaces: 2
})

For the object version, apiSchema can't be accessed staticaly but work's the same way :

import { GraphQLApiSchema } from 'graphql-api-schema'
const graphQLApiSchema = new GraphQLApiSchema({
  dirName: 'src'
  fileName: 'apiSchema.json'
})

const apiSchema = graphQLApiSchema.apiSchema

File generation is optional.

Package Sidebar

Install

npm i graphql-api-schema

Weekly Downloads

1

Version

0.5.8

License

MIT

Unpacked Size

34.8 kB

Total Files

44

Last publish

Collaborators

  • stphdenis