Filters a data structure by a GraphQL fragment, useful for removing read-only fields before mutations. Current stable version is 1.0.5. Low release cadence (no updates since initial). Key differentiator: lightweight alternative to the deprecated 'graphql-anywhere' package, compatible with Apollo Client v3 and graphql v16, written in TypeScript.
npm install graphql-filter-fragmentNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows how to filter a data object to only keep fields defined in a GraphQL fragment.
Deep clone data before passing if you need to preserve original: const filtered = filterGraphQlFragment(fragment, JSON.parse(JSON.stringify(data)));
Use gql from '@apollo/client/core' to parse fragment.
Ensure fragment only includes fields you want to keep, without arguments/directives.
Use default import: import filterGraphQlFragment from 'graphql-filter-fragment';
Use gql from '@apollo/client/core' to parse the fragment string before passing.
Ensure fragment is defined and a valid gql DocumentNode.