Registry / devops / graphql-toe

graphql-toe

JSON →
library1.0.0jsnpmunverified

A <512 byte zero-dependency library that transforms GraphQL responses by replacing errored fields with throwing getters. Version 1.0.0 stable. It solves the ambiguous `null` problem in GraphQL by throwing when you access a field that errored, allowing natural error handling with try/catch or React ErrorBoundary. Works with any GraphQL client (Apollo, URQL, fetch) that returns `{ data, errors }` — unlike Relay which has native directives. Ships TypeScript types, supports ESM and CJS.

npm install graphql-toe
INSTALL
IMPORT
SIG · GRAPHQL-TOE
G
graphql-toe
devopsjavascriptv1.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

toe
import { toe } from 'graphql-toe'
const toe = require('graphql-toe')
ESM-only since v1.0.0. CJS require() will fail.
toe
import { toe } from 'graphql-toe'
import toe from 'graphql-toe'
Named export only; there is no default export.
GraphQLError
import { GraphQLError } from 'graphql'
import { GraphQLError } from 'graphql-toe'
GraphQLError is not exported from graphql-toe; use the `graphql` package if needed.

Shows how to use toe() to transform a GraphQL response and handle errors via try/catch.

import { toe } from 'graphql-toe'; async function fetchUsers() { const response = await fetch('/graphql', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ query: '{ users { id name } }' }) }); const result = await response.json(); const data = toe(result); try { console.log(data.users[0].name); console.log(data.users[1].name); // might throw } catch (e) { console.error('GraphQL error:', e.message); } }
Debug
Known issues
breakingtoe() requires result.data and result.errors arrays. If result.data is null, it throws immediately.
fix
Always ensure the GraphQL response has a data field. Use try/catch around toe() to handle missing data.
affects: >=1.0.0
gotchatoe() only replaces null values that are due to errors. If a null exists in the data without an error entry, it will remain null (data-null).
fix
For ambiguous nulls, verify that errors array contains a matching path. Consider preprocessing errors if needed.
affects: >=1.0.0
gotchaThe thrown error is the raw error object from the errors array, not an Error instance. It may lack a stack trace.
fix
Wrap the error object in an Error or GraphQLError before calling toe(), or add your own error handling.
affects: >=1.0.0
deprecatedNo deprecated features in v1.0.0.
fix
N/A
affects: >=1.0.0
breakingtoe() is not a deep clone; it modifies the original data object by replacing errored properties with throwing getters.
fix
If you need to preserve the original response, deep-clone before calling toe().
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'graphql-toe'
Package not installed or import path incorrect.
fix
Run 'npm install graphql-toe' and ensure import is 'graphql-toe' not 'graphql-toe/dist' or similar.
TypeError: (0 , graphql_toe.toe) is not a function
Using default import instead of named import.
fix
Change 'import toe from "graphql-toe"' to 'import { toe } from "graphql-toe"'.
toe is not defined
Using CJS require() incorrectly.
fix
Use ESM import syntax: 'import { toe } from "graphql-toe"'.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
graphql-toe — npm install graphql-toe · libregistry