graphql-list-fields
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/graphql-list-fields package

2.0.4 • Public • Published

graphql-list-fields

npm version

When implementing a GraphQL server, it can be useful to know the list of fields being queried on a given type. This module takes a GraphQLResolveInfo object and returns a list of fields.

Supported features

  • Basic Fields
  • Fragments
  • Inline Fragments
  • @skip and @include directives
  • Nested fields into dot.notation
npm install --save graphql-list-fields

Usage

import getFieldNames from 'graphql-list-fields';

// in some resolve function
resolve(parent, args, context, info) {
    const fields = getFieldNames(info);
    return fetch('/someservice/?fields=' + fields.join(','));
}

Depth Limiting

getFieldNames also accepts an optional depth argument, for how many levels deep results should be returned.

The following will only return top-level fields:

const fields = getFieldNames(info, 1);

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 2.0.4
    15,154
    • latest

Version History

Package Sidebar

Install

npm i graphql-list-fields

Weekly Downloads

57,352

Version

2.0.4

License

MIT

Unpacked Size

4.2 kB

Total Files

3

Last publish

Collaborators

  • jakepusateri