Relay helpers and utilities for use across our projects
npm install @ferocia-oss/relay``sh`
yarn add @ferocia-oss/relay
This is a factory factory, that creates a makeUseMutation function that can then be used to create useMutation hooks. This allows us to specify project-wide handlers for validation and fatal errors.
`ts
import {makeUseMutationFactory} from '@ferocia-oss/relay';
export const makeUseMutation = makeUseMutationFactory({
onError: (error) => {
BugSnag.error(error);
},
onPayloadErrors: (errors) => {
errors.forEach((error) => BugSnag.error(error));
},
onValidationErrors: (errors) => {
console.warn(errors);
},
});
`
Reported via the onPayloadErrors handler. This is a wrapper around the PayloadError type from Relay, which allows us to add additional metadata to the error to be more useful for sending to BugSnag or another error reporting service.
Error handler class, exposed via onFatalError, onFailure and onError, call handle() to mark the error as handled and prevent it from flowing through to the next handler.
Relay connections often have nullable edges and nodes, this will filter the collection and return only the non-null nodes.
* setFieldsOnRecord - Set multiple fields on a RecordProxygetFieldsOnRecord
* - Get multiple fields on a RecordProxyresolveNestedRecord
* - Safely traverse to a deep linked recordidExistsInEdges
* - Check if a Node ID already exists in a collection of edgeswithRecord` - Perform some actions on a record if it exists
*