A set of utilities to use when consuming Shopify’s admin graphql api.
$ yarn add @shopify/admin-graphql-api-utilities
Given a Gid string, parse out the id.
import {parseGid} from '@shopify/admin-graphql-api-utilities';
parseGid('gid://shopify/Customer/12345');
// → '12345'
Given a key and id, compose a Gid string.
import {composeGid} from '@shopify/admin-graphql-api-utilities';
composeGid('Customer', 12345);
// → 'gid://shopify/Customer/12345'
composeGid('Customer', '67890');
// → 'gid://shopify/Customer/67890'
Given an array of edges, return the nodes.
import {nodesFromEdges} from '@shopify/admin-graphql-api-utilities';
nodesFromEdges([
{node: {id: '1', title: 'title one'}},
{node: {id: '2', title: 'title two'}},
]);
// → [{id: '1', title: 'title one'}, {id: '2', title: 'title two'}]
Given an array of edges, return a new array of only the specific key from those nodes.
import {keyFromEdges} from '@shopify/admin-graphql-api-utilities';
keyFromEdges(
[
{node: {id: '1', title: 'title one'}},
{node: {id: '2', title: 'title two'}},
],
'title',
);
// → ['title one', 'title two']