With the new onError: "NULL" GraphQL request property, there is no error
propagation (null bubbling) on the server side. This is great for our client's
normalized stores since it's now save to store results even if errors occurred,
however existing applications may be expecting the traditional error propagation
behavior.
This library has errors elevate locally, i.e. it implements the error
propagation (null bubbling) behavior on the client side - thus a client using
onError: "NULL" with the server can expose { data, errors } to the consuming
application as if error propagation was enabled:
import { heel } from "graphql-heel";
const res = await fetch("/graphql", {
method: "POST",
headers: {
"content-type": "application/json",
accept: "application/graphql-response+json",
},
body: JSON.stringify({
query: `{ __typename }`,
}),
});
const graphqlResponse = await res.json();
const { data, errors } = heel(graphqlResponse);GraphQL HEEL helps clients adopt onError: "NULL" whilst supporting legacy
applications - it's a rearward-facing approach (hence it's the heel). For a more
forward-looking approach,
see GraphQL TOE, where the
application needs only deal with data (no errors list); errors are thrown
when the failed field is read,
and conventional error handling (try/catch and <ErrorBoundary />)
is used to implement error boundaries