graphql-map-deduplicator
v0.2.0
Published
`mapit()` will deduplicate graphql responses by generating a map of every entity that has `__typename` and `id` properties. It will pull those out and place them into a new root property `__map__` of the response. Entities without those properties are lef
Downloads
4
Readme
graphql-map-deduplicator
mapit()
will deduplicate graphql responses by generating a map of every entity that has __typename
and id
properties. It will pull those out and place them into a new root property __map__
of the response. Entities without those properties are left in place.
unmapit()
will remove the __map__
property and place them back into data object. It has an optional parameter {inMemory: true}
to unmap the object back in memory. This makes use of getters on the object to define a function that returns the mapped entity itself. This allows for a smaller memory footprint on really large responses.
Server example:
formatResponse: (response, context) => {
if (context.request.http?.headers.get('gql-map-dedupe') === 'true') {
response.data = mapit(response.data || {})
return response
}
return null
}
Client example:
const data = unmapit(mappedResponseData)
In memory example:
const data = unmapit(mappedResponseData, { inMemory: true })