graphql-field-visitor
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 typeGraphQLSchema
-
callback
has to be a function of the typeGraphQLSchema
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.