graphql-field-visitor

0.0.3 • Public • Published

graphql-field-visitor

NPM version Build Status Coverage Status Maintainability codebeat badge devDependency Status JavaScript Style Guide

NPM Downloads

Iterates over all fields in all types declared in a GraphQL schema. It can be used for analysis, instrumentation or documentation of the schema.

Synopsis

const { visitFields } = require('graphql-field-visitor')

const schema = new GraphQLSchema({
  query: new GraphQLObjectType({
    name: 'Query',
    fields: () => { ... }
  })
})

// Prints all fields prefixed by their parent type.
visitFields(schema, (field, type) =>
  console.log(`${type.name}: ${field.name}`))

Installation

This module can be installed in your project using NPM or Yarn. Make sure, that you use Node.js version 8 or newer.

$ npm i graphql-field-visitor -S
$ yarn add graphql-field-visitor

Description

visitFields(schema, callback)

Iterates recursively over all fields in all types declared in a GraphQL schema. Each type is visited only once. Fields are visited using the depth-first strategy.

  • schema has to be an object instance of the type GraphQLSchema
  • callback has to be a function of the type GraphQLSchema receiving arguments:
    • field is the field configuration object
    • type is the parent type instance of the field
const { visitFields } = require('graphql-field-visitor')

const schema = ...

visitFields(schema, (field, type) => ...)

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

Release History

  • 2019-08-18 v0.0.1 Initial release

License

Copyright (c) 2019 Ferdinand Prantl

Licensed under the MIT license.

Package Sidebar

Install

npm i graphql-field-visitor

Weekly Downloads

6

Version

0.0.3

License

MIT

Unpacked Size

6.15 kB

Total Files

4

Last publish

Collaborators

  • prantlf