@ferocia-oss/relay v1.0.1
@ferocia-oss/relay
Relay helpers and utilities for use across our projects
Installation
yarn add @ferocia-oss/relayDocumentation
makeUseMutationFactory
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.
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);
},
});RelayPayloadError
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.
ErrorHandler
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.
getCollectionNodes
Relay connections often have nullable edges and nodes, this will filter the collection and return only the non-null nodes.
Store helpers
setFieldsOnRecord- Set multiple fields on aRecordProxygetFieldsOnRecord- Get multiple fields on aRecordProxyresolveNestedRecord- 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