Registry / database / graphql-field-mask

graphql-field-mask

JSON →
library0.2.1jsnpmunverified

Generate google.protobuf.FieldMask paths from a GraphQL resolve info object. Version 0.2.1 (as of early 2025), limited release history. Converts the requested GraphQL fields into a list of dot-notation paths that can be used with FieldMask. Supports custom field name mapping (e.g., camelCase to snake_case), custom scalars (e.g., Date fields expanded to day/month/year), extra dependent fields, and abstract types (e.g., oneof). Integrates with ProtoNexus for protobuf-aware GraphQL schemas. Requires GraphQL ^15.0.0 || ^16.0.0 as a peer dependency. Ships TypeScript definitions.

npm install graphql-field-mask
INSTALL
IMPORT
SIG · GRAPHQL-FIELD-MASK
G
graphql-field-mask
databasejavascriptv0.2.1
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.

fieldMaskPathsFromResolveInfo
import { fieldMaskPathsFromResolveInfo } from 'graphql-field-mask'
import fieldMaskPathsFromResolveInfo from 'graphql-field-mask'
This is a named export, not default. Always use named import.
GetFieldNameFunc
import { GetFieldNameFunc } from 'graphql-field-mask'
import { GetFieldNameFunc } from 'graphql-field-mask/types'
Type is exported from the main entry point, no separate path needed.
AddExtraFieldsFunc
import { AddExtraFieldsFunc } from 'graphql-field-mask'
const { AddExtraFieldsFunc } = require('graphql-field-mask')
Library is ESM-only. CommonJS require will break.
GetAbstractTypeFieldMaskPathsFunc
import { GetAbstractTypeFieldMaskPathsFunc } from 'graphql-field-mask'
Less commonly used; ensure you need it before importing.

Shows how to extract FieldMask paths from a GraphQL resolve info object and log them. Run with ts-node or similar.

import { fieldMaskPathsFromResolveInfo } from 'graphql-field-mask'; import { GraphQLObjectType, GraphQLString, GraphQLNonNull, GraphQLSchema, graphql } from 'graphql'; const UserType = new GraphQLObjectType({ name: 'User', fields: () => ({ id: { type: new GraphQLNonNull(GraphQLString) }, name: { type: GraphQLString }, email: { type: GraphQLString }, }), }); const QueryType = new GraphQLObjectType({ name: 'Query', fields: () => ({ viewer: { type: UserType, resolve(_source, _args, _context, info) { const paths = fieldMaskPathsFromResolveInfo('User', info); console.log(paths); // e.g., ['id', 'name', 'email'] return { id: '1', name: 'John', email: 'john@example.com' }; }, }, }), }); const schema = new GraphQLSchema({ query: QueryType }); async function main() { const result = await graphql({ schema, source: '{ viewer { id name } }' }); console.log(result.data); } main().catch(console.error);
Debug
Known issues
gotchaThe function fieldMaskPathsFromResolveInfo requires the type name as the first argument. If the type name is incorrect, the returned paths may be incomplete or wrong.
fix
Ensure the typeName matches the exact GraphQL type name (case-sensitive) of the resolving field.
affects: >=0.0.0
gotchaCustom field name mapping via getFieldName must return either a string (for scalar fields) or an array of strings (for custom scalar expansion). Returning null or undefined will skip the field.
fix
Always return a string or string[] from getFieldName. Use null to exclude the field.
affects: >=0.0.0
gotchaThe addExtraFields callback receives a field object and must return an array of extra field names (strings). These paths are appended to the mask, but may cause duplicates if not deduplicated.
fix
Return an empty array if no extra fields are needed. The library does not deduplicate paths.
affects: >=0.0.0
deprecatedNo breaking changes or deprecations reported in the current version.
fix
Stay updated with the library's releases.
affects: <=0.2.1
Errors
Common errors & fixes
TypeError: Cannot destructure property 'fieldName' of 'undefined' or 'null'.
getFieldName callback did not return a value for a field (returned undefined).
fix
Ensure getFieldName always returns a string, array of strings, or null/undefined to skip the field. Check that the function handles all field cases.
Error: Cannot read properties of undefined (reading 'map') in fieldMaskPathsFromResolveInfo
The info object passed might not have the expected GraphQLResolveInfo shape, or the typeName is incorrect leading to undefined fields.
fix
Verify that you are using the function inside a GraphQL resolver with a valid info argument, and typeName matches the type's name exactly.
Module not found: Can't resolve 'graphql-field-mask'
Package not installed or missing from node_modules.
fix
Run npm install graphql-field-mask (ensure graphql is also installed as a peer dependency).
Upgrade
Version history
0.2.1latest on npm
Audit
Dependencies
graphqlrequiredPeer dependency: provides GraphQLResolveInfo, GraphQLObjectType, graphql types used by the library
Agent activity
7 hits · last 30 days
node
6
Amazon
1
Resources
graphql-field-mask — npm install graphql-field-mask · libregistry