Socket
Socket
Sign inDemoInstall

graphql-list-fields

Package Overview
Dependencies
0
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    graphql-list-fields

Get a list of fields while resolving a GraphQL query


Version published
Weekly downloads
56K
decreased by-16.5%
Maintainers
1
Install size
4.10 kB
Created
Weekly downloads
 

Readme

Source

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

Keywords

FAQs

Last updated on 10 Feb 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc