A lightweight library that normalizes GraphQL responses into a flat, entity-based structure (e.g., { EntityType: { id: entity } }) suitable for client-side caching in Flux/Redux stores or local state management. As of v2.10.3, it supports any GraphQL version from 0.11 to 15.x and works in both Node.js and browser environments. Unlike normalizr (which is schema-based), graphql-normalizr leverages the `__typename` field and `id` field automatically, simplifying integration with GraphQL clients. It is unopinionated about caching strategies and does not require defining schemas upfront. It is actively maintained with regular releases.
npm install graphql-normalizrNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows how to use normalize and denormalize with a typical GraphQL query result.
Ensure all entity types have an `id` field and `__typename` in the GraphQL response, or use a wrapper to map fields before passing to normalize.
Avoid passing scalar arrays directly; use a wrapper or filter them out before normalization.
Always pass the original `data` object (or the portion of the result that matches the query) as the fourth argument to denormalize.
Use `normalize` (capital 'N' i.e., the Node.js style) instead.
Ensure your GraphQL query includes `__typename` on all nested objects, or add a custom resolver.
Add an `id` field to your GraphQL schema/query for each type that should be normalized.
Use ES module import: `import { normalize } from 'graphql-normalizr'`.