Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aryanj-nyc/relay-connections-deconstructor
https://github.com/aryanj-nyc/relay-connections-deconstructor
Last synced: about 7 hours ago
JSON representation
- Host: GitHub
- URL: https://github.com/aryanj-nyc/relay-connections-deconstructor
- Owner: AryanJ-NYC
- License: mit
- Created: 2020-07-11T02:16:41.000Z (over 4 years ago)
- Default Branch: development
- Last Pushed: 2023-01-07T19:59:22.000Z (almost 2 years ago)
- Last Synced: 2024-10-10T23:18:20.557Z (28 days ago)
- Language: TypeScript
- Size: 621 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Relay Connections Deconstructor
[![npm](https://img.shields.io/npm/v/relay-connections-deconstructor?style=plastic)](https://www.npmjs.com/package/relay-connections-deconstructor)
## Description
Not all of us love the Relay spec but sometimes we need to wrestle with a third-party service that uses it. We find ourselves wrestling with edges and nodes and edges and nodes and edges and...
Welp, I wrote a quick little function to flatten out said edges and nodes and edges and nodes.
## Installation
```bash
yarn add relay-connections-deconstructor
```or
```bash
npm install relay-connections-deconstructor
```## Usage
```typescript
import { relayDeconstructor } from 'relay-connections-deconstructor';const responseFollowingRelaySpec = {
friends: {
totalCount: 3,
edges: [
{
node: {
name: 'Han Solo',
},
cursor: 'Y3Vyc29yMg==',
},
{
node: {
name: 'Leia Organa',
},
cursor: 'Y3Vyc29yMw==',
},
],
pageInfo: {
endCursor: 'Y3Vyc29yMw==',
hasNextPage: false,
},
},
planets: {
totalCount: 2,
edges: [
{ node: { name: 'Pluto' }, cursor: 'Y3Vyc29yMg==' },
{ node: { name: 'Mars' }, cursor: 'Y3Vyc29yMw==' },
],
},
};const deconstructedObject = relayDeconstructor(responseFollowingRelaySpec);
console.log(deconstructedObject);
// 👇
// {
// friends: [
// {
// name: 'Han Solo',
// cursor: 'Y3Vyc29yMg==',
// },
// {
// name: 'Leia Organa',
// cursor: 'Y3Vyc29yMw==',
// },
// ],
// planets: [
// { cursor: 'Y3Vyc29yMg==', name: 'Pluto' },
// { cursor: 'Y3Vyc29yMw==', name: 'Mars' },
// ],
// };const justTheFriends = relayDeconstructor(responseFollowingRelaySpec.friends);
console.log(justTheFriends);
// 👇
// [
// {
// name: 'Han Solo',
// cursor: 'Y3Vyc29yMg==',
// },
// {
// name: 'Leia Organa',
// cursor: 'Y3Vyc29yMw==',
// },
// ]
```