# @shopify/admin-graphql-api-utilities

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

Latest version **2.2.0** (published 2024-06-10) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @shopify/admin-graphql-api-utilities
pnpm add @shopify/admin-graphql-api-utilities
yarn add @shopify/admin-graphql-api-utilities
bun add @shopify/admin-graphql-api-utilities
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 2.2.0 |
| Published | 2024-06-10 |
| First published | 2018-09-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=18.12.0 |
| Dependencies | 0 |
| Unpacked size | 15 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1681 |
| Author | Shopify Inc. |
| Maintainers | jaimie.rockburn, blittle, shopify-admin, maryharte, crisfmb, pmoloney89, netlohan, st999999, justin-irl, megswim, wcandillon, nathanpjf, shopify-dep, goodforonefare, lemonmade, vsumner, wizardlyhel, antoine.grant, tsov, andyw8-shopify, henrytao, hannachen, vividviolet, bpscott |

## Links

- npm: https://www.npmjs.com/package/@shopify/admin-graphql-api-utilities
- Repository: https://github.com/Shopify/quilt
- Homepage: https://github.com/Shopify/quilt/blob/main/packages/admin-graphql-api-utilities/README.md
- Issues: https://github.com/Shopify/quilt/issues
- npm.io page: https://npm.io/package/@shopify/admin-graphql-api-utilities

## Recent versions

- 2.2.0 (latest) — 2024-06-10
- 0.0.0-snapshot-20230518135133 (snapshot) — 2023-05-18
- 1.0.7-export-beta.0 (next) — 2022-02-22
- 1.0.1-address-mocks-minified-beta.0 (beta) — 2021-06-02
- 2.1.0 — 2023-06-01
- 2.0.1 — 2022-08-24
- 2.0.0 — 2022-05-19
- 1.0.9 — 2022-03-09
- 1.0.8 — 2022-02-25
- 1.0.7 — 2022-02-01
- 1.0.6 — 2022-02-01
- 1.0.5 — 2021-09-24
- 1.0.4 — 2021-08-24
- 1.0.3 — 2021-08-04
- 1.0.2 — 2021-08-04
- … 35 more at https://npm.io/package/@shopify/admin-graphql-api-utilities/versions

## README

# `@shopify/admin-graphql-api-utilities`

[![Build Status](https://github.com/Shopify/quilt/workflows/Node-CI/badge.svg?branch=main)](https://github.com/Shopify/quilt/actions?query=workflow%3ANode-CI)
[![Build Status](https://github.com/Shopify/quilt/workflows/Ruby-CI/badge.svg?branch=main)](https://github.com/Shopify/quilt/actions?query=workflow%3ARuby-CI)
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE.md) [![npm version](https://badge.fury.io/js/%40shopify%2Fadmin-graphql-api-utilities.svg)](https://badge.fury.io/js/%40shopify%2Fadmin-graphql-api-utilities.svg) [![npm bundle size (minified + gzip)](https://img.shields.io/bundlephobia/minzip/@shopify/admin-graphql-api-utilities.svg)](https://img.shields.io/bundlephobia/minzip/@shopify/admin-graphql-api-utilities.svg)

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

## Installation

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

## API Reference

### `parseGidType(gid: string): string`

Given a Gid string, parse out the type.

#### Example Usage

```typescript
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

```typescript
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

```typescript
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

```typescript
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

```typescript
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

```typescript
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

```typescript
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

```typescript
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

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

---
_Source: https://npm.io/package/@shopify/admin-graphql-api-utilities · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
