1.0.5 • Published 2 years ago

graphql-filter-fragment v1.0.5

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

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.

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.1.0

2 years ago