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);

Dependencies (0)

    Dev Dependencies (3)

    Package Sidebar

    Install

    npm i graphql-list-fields

    Weekly Downloads

    54,084

    Version

    2.0.4

    License

    MIT

    Unpacked Size

    4.2 kB

    Total Files

    3

    Last publish

    Collaborators

    • jakepusateri