Registry / testing / graphql-list-fields

graphql-list-fields

JSON →
library2.0.4jsnpmunverified

Utility to extract field names from a GraphQLResolveInfo object during query resolution. Current stable version 2.0.4 (last updated 2019). Lightweight, supports fragments, inline fragments, @skip/@include directives, and nested dot-notation. Minimal alternative to apollo-server's field introspection or custom resolver logic.

npm install graphql-list-fields
INSTALL
IMPORT
SIG · GRAPHQL-LIST-FIELD
G
graphql-list-fields
testingjavascriptv2.0.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import getFieldNames from 'graphql-list-fields'
const getFieldNames = require('graphql-list-fields');
The package exports a default function. CommonJS require works but TypeScript may need esModuleInterop.
getFieldNames
import getFieldNames from 'graphql-list-fields'
import { getFieldNames } from 'graphql-list-fields'
Named import is incorrect; the module has a default export only.
GraphQLResolveInfo
import type { GraphQLResolveInfo } from 'graphql'
import { GraphQLResolveInfo } from 'graphql-list-fields'
Type is exported by 'graphql', not this package.

Demonstrates extracting field names from GraphQLResolveInfo in a resolver.

import getFieldNames from 'graphql-list-fields'; import { graphql, buildSchema } from 'graphql'; const schema = buildSchema(` type Query { user: User } type User { id: ID name: String email: String } `); const rootValue = { user: (parent, args, context, info) => { const fields = getFieldNames(info); console.log(fields); // ['id', 'name', 'email'] return { id: '1', name: 'Alice', email: 'alice@example.com' }; } }; const query = '{ user { id name email } }'; graphql({ schema, source: query, rootValue }).then(response => { console.log(JSON.stringify(response)); });
Debug
Known issues
gotchaFields from fragments are included but may be duplicated if used multiple times.
fix
Deduplicate with Set or lodash.uniq.
affects: all
gotchaThe depth parameter (second argument) is 1-indexed; depth 1 returns only top-level fields, depth 2 includes nested, etc.
fix
Pass appropriate depth; depth 0 returns empty array.
affects: >=2.0.0
deprecatedPackage not updated since 2019; no GraphQL v16+ support verification.
fix
Test with your GraphQL version; consider alternatives like graphql-parse-resolve-info.
affects: 2.0.4
gotchaDoes not support @deprecated directive filtering or custom metadata.
fix
Use graphql-parse-resolve-info for advanced introspection.
affects: all
Errors
Common errors & fixes
TypeError: getFieldNames is not a function
Using named import instead of default import.
fix
Change 'import { getFieldNames } from 'graphql-list-fields'' to 'import getFieldNames from 'graphql-list-fields''.
Cannot find module 'graphql-list-fields' or its corresponding type declarations.
Missing type definitions; package has no built-in types.
fix
Install @types/graphql-list-fields or create a declaration file: declare module 'graphql-list-fields';
The request /someservice/?fields= returns empty string
getFieldNames returns empty array when called outside resolver or with invalid info.
fix
Ensure getFieldNames is called with the 'info' parameter from a GraphQL resolver.
Upgrade
Version history
2.0.4latest on npm
Audit
Dependencies
graphqlrequiredPeer dependency for GraphQLResolveInfo type integration.
Agent activity
8 hits · last 30 days
node
8
Resources
graphql-list-fields — npm install graphql-list-fields · libregistry