Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/relay-tools/relay-connection-handler-plus
Relay connection handler with additional functionality
https://github.com/relay-tools/relay-connection-handler-plus
Last synced: 3 months ago
JSON representation
Relay connection handler with additional functionality
- Host: GitHub
- URL: https://github.com/relay-tools/relay-connection-handler-plus
- Owner: relay-tools
- License: mit
- Created: 2020-04-22T06:55:12.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-07-31T18:18:12.000Z (3 months ago)
- Last Synced: 2024-07-31T22:30:51.045Z (3 months ago)
- Language: TypeScript
- Size: 535 KB
- Stars: 21
- Watchers: 4
- Forks: 1
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-list - relay-connection-handler-plus - tools | 16 | (TypeScript)
README
# Relay Connection Handler Plus! [![npm][npm-badge]][npm]
[Relay](https://relay.dev/) connection handler with additional functionality.
# Usage
```js
import ConnectionHandler from 'relay-connection-handler-plus';
import { Environment } from 'relay-runtime';
import RelayDefaultHandlerProvider from "relay-runtime/lib/handlers/RelayDefaultHandlerProvider";function handlerProvider(handle) {
switch (handle) {
case 'connection':
return ConnectionHandler;
default:
return RelayDefaultHandlerProvider(handle);
}
}const environment = new Environment({
handlerProvider,
/* ... */
});
```Relay Connection Handler Plus! provides an enhanced connection handler that can be used in place of the default connection handler.
This connection handler exposes an additional `getConnections` method. This method allows getting all connections for a connection key, per [facebook/relay#1861](https://github.com/facebook/relay/issues/1861):
```js
const connections = ConnectionHandler.getConnections(record, connectionKey);
```The `getConnections` method also allows getting a subset of connections for a given connection key that were fetched with args matching a filter function. For example, it can be used to get all connections loaded with `color: "red"`, regardless of the other arguments on the connection:
```js
const connections = ConnectionHandler.getConnections(
record,
connectionKey,
({ color }) => color === 'red',
);
```[npm-badge]: https://img.shields.io/npm/v/relay-connection-handler-plus.svg
[npm]: https://www.npmjs.org/package/relay-connection-handler-plus