{"_id":"graphql-toe","_rev":"8-563f7c0aafdd3eb0ded0d1e695ebe801","name":"graphql-toe","dist-tags":{"latest":"1.0.0"},"versions":{"0.1.0":{"name":"graphql-toe","version":"0.1.0","keywords":["graphql","throw","error","errors","raise","exception","semantic","null","non-null","nullability","null","only","on","error"],"author":{"name":"Benjie Gillam","email":"code@benjiegillam.com"},"license":"MIT","_id":"graphql-toe@0.1.0","maintainers":[{"name":"benjie","email":"npm@benjiegillam.com"}],"dist":{"shasum":"ac3e1273b00525ef40c0a04825e1e3c6fe3cc339","tarball":"https://registry.npmjs.org/graphql-toe/-/graphql-toe-0.1.0.tgz","fileCount":4,"integrity":"sha512-uQzVAC6jMCj+luHT2HJR+YJyYVrxpjRkRXAUVsFiF+qYcx01C8rBZt59kKWoAyz0uBXT6sTOMA2AOJ59dOF+Pg==","signatures":[{"sig":"MEYCIQClsaIsTVdDSEtEDlhOhfomJcelbc775ur5zvIbYEjv0wIhAIIIizdNSaNK83tPv/oeuzTopAt1RRTOkLgxh8w4ec4/","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":6649},"main":"dist/index.js","types":"./dist/index.d.ts","gitHead":"1e2f0ff6e3d512b7bffac3aaf036e5113ffb4a7b","scripts":{"test":"node --test"},"_npmUser":{"name":"benjie","email":"npm@benjiegillam.com"},"prettier":{"proseWrap":"always"},"repository":{"url":"https+git://github.com/graphile/graphql-toe.git","type":"git"},"_npmVersion":"10.8.2","description":"GraphQL Throw-On-Error - incorporate error handling back into the reading of your data, so you can handle errors in the most natural way.","directories":{},"_nodeVersion":"20.17.0","_hasShrinkwrap":false,"devDependencies":{"graphql":"^16.9.0","prettier":"^3.3.3","typescript":"^5.6.2","@types/node":"^22.5.4","@tsconfig/recommended":"^1.0.7"},"_npmOperationalInternal":{"tmp":"tmp/graphql-toe_0.1.0_1726265582247_0.53098903159789","host":"s3://npm-registry-packages"}},"0.1.1":{"name":"graphql-toe","version":"0.1.1","keywords":["graphql","throw","error","errors","raise","exception","semantic","null","non-null","nullability","null","only","on","error"],"author":{"name":"Benjie Gillam","email":"code@benjiegillam.com"},"license":"MIT","_id":"graphql-toe@0.1.1","maintainers":[{"name":"benjie","email":"npm@benjiegillam.com"}],"dist":{"shasum":"e1a9be0efce0d7d4597f6b798298e3aac0f970d0","tarball":"https://registry.npmjs.org/graphql-toe/-/graphql-toe-0.1.1.tgz","fileCount":4,"integrity":"sha512-jOvYRHu0ufid10/Zm3f7N5+9Ys00XKZ8QcIonYz95/P6Va/EAN1wDmQVedpsRA16mT5cK15gZiUxijGkDpAT+A==","signatures":[{"sig":"MEUCIQD1g6v3Fa2xvRkRuFJDxE+cV0stXL5YbmZzTbcRD+g04gIgWKChlLmtqjWdhiY5zVGajUKnalxZj+Rj4nutXWFhv2s=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":7479},"main":"dist/index.js","types":"./dist/index.d.ts","gitHead":"c26bd6d8d1d21a0a631b89b6e4376ddfb7d4c1e8","scripts":{"test":"node --test"},"_npmUser":{"name":"benjie","email":"npm@benjiegillam.com"},"prettier":{"proseWrap":"always"},"repository":{"url":"https+git://github.com/graphile/graphql-toe.git","type":"git"},"_npmVersion":"10.8.2","description":"GraphQL Throw-On-Error - incorporate error handling back into the reading of your data, so you can handle errors in the most natural way.","directories":{},"_nodeVersion":"20.17.0","_hasShrinkwrap":false,"devDependencies":{"graphql":"^16.9.0","prettier":"^3.3.3","typescript":"^5.6.2","@types/node":"^22.5.4","@tsconfig/recommended":"^1.0.7"},"_npmOperationalInternal":{"tmp":"tmp/graphql-toe_0.1.1_1726266181044_0.3239033997586074","host":"s3://npm-registry-packages"}},"0.1.2":{"name":"graphql-toe","version":"0.1.2","keywords":["graphql","throw","error","errors","raise","exception","semantic","null","non-null","nullability","null","only","on","error"],"author":{"name":"Benjie Gillam","email":"code@benjiegillam.com"},"license":"MIT","_id":"graphql-toe@0.1.2","maintainers":[{"name":"benjie","email":"npm@benjiegillam.com"}],"homepage":"https://github.com/graphile/graphql-toe","bugs":{"url":"https://github.com/graphile/graphql-toe/issues"},"dist":{"shasum":"85469afe743ff6109f588689d1d5779c55437b56","tarball":"https://registry.npmjs.org/graphql-toe/-/graphql-toe-0.1.2.tgz","fileCount":4,"integrity":"sha512-XK04wXEHbLY33YHoPAnLMIafRKSOn7FTWzTCob23GC6o8DnO4ibkA8Aje+Udee8QdXx46TV6m6LQM9iU8C9vwQ==","signatures":[{"sig":"MEQCICVnanLZrNVVHSlrOc+0ETssBhlV4aSMSZMbVkNAI3mmAiAUdwKHTGCojGqaYT3mocUd6BNDVx3x/gIsa0ldGfCoxw==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":8262},"main":"dist/index.js","types":"./dist/index.d.ts","gitHead":"40cc05959d8e31e8a5680788a605a1639575c57e","scripts":{"test":"node --test"},"_npmUser":{"name":"benjie","email":"npm@benjiegillam.com"},"prettier":{"proseWrap":"always"},"repository":{"url":"https+git://github.com/graphile/graphql-toe.git","type":"git"},"_npmVersion":"10.8.2","description":"GraphQL Throw-On-Error - incorporate error handling back into the reading of your data, so you can handle errors in the most natural way.","directories":{},"_nodeVersion":"20.17.0","_hasShrinkwrap":false,"devDependencies":{"graphql":"^16.9.0","prettier":"^3.3.3","typescript":"^5.6.2","@types/node":"^22.5.4","@tsconfig/recommended":"^1.0.7"},"_npmOperationalInternal":{"tmp":"tmp/graphql-toe_0.1.2_1726267028926_0.13939557892897825","host":"s3://npm-registry-packages"}},"0.1.3":{"name":"graphql-toe","version":"0.1.3","keywords":["graphql","throw","error","errors","raise","exception","semantic","null","non-null","nullability","null","only","on","error"],"author":{"name":"Benjie Gillam","email":"code@benjiegillam.com"},"license":"MIT","_id":"graphql-toe@0.1.3","maintainers":[{"name":"benjie","email":"npm@benjiegillam.com"}],"homepage":"https://github.com/graphile/graphql-toe","bugs":{"url":"https://github.com/graphile/graphql-toe/issues"},"dist":{"shasum":"fe1191b18b0e8efc979449ec465951995bd13eff","tarball":"https://registry.npmjs.org/graphql-toe/-/graphql-toe-0.1.3.tgz","fileCount":2,"integrity":"sha512-/vllhqBO9bwoKJelll4JMG6suaT9FnATpauQlAVH8zWpkMnscAqHE4Eae8aSWAsalA45EnR5UeZXpbngGpVBLg==","signatures":[{"sig":"MEYCIQDWHcCOfuugehtvxci7PlIfbfSxG74BtZ9KxuldEC2gigIhAMSvmqNcIQdopVuMHgMdmi3g42jG7lWE6wYKj3CBuqO3","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":6518},"main":"dist/index.js","gitHead":"30d83f04b28432e8b2a8651401905aefb0831e69","scripts":{"test":"node --test"},"_npmUser":{"name":"benjie","email":"npm@benjiegillam.com"},"prettier":{"proseWrap":"always"},"repository":{"url":"https+git://github.com/graphile/graphql-toe.git","type":"git"},"_npmVersion":"10.2.4","description":"GraphQL Throw-On-Error - incorporate error handling back into the reading of your data, so you can handle errors in the most natural way.","directories":{},"_nodeVersion":"20.11.1","_hasShrinkwrap":false,"devDependencies":{"graphql":"^16.9.0","prettier":"^3.3.3","typescript":"^5.6.2","@types/node":"^22.5.4","@tsconfig/recommended":"^1.0.7"},"_npmOperationalInternal":{"tmp":"tmp/graphql-toe_0.1.3_1726772112842_0.9074636341696407","host":"s3://npm-registry-packages"}},"0.1.4":{"name":"graphql-toe","version":"0.1.4","keywords":["graphql","throw","error","errors","raise","exception","semantic","null","non-null","nullability","null","only","on","error"],"author":{"name":"Benjie Gillam","email":"code@benjiegillam.com"},"license":"MIT","_id":"graphql-toe@0.1.4","maintainers":[{"name":"benjie","email":"npm@benjiegillam.com"}],"homepage":"https://github.com/graphile/graphql-toe","bugs":{"url":"https://github.com/graphile/graphql-toe/issues"},"dist":{"shasum":"628d3238506c1f761e25c78599abd138c3efd38f","tarball":"https://registry.npmjs.org/graphql-toe/-/graphql-toe-0.1.4.tgz","fileCount":4,"integrity":"sha512-BKEjcgLj5tW1m3noqRXkzJy4rgh8DQrsK5r9rn4dEFs68QmfDaLyJJjJdl6OOzLIAIFM5HGTZtcVogr80aETlg==","signatures":[{"sig":"MEQCIFlWkMIpnpWgzV79qGGSFDQVYx2Ie0BGE1v2nqVCWGFOAiAHXrBHkNbOD1Jqm9bcRrMPYJIYf5pRSCAkqvTor+9IYA==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":9901},"main":"dist/index.js","types":"./dist/index.d.ts","gitHead":"e1ef2e87d98a58681f87d3106734fb43d708d205","scripts":{"test":"node --test","prepack":"tsc"},"_npmUser":{"name":"benjie","email":"npm@benjiegillam.com"},"prettier":{"proseWrap":"always"},"repository":{"url":"https+git://github.com/graphile/graphql-toe.git","type":"git"},"_npmVersion":"10.2.4","description":"GraphQL Throw-On-Error - incorporate error handling back into the reading of your data, so you can handle errors in the most natural way.","directories":{},"_nodeVersion":"20.11.1","_hasShrinkwrap":false,"devDependencies":{"graphql":"^16.9.0","prettier":"^3.3.3","typescript":"^5.6.2","@types/node":"^22.5.4","@tsconfig/recommended":"^1.0.7"},"_npmOperationalInternal":{"tmp":"tmp/graphql-toe_0.1.4_1727169927851_0.8806427750294532","host":"s3://npm-registry-packages"}},"1.0.0-rc.0":{"name":"graphql-toe","version":"1.0.0-rc.0","keywords":["graphql","throw","error","errors","raise","exception","semantic","null","non-null","nullability","null","only","on","error"],"author":{"name":"Benjie Gillam","email":"code@benjiegillam.com"},"license":"MIT","_id":"graphql-toe@1.0.0-rc.0","maintainers":[{"name":"benjie","email":"npm@benjiegillam.com"}],"homepage":"https://github.com/graphile/graphql-toe","bugs":{"url":"https://github.com/graphile/graphql-toe/issues"},"dist":{"shasum":"76e469aa8d873a4d15289ddf13759045adcd5096","tarball":"https://registry.npmjs.org/graphql-toe/-/graphql-toe-1.0.0-rc.0.tgz","fileCount":4,"integrity":"sha512-/reEXGT1QCrQkweajQvbK298u/duyEHGftzKlFO0K3kD050USxD55bQw0QctjhCzKEZJIvdkoCxoUfijHv4izg==","signatures":[{"sig":"MEUCIDoEuBYkoQBN1EJQpEjivbU8tbfVhqN1KShBIJZqhkAxAiEAwmeJgOFj6QMiRZJOBFJwbMGoO5PH0s4ti8biZ12C/Vo=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":11523},"main":"dist/index.js","types":"./dist/index.d.ts","gitHead":"34f4e9596f07153a902cb04ca0a8f88eb119e621","scripts":{"test":"yarn prepack && node --test","prepack":"tsc"},"_npmUser":{"name":"benjie","email":"npm@benjiegillam.com"},"prettier":{"proseWrap":"always"},"repository":{"url":"https+git://github.com/graphile/graphql-toe.git","type":"git"},"_npmVersion":"10.8.2","description":"GraphQL Throw-On-Error - incorporate error handling back into the reading of your data, so you can handle errors in the most natural way.","directories":{},"_nodeVersion":"20.18.1","_hasShrinkwrap":false,"devDependencies":{"graphql":"^16.9.0","prettier":"^3.3.3","typescript":"^5.6.2","@types/node":"^22.5.4","@tsconfig/recommended":"^1.0.7"},"_npmOperationalInternal":{"tmp":"tmp/graphql-toe_1.0.0-rc.0_1742561145305_0.9023803961464527","host":"s3://npm-registry-packages-npm-production"}},"1.0.0-rc.1":{"name":"graphql-toe","version":"1.0.0-rc.1","keywords":["graphql","throw","error","errors","raise","exception","semantic","null","non-null","nullability","null","only","on","error"],"author":{"name":"Benjie Gillam","email":"code@benjiegillam.com"},"license":"MIT","_id":"graphql-toe@1.0.0-rc.1","maintainers":[{"name":"benjie","email":"npm@benjiegillam.com"}],"homepage":"https://github.com/graphile/graphql-toe","bugs":{"url":"https://github.com/graphile/graphql-toe/issues"},"dist":{"shasum":"f5fbbe544091ed83af1d4a6810e1684ce71026f3","tarball":"https://registry.npmjs.org/graphql-toe/-/graphql-toe-1.0.0-rc.1.tgz","fileCount":4,"integrity":"sha512-9PyhwmGQK7ccoo1gm2dtLkZiQ2qk6oVNylTixFxkuaVimMTE2RXyXtFdrNvuqctsHgSuroTb/38hv2+6PY3pHQ==","signatures":[{"sig":"MEQCIEJFlS14P57Sk3U1wMgd/PuRoFb1FvDR+wXDuyUTm81cAiA1OYPY7HZbARrbcZeY9+FrfzkJ5iLlH4pQa04nOZTEnQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":12798},"main":"dist/index.js","types":"./dist/index.d.ts","gitHead":"bef01bac06b85f84cf8f55a6d9dee693f0e7a2b5","scripts":{"test":"yarn prepack && node --test","prepack":"tsc"},"_npmUser":{"name":"benjie","email":"npm@benjiegillam.com"},"prettier":{"proseWrap":"always"},"repository":{"url":"https+git://github.com/graphile/graphql-toe.git","type":"git"},"_npmVersion":"10.9.2","description":"GraphQL Throw-On-Error - incorporate error handling back into the reading of your data, so you can handle errors in the most natural way.","directories":{},"_nodeVersion":"22.15.0","_hasShrinkwrap":false,"devDependencies":{"graphql":"^16.9.0","prettier":"^3.3.3","typescript":"^5.6.2","@types/node":"^22.5.4","@tsconfig/recommended":"^1.0.7"},"_npmOperationalInternal":{"tmp":"tmp/graphql-toe_1.0.0-rc.1_1756485459414_0.6186707858275411","host":"s3://npm-registry-packages-npm-production"}},"1.0.0":{"name":"graphql-toe","version":"1.0.0","description":"GraphQL Throw-On-Error - incorporate error handling back into the reading of your data, so you can handle errors in the most natural way.","main":"dist/index.js","scripts":{"prepack":"tsc","test":"yarn prepack && node --test"},"repository":{"type":"git","url":"https+git://github.com/graphile/graphql-toe.git"},"bugs":{"url":"https://github.com/graphile/graphql-toe/issues"},"homepage":"https://github.com/graphile/graphql-toe","keywords":["graphql","throw","error","errors","raise","exception","semantic","null","non-null","nullability","null","only","on","error"],"author":{"name":"Benjie Gillam","email":"code@benjiegillam.com"},"license":"MIT","devDependencies":{"@tsconfig/recommended":"^1.0.7","@types/node":"^22.5.4","graphql":"^16.9.0","prettier":"^3.3.3","typescript":"^5.6.2"},"prettier":{"proseWrap":"always"},"_id":"graphql-toe@1.0.0","gitHead":"2942ce530ad20cba8bdcb8a7b8123f4024b45cc7","types":"./dist/index.d.ts","_nodeVersion":"22.15.0","_npmVersion":"10.9.2","dist":{"integrity":"sha512-gu2GOt9oHaj3EAWfwYVBOeYMcvLLzeYxzCL7IBcjCwE0LRTAP4FpFnjLHMzoIKyZaRFqgqBAulKRvEfhQ7dHag==","shasum":"fe16db449f12f078a3ed1420c08d2e7ddeb7b9e4","tarball":"https://registry.npmjs.org/graphql-toe/-/graphql-toe-1.0.0.tgz","fileCount":4,"unpackedSize":12817,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIF7i5zWt3Ua5U/82UkhWfKP7N3aIw29HCpZ3wrT/RCHAAiAYEuZ64kZypQU07I97X6KCC82Ar40PxXH4zl4PHnzsVA=="}]},"_npmUser":{"name":"benjie","email":"npm@benjiegillam.com"},"directories":{},"maintainers":[{"name":"benjie","email":"npm@benjiegillam.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/graphql-toe_1.0.0_1756485642722_0.2416549228639664"},"_hasShrinkwrap":false}},"time":{"created":"2024-09-13T22:13:02.246Z","modified":"2025-08-29T16:40:43.078Z","0.1.0":"2024-09-13T22:13:02.648Z","0.1.1":"2024-09-13T22:23:01.161Z","0.1.2":"2024-09-13T22:37:09.110Z","0.1.3":"2024-09-19T18:55:13.043Z","0.1.4":"2024-09-24T09:25:28.035Z","1.0.0-rc.0":"2025-03-21T12:45:45.463Z","1.0.0-rc.1":"2025-08-29T16:37:39.607Z","1.0.0":"2025-08-29T16:40:42.895Z"},"bugs":{"url":"https://github.com/graphile/graphql-toe/issues"},"author":{"name":"Benjie Gillam","email":"code@benjiegillam.com"},"license":"MIT","homepage":"https://github.com/graphile/graphql-toe","keywords":["graphql","throw","error","errors","raise","exception","semantic","null","non-null","nullability","null","only","on","error"],"repository":{"type":"git","url":"https+git://github.com/graphile/graphql-toe.git"},"description":"GraphQL Throw-On-Error - incorporate error handling back into the reading of your data, so you can handle errors in the most natural way.","maintainers":[{"name":"benjie","email":"npm@benjiegillam.com"}],"readme":"# GraphQL TOE (Throw On Error)\n\n**The <512 byte solution to your GraphQL ambiguous `null` woes.**\n\nWorks with:\n\n- Apollo Client\n- URQL\n- graffle\n- window.fetch()\n- _any_ GraphQL client that returns the JSON `{ data, errors }`\n\n**Not needed with Relay** as it has native error handling support via the\n[@throwOnFieldError](https://relay.dev/docs/guides/throw-on-field-error-directive/)\nand [@catch](https://relay.dev/docs/guides/catch-directive/) directives.\n\n## The problem\n\nYou read `null` from a field in GraphQL... but is that a data-null (explicit\nnon-existence) or an error-null (something went wrong)? This is an important\ndistinction: your boyfriend's profile page showing `Partner: none` is very\ndifferent than it showing `Error loading partner`!\n\nIf you're not using an error-handling GraphQL client, then for each `null` you\nsee in a GraphQL response you must check through the `errors` list to determine\nif it relates to an error or not. To do so, you need to know the path of the\ncurrently rendering data - instead of just passing the data to your component,\nyou need to pass the root list of errors, and the path of the data being\nrendered.\n\nManaging this yourself is a huge hassle, and most people don't bother - instead\neither rejecting requests that include errors (and losing the \"partial success\"\nbenefit of GraphQL) or treating all `null` as ambiguous: maybe it errored, maybe\nit's null, we don't know. Or worse, they treat an error-null as if it is a\ndata-null, and cause much heartbreak!\n\n**Well, no more!**\n\n## The solution\n\nGraphQL-TOE transforms your GraphQL response (`{ data: {...}, errors: [...] }`)\ninto a new object that looks exactly like `data`, except it throws when you\naccess a position that is `null` due to an error. As such, your application can\nnever read an error-null (because the error will be thrown if you try) - so if\nyou read a `null` value you know it's definitely a data-null and can render it\nas such. And for the errors... you can handle them as any other throw error:\nwith native JavaScript methods like `try`/`catch`, or those built on top of them\nsuch as React's `<ErrorBoundary />`!\n\n**Stop writing code that second-guesses your data; re-throw GraphQL errors!**\n\n## Installation\n\n```bash\nyarn add graphql-toe\n# OR: npm install --save graphql-toe\n# OR: pnpm install --save graphql-toe\n```\n\n## Usage\n\n```ts\nimport { toe } from \"graphql-toe\";\n\nconst result = await fetch(/* ... */).then((res) => res.json());\nconst data = toe(result);\n```\n\nIf `result.data` is `null` or not present, `toe(result)` will throw immediately.\nOtherwise, `data` is a derivative of `result.data` where errored fields are\nreplaced with throwing getters.\n\n## Zero dependencies\n\n**Under 512 bytes** gzipped\n([v1.0.0-rc.1 was 471 bytes according to bundlephobia](https://bundlephobia.com/package/graphql-toe@1.0.0-rc.1))\n\nWorks with _any_ GraphQL client that returns `{ data, errors }`.\n\nErrors are thrown as-is; you can pre-process them to wrap in `Error` or\n`GraphQLError` if needed:\n\n```ts\nimport { GraphQLError } from \"graphql\";\nimport { toe } from \"graphql-toe\";\n\nconst mappedResult = {\n  ...result,\n  errors: result.errors?.map(\n    (e) =>\n      new GraphQLError(e.message, {\n        positions: e.positions,\n        path: e.path,\n        originalError: e,\n        extensions: e.extensions,\n      }),\n  ),\n};\nconst data = toe(mappedResult);\n```\n\n## Example\n\n```ts\nimport { toe } from \"graphql-toe\";\n\n// Result of query `{ users(first: 3) { id, name } }`\nconst graphqlResult = {\n  data: {\n    users: [\n      { id: 1, name: \"Alice\" },\n      null, // < An error occurred\n      { id: 3, name: \"Caroline\" },\n    ],\n  },\n  errors: [\n    {\n      path: [\"users\", 1],\n      message: \"Loading user 2 failed!\",\n    },\n  ],\n};\n\n// Return the transformed data that will Throw On Error:\nconst data = toe(graphqlResult);\n\nconsole.log(data.users[0]); // Logs { id: 1, name: \"Alice\" }\nconsole.log(data.users[1]); // Throws \"Loading user 2 failed!\"\n```\n\n## Framework examples\n\nDifferent frameworks and libraries have different approaches to feeding the\nGraphQL result into GraphQL-TOE:\n\n### Apollo Client (React)\n\n```ts\nimport { useQuery } from \"@apollo/client\";\nimport { toe } from \"graphql-toe\";\nimport { useMemo } from \"react\";\n\nfunction useQueryTOE(document, options) {\n  const rawResult = useQuery(document, { ...options, errorPolicy: \"all\" });\n  return useMemo(\n    () => toe({ data: rawResult.data, errors: rawResult.error?.graphQLErrors }),\n    [rawResult.data, rawResult.error],\n  );\n}\n```\n\nNow simply replace all usages of `useQuery()` with `useQueryTOE()`.\n\nNote: apply similar changes for mutations and subscriptions.\n\n### URQL\n\nUse\n[@urql/exchange-throw-on-error](https://github.com/urql-graphql/urql/tree/main/exchanges/throw-on-error):\n\n```ts\nimport { Client, fetchExchange } from \"urql\";\nimport { throwOnErrorExchange } from \"@urql/exchange-throw-on-error\";\n\nconst client = new Client({\n  url: \"/graphql\",\n  exchanges: [fetchExchange, throwOnErrorExchange()],\n});\n```\n\n### graffle\n\n```ts\nimport { request } from \"graffle\";\n\nconst result = await request(\"https://api.spacex.land/graphql/\", document);\nconst data = toe(result);\n```\n\n### fetch()\n\n```ts\nimport { toe } from \"graphql-toe\";\n\nconst response = await fetch(\"/graphql\", {\n  headers: {\n    Accept: \"application/graphql-response+json, application/json\",\n    \"Content-Type\": \"application/json\",\n  },\n  body: JSON.stringify({ query: \"{ __schema { queryType { name } } }\" }),\n});\nif (!response.ok) throw new Error(\"Uh-oh!\");\nconst result = await response.json();\nconst data = toe(result);\n```\n\n### Relay\n\nRelay has native support for error handling via the\n[@throwOnFieldError](https://relay.dev/docs/guides/throw-on-field-error-directive/)\nand [@catch](https://relay.dev/docs/guides/catch-directive/) directives - use\nthat instead!\n\n## Semantic nullability\n\nThe\n[@semanticNonNull](https://specs.apollo.dev/nullability/v0.4/#@semanticNonNull)\ndirective lets schema designers mark fields where `null` is **never a valid\nvalue**; a `null` in such a position must mean an error occurred (and thus there\nwill be an entry in the `errors` list matching the path).\n\nWith `toe()` you can treat these `@semanticNonNull` fields as non-nullable since\nwe know an error-null can never be accessed; and thus your JavaScript/TypeScript\nfrontend code will need fewer null checks!\n\nIn TypeScript, use\n[semanticToStrict from graphql-sock](https://github.com/graphile/graphql-sock?tab=readme-ov-file#semantic-to-strict)\nto rewrite semantic-non-null to traditional non-null for type generation.\n\nTogether, this combination gives you:\n\n- More accurate codegen types\n- Improved DX with fewer null checks\n- Safer, cleaner client code\n\n## How does it work?\n\nCreates copies of data impacted by errors, using\n[getters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get)\nto throw when error positions are accessed.\n\nHighly efficient: only response sections impacted by errors are copied; with no\nerrors the underlying data is returned verbatim.\n\n## Motivation\n\nThere's growing consensus amongst the GraphQL Working Group that the future of\nGraphQL has errors handled on the client side, with server-side error\npropagation disabled. This fixes a number of issues, among them the\nproliferation of null types (and the associated nullability checks peppering\nclient code), and inability to safely write data to normalized caches if that\ndata came from a request containing errors.\n\nOver time, we hope all major GraphQL clients will integrate error handling deep\ninto their architecture so that users don't need to think about it. In the mean\ntime, this project can add support for this future behavior to almost any\nGraphQL client by re-introducing thrown errors into your data.\n\n**Handle errors the way your programming language or framework is designed to —\nno need for GraphQL-specific logic.**\n\nRead more on the motivation behind this here:\nhttps://benjie.dev/graphql/nullability/\n\n## Deeper example\n\n```ts\nimport { toe } from \"graphql-toe\";\n\n// Example data from GraphQL\nconst result = {\n  data: {\n    deep: {\n      withList: [\n        { int: 1 },\n        {\n          /* `null` because an error occurred */\n          int: null,\n        },\n        { int: 3 },\n      ],\n    },\n  },\n  errors: [\n    {\n      message: \"Two!\",\n      // When you read from this path, an error will be thrown\n      path: [\"deep\", \"withList\", 1, \"int\"],\n    },\n  ],\n};\n\n// TOE'd data:\nconst data = toe(result);\n\n// Returns `3`:\ndata.deep.withList[2].int;\n\n// Returns an object with the key `int`\ndata.deep.withList[1];\n\n// Throws the error `Two!`\ndata.deep.withList[1].int;\n```\n\n## TODO\n\n- [ ] Add support for incremental delivery\n\n## History\n\nVersion 0.1.0 of this module was released from San Francisco the day after\nGraphQLConf 2024, following many fruitful discussions around nullability.\n\nVersion 1.0.0 of this module was released just before GraphQLConf 2025, as the\nresult of what we call Conference-Driven Development.\n","readmeFilename":"README.md"}