@ferocia-oss/relay
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

@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 a RecordProxy
  • getFieldsOnRecord - Get multiple fields on a RecordProxy
  • resolveNestedRecord - Safely traverse to a deep linked record
  • idExistsInEdges - Check if a Node ID already exists in a collection of edges
  • withRecord - Perform some actions on a record if it exists

Readme

Keywords

none

Package Sidebar

Install

npm i @ferocia-oss/relay

Weekly Downloads

233

Version

1.0.1

License

MIT

Unpacked Size

33 kB

Total Files

24

Last publish

Collaborators

  • levibuzolic
  • azz