{"id":47913,"library":"graphql-normalizr","title":"graphql-normalizr","description":"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.","status":"active","version":"2.10.3","language":"javascript","source_language":"en","source_url":"https://github.com/monojack/graphql-normalizr","tags":["javascript","graphql","normalizr","normalizer"],"install":[{"cmd":"npm install graphql-normalizr","lang":"bash","label":"npm"},{"cmd":"yarn add graphql-normalizr","lang":"bash","label":"yarn"},{"cmd":"pnpm add graphql-normalizr","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency required for GraphQL type handling; v0.11 to v15 supported.","package":"graphql","optional":true}],"imports":[{"note":"The library exports `normalize` as a named export, not a default export.","wrong":"import normalize from 'graphql-normalizr'","symbol":"normalize","correct":"import { normalize } from 'graphql-normalizr'"},{"note":"The correct function name is `denormalize`, not `normalizr`.","wrong":"import { normalizr } from 'graphql-normalizr'","symbol":"denormalize","correct":"import { denormalize } from 'graphql-normalizr'"},{"note":"A helper to check if an object has __typename and id. Useful for custom logic.","wrong":null,"symbol":"isEntity","correct":"import { isEntity } from 'graphql-normalizr'"}],"quickstart":{"code":"import { normalize, denormalize } from 'graphql-normalizr';\n\nconst queryResult = {\n  data: {\n    findUser: [\n      {\n        __typename: 'User',\n        id: '1',\n        name: 'Alice',\n        posts: [\n          {\n            __typename: 'Post',\n            id: '10',\n            title: 'GraphQL Rocks'\n          }\n        ]\n      }\n    ]\n  }\n};\n\nconst schema = queryResult.data; // The data object itself\nconst normalized = normalize(schema);\nconsole.log(JSON.stringify(normalized, null, 2));\n// Output:\n// {\n//   \"User\": {\n//     \"1\": {\n//       \"id\": \"1\",\n//       \"name\": \"Alice\",\n//       \"posts\": [\"10\"]\n//     }\n//   },\n//   \"Post\": {\n//     \"10\": {\n//       \"id\": \"10\",\n//       \"title\": \"GraphQL Rocks\"\n//     }\n//   }\n// }\n\n// Denormalize back to original structure\nconst entityType = 'User';\nconst entityId = '1';\nconst denormalized = denormalize(entityType, entityId, normalized, schema);\nconsole.log(JSON.stringify(denormalized, null, 2));\n// Output matches the original findUser[0] object with nested posts populated.","lang":"typescript","description":"Shows how to use normalize and denormalize with a typical GraphQL query result."},"warnings":[{"fix":"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.","message":"The library expects every entity object to have a `__typename` and an `id` field. If your schema uses a different ID field (e.g., `_id` or `uuid`), normalization will not detect entities correctly.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Avoid passing scalar arrays directly; use a wrapper or filter them out before normalization.","message":"Arrays of scalars (e.g., [String]) will be treated as entity arrays and may cause unexpected behavior if those scalars have no `id`.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always pass the original `data` object (or the portion of the result that matches the query) as the fourth argument to denormalize.","message":"Denormalize requires the original schema (the query result structure) to reconstruct nested objects. If the schema is missing, denormalize may omit relationships.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use `normalize` (capital 'N' i.e., the Node.js style) instead.","message":"The `normalizr` export (lowercase) was used in early v1 but removed in v2. Using it will throw a runtime error.","severity":"deprecated","affected_versions":">=2.0.0"}],"env_vars":null,"search_vec":"'0.11':44 '15':46 'activ':94 'automat':73 'base':16,62 'browser':54 'cach':27,83 'client':25,78 'client-sid':24 'defin':89 'e.g':18 'entiti':15,21 'entity-bas':14 'entitytyp':19 'environ':55 'field':69,72 'flat':13 'flux/redux':29 'graphql':2,9,41,64,77,100 'graphql-normalizr':1,63 'id':20,71 'integr':75 'javascript':99 'leverag':66 'librari':6 'lightweight':5 'local':32 'maintain':95 'manag':34 'node.js':52 'normal':8,102 'normalizr':3,57,65,101 'regular':97 'releas':98 'requir':88 'respons':10 'schema':61,90 'schema-bas':60 'side':26 'simplifi':74 'state':33 'store':30 'strategi':84 'structur':17 'suitabl':22 'support':39 'typenam':68 'unlik':56 'unopinion':81 'upfront':91 'v2.10.3':37 'version':42 'work':49 'x':47","created_at":"2026-06-07T16:53:58.226672+00:00","updated_at":"2026-06-07T16:53:58.226672+00:00","problems":[{"fix":"Ensure your GraphQL query includes `__typename` on all nested objects, or add a custom resolver.","cause":"Missing `__typename` field on an entity in the GraphQL response (likely introspected).","error":"TypeError: __typename is not defined"},{"fix":"Add an `id` field to your GraphQL schema/query for each type that should be normalized.","cause":"Entity object is missing an `id` field; library expects every entity to have an `id`.","error":"TypeError: Cannot read properties of undefined (reading 'id')"},{"fix":"Use ES module import: `import { normalize } from 'graphql-normalizr'`.","cause":"Using CommonJS require() in an ESM environment (e.g., React with Vite).","error":"Uncaught ReferenceError: require is not defined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/monojack/graphql-normalizr#readme","github":"https://github.com/monojack/graphql-normalizr","docs":null,"changelog":null,"pypi":null,"npm":"graphql-normalizr","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}