npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@shopify/admin-graphql-api-utilities

v2.2.0

Published

A set of utilities to use when consuming Shopify’s admin GraphQL API

Downloads

284,440

Readme

@shopify/admin-graphql-api-utilities

Build Status Build Status License: MIT npm version npm bundle size (minified + gzip)

A set of utilities to use when consuming Shopify’s admin GraphQL API.

Installation

yarn add @shopify/admin-graphql-api-utilities

API Reference

parseGidType(gid: string): string

Given a Gid string, parse out the type.

Example Usage

import {parseGidType} from '@shopify/admin-graphql-api-utilities';

parseGidType('gid://shopify/Customer/12345');
// → 'Customer'

function parseGid(gid: string): string

Given a Gid string, parse out the id.

Example Usage

import {parseGid} from '@shopify/admin-graphql-api-utilities';

parseGid('gid://shopify/Customer/12345');
// → '12345'

function parseGidWithParams(gid: string): ParsedGid

Given a Gid string, parse out the id and its params.

Example Usage

import {parseGidWithParams} from '@shopify/admin-graphql-api-utilities';

parseGidWithParams('gid://shopify/Customer/12345?sessionId=123&foo=bar');
// → {
//     id: '12345',
//     params: {sessionId: '123', foo: 'bar'}
//   }

function composeGidFactory<N extends string>(namespace: N): Function

Create a new composeGid with a given namespace instead of the default shopify namespace.

Example Usage

import {composeGidFactory} from '@shopify/admin-graphql-api-utilities';

const composeGid = composeGidFactory('CustomApp');

composeGid('Product', '123');
// → 'gid://CustomApp/Product/123'

function composeGid<T extends string>(key: T, id: number | string, params: Record<string, string> = {}): Gid<'shopify', T>

Given a key and id, compose a Gid string.

Example Usage

import {composeGid} from '@shopify/admin-graphql-api-utilities';

composeGid('Customer', 12345);
// → 'gid://shopify/Customer/12345'

composeGid('Customer', '67890', {foo: 'bar'});
// → 'gid://shopify/Customer/67890?foo=bar'

function isGidFactory<N extends string>(namespace: N): Function

Create a new isGid with a given namespace instead of the default shopify namespace.

Example Usage

import {isGidFactory} from '@shopify/admin-graphql-api-utilities';

const isGid = isGidFactory('CustomApp');

isGid('gid://CustomApp/Product/123');
// → true

isGid('gid://CustomApp/Product/123', 'Customer');
// → false

function isGid<T extends string>(gid: string, key?: T,): boolean

Check if a given string is a valid Gid.

Example Usage

import {isGid} from '@shopify/admin-graphql-api-utilities';

isGid('gid://shopify/Customer/12345');
// → true

isGid('gid://shopify/Customer/12345', 'Customer');
// → false

function nodesFromEdges(edges)

Given an array of edges, return the nodes.

Example Usage

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'}]

function keyFromEdges(edges, key)

Given an array of edges, return a new array of only the specific key from those nodes.

Example Usage

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']