15270821319 4e5c5d37f9 初步设计数据库,注册登录 10 luni în urmă
..
README.md 4e5c5d37f9 初步设计数据库,注册登录 10 luni în urmă
index.js 4e5c5d37f9 初步设计数据库,注册登录 10 luni în urmă
package.json 4e5c5d37f9 初步设计数据库,注册登录 10 luni în urmă

README.md

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