graphql-filter-fragment
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

graphql-filter-fragment

Filters a data structure by a GraphQL fragment.

Example

import filterGraphQlFragment from 'graphql-filter-fragment';
import {gql} from '@apollo/client/core';

const result = filterGraphQlFragment(
  gql`
    fragment museum on Museum {
      name
      address {
        city
      }
    }
  `,
  {
    name: 'Museum of Popular Culture',
    address: {
      street: '325 5th Ave N',
      city: 'Seattle'
    }
  }
);

expect(result).toEqual({
  name: 'Museum of Popular Culture',
  address: {
    city: 'Seattle'
  }
});

Why?

This utility function is helpful to remove read-only fields before mutations if the data was fetched previously.

Credits

All credit goes to the graphql-anywhere package which is unfortunately not maintained anymore and the utilities no longer included in recent @apollo/client versions. The code in this repo is a direct copy-paste from the original code with an updated peer dependency version of graphql.

Readme

Keywords

Package Sidebar

Install

npm i graphql-filter-fragment

Weekly Downloads

4,867

Version

1.0.5

License

MIT

Unpacked Size

58.9 kB

Total Files

19

Last publish

Collaborators

  • amann