@ferocia-oss/relay
v1.0.1
Published
Relay helpers and utilities for use across our projects
Downloads
588
Readme
@ferocia-oss/relay
Relay helpers and utilities for use across our projects
Installation
yarn add @ferocia-oss/relay
Documentation
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 aRecordProxy
getFieldsOnRecord
- Get multiple fields on aRecordProxy
resolveNestedRecord
- 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