Gathering detailed insights and metrics for @shopify/graphql-client
Gathering detailed insights and metrics for @shopify/graphql-client
Gathering detailed insights and metrics for @shopify/graphql-client
Gathering detailed insights and metrics for @shopify/graphql-client
npm install @shopify/graphql-client
Typescript
Module System
Node Version
NPM Version
99.8
Supply Chain
100
Quality
92
Maintenance
100
Vulnerability
100
License
@shopify/shopify-app-remix@3.8.5
Updated on Jul 21, 2025
@shopify/shopify-app-react-router@0.1.1
Updated on Jul 21, 2025
@shopify/shopify-app-express@5.0.20
Updated on Jul 21, 2025
@shopify/shopify-api@11.14.1
Updated on Jul 21, 2025
@shopify/shopify-app-session-storage-redis@4.2.13
Updated on Jul 21, 2025
@shopify/shopify-app-session-storage-sqlite@4.0.20
Updated on Jul 21, 2025
TypeScript (99.93%)
JavaScript (0.06%)
Shell (0.01%)
Total Downloads
7,087,636
Last Day
7,313
Last Week
177,149
Last Month
698,063
Last Year
5,795,628
MIT License
433 Stars
5,827 Commits
166 Forks
168 Watchers
102 Branches
7,222 Contributors
Updated on Jul 29, 2025
Latest Version
1.4.1
Package Id
@shopify/graphql-client@1.4.1
Unpacked Size
319.99 kB
Size
67.72 kB
File Count
77
NPM Version
10.8.2
Node Version
18.20.8
Published on
Jul 21, 2025
Cumulative downloads
Total Downloads
Last Day
8.7%
7,313
Compared to previous day
Last Week
2%
177,149
Compared to previous week
Last Month
9.5%
698,063
Compared to previous month
Last Year
348.6%
5,795,628
Compared to previous year
The GraphQL Client can be used to interact with any Shopify's GraphQL APIs. Client users are expected to provide the full API URL and necessary headers.
Using your preferred package manager, install this package in a project:
1yarn add @shopify/graphql-client
1npm install @shopify/graphql-client --s
1pnpm add @shopify/graphql-client
The UMD builds of each release version are available via the unpkg
CDN
1// The minified `v0.9.3` version of the GraphQL API Client 2<script src="https://unpkg.com/@shopify/graphql-client@0.9.3/dist/umd/graphql-client.min.js"></script> 3 4<script> 5const client = ShopifyGraphQLClient.createGraphQLClient({...}); 6</script>
1import {createGraphQLClient} from '@shopify/graphql-client'; 2 3const client = createGraphQLClient({ 4 url: 'http://your-shop-name.myshopify.com/api/2023-10/graphql.json', 5 headers: { 6 'Content-Type': 'application/json', 7 'X-Shopify-Storefront-Access-Token': 'public-token', 8 }, 9 retries: 1 10});
In order to use the client within a server, a server enabled JS Fetch API will need to be provided to the client at initialization. By default, the client uses window.fetch
for network requests.
1import {createGraphQLClient} from '@shopify/graphql-client'; 2import {fetch as nodeFetch} from 'node-fetch'; 3 4const client = createGraphQLClient({ 5 url: 'http://your-shop-name.myshopify.com/api/2023-10/graphql.json', 6 headers: { 7 'Content-Type': 'application/json', 8 'X-Shopify-Storefront-Access-Token': 'public-token', 9 }, 10 customFetchApi: nodeFetch 11});
createGraphQLClient()
parametersProperty | Type | Description |
---|---|---|
url | string | The GraphQL API URL |
headers | Record<string, string | string[]> | Headers to be included in requests |
retries? | number | The number of HTTP request retries if the request was abandoned or the server responded with a Too Many Requests (429) or Service Unavailable (503) response. Default value is 0 . Maximum value is 3 . |
customFetchApi? | (url: string, init?: {method?: string, headers?: HeaderInit, body?: string}) => Promise<Response> | A replacement fetch function that will be used in all client network requests. By default, the client uses window.fetch() . |
logger? | (logContent: HTTPResponseLog | HTTPRetryLog | HTTPResponseGraphQLDeprecationNotice ) => void | A logger function that accepts log content objects. This logger will be called in certain conditions with contextual information. |
Property | Type | Description |
---|---|---|
config | {url: string, headers: Record<string, string | string[]>, retries: number} | Configuration for the client |
fetch | (operation: string, options?: RequestOptions ) => Promise<Response> | Fetches data from the GraphQL API using the provided GQL operation string and RequestOptions object and returns the network response |
request | <TData>(operation: string, options?: RequestOptions ) => Promise< ClientResponse<TData> > | Fetches data from the GraphQL API using the provided GQL operation string and RequestOptions object and returns a normalized response object |
requestStream | <TData>(operation: string, options?: RequestOptions ) => Promise <AsyncIterator< ClientStreamResponse<TData> >> | Fetches GQL operations that can result in a streamed response from the API (eg. Storefront API's @defer directive). The function returns an async iterator and the iterator will return normalized stream response objects as data becomes available through the stream. |
RequestOptions
propertiesName | Type | Description |
---|---|---|
variables? | Record<string, any> | Variable values needed in the graphQL operation |
url? | string | Alternative request API URL |
headers? | Record<string, string | string[]> | Additional and/or replacement headers to be used in the request |
retries? | number | Alternative number of retries for the request. Retries only occur for requests that were abandoned or if the server responds with a Too Many Request (429) or Service Unavailable (503) response. Minimum value is 0 and maximum value is 3 . |
keepalive? | boolean | Whether to keep a connection alive when page is unloaded before a request has completed. Default value is false . |
signal? | AbortSignal | If this option is set, the request can be canceled by calling abort() on the corresponding AbortController . |
ClientResponse<TData>
Name | Type | Description |
---|---|---|
data? | TData | any | Data returned from the GraphQL API. If TData was provided to the function, the return type is TData , else it returns type any . |
errors? | ResponseErrors | Errors object that contains any API or network errors that occured while fetching the data from the API. It does not include any UserErrors . |
extensions? | Record<string, any> | Additional information on the GraphQL response data and context. It can include the context object that contains the context settings used to generate the returned API response. |
ClientStreamResponse<TData>
Name | Type | Description |
---|---|---|
data? | TData | any | Currently available data returned from the GraphQL API. If TData was provided to the function, the return type is TData , else it returns type any . |
errors? | ResponseErrors | Errors object that contains any API or network errors that occured while fetching the data from the API. It does not include any UserErrors . |
extensions? | Record<string, any> | Additional information on the GraphQL response data and context. It can include the context object that contains the context settings used to generate the returned API response. |
hasNext | boolean | Flag to indicate whether the response stream has more incoming data |
ResponseErrors
Name | Type | Description |
---|---|---|
networkStatusCode? | number | HTTP response status code |
message? | string | The provided error message |
graphQLErrors? | any[] | The GraphQL API errors returned by the server |
response? | Response | The raw response object from the network fetch call |
1const productQuery = ` 2 query ProductQuery($handle: String) { 3 product(handle: $handle) { 4 id 5 title 6 handle 7 } 8 } 9`; 10 11const {data, errors, extensions} = await client.request(productQuery, { 12 variables: { 13 handle: 'sample-product', 14 }, 15});
@defer
directive1const productQuery = ` 2 query ProductQuery($handle: String) { 3 product(handle: $handle) { 4 id 5 handle 6 ... @defer(label: "deferredFields") { 7 title 8 description 9 } 10 } 11 } 12`; 13 14const responseStream = await client.requestStream(productQuery, { 15 variables: {handle: 'sample-product'}, 16}); 17 18// await available data from the async iterator 19for await (const response of responseStream) { 20 const {data, errors, extensions, hasNext} = response; 21}
1const productQuery = ` 2 query ProductQuery($handle: String) { 3 product(handle: $handle) { 4 id 5 title 6 handle 7 } 8 } 9`; 10 11const {data, errors, extensions} = await client.request(productQuery, { 12 variables: { 13 handle: 'sample-product', 14 }, 15 headers: { 16 'Shopify-Storefront-Id': 'shop-id', 17 }, 18});
1const productQuery = ` 2 query ProductQuery($handle: String) { 3 product(handle: $handle) { 4 id 5 title 6 handle 7 } 8 } 9`; 10 11const {data, errors, extensions} = await client.request(productQuery, { 12 variables: { 13 handle: 'sample-product', 14 }, 15 url: 'http://your-shop-name.myshopify.com/api/unstable/graphql.json', 16});
1const shopQuery = ` 2 query ShopQuery { 3 shop { 4 name 5 id 6 } 7 } 8`; 9 10// Will retry the HTTP request to the server 2 times if the requests were abandoned or the server responded with a 429 or 503 error 11const {data, errors, extensions} = await client.request(shopQuery, { 12 retries: 2, 13});
1const shopQuery = ` 2 query ShopQuery { 3 shop { 4 name 5 id 6 } 7 } 8`; 9 10const {data, errors, extensions} = await client.request(shopQuery, { 11 keepalive: true, 12});
client.request()
and client.requestStream()
1import {print} from 'graphql/language'; 2 3// GQL operation types are usually auto generated during the application build 4import {CollectionQuery, CollectionDeferredQuery} from 'types/appTypes'; 5import collectionQuery from './collectionQuery.graphql'; 6import collectionDeferredQuery from './collectionDeferredQuery.graphql'; 7 8const {data, errors, extensions} = await client.request<CollectionQuery>( 9 print(collectionQuery), 10 { 11 variables: { 12 handle: 'sample-collection', 13 }, 14 } 15); 16 17const responseStream = await client.requestStream<CollectionDeferredQuery>( 18 print(collectionDeferredQuery), 19 { 20 variables: {handle: 'sample-collection'}, 21 } 22);
client.fetch()
to get API data1const shopQuery = ` 2 query shop { 3 shop { 4 name 5 id 6 } 7 } 8`; 9 10const response = await client.fetch(shopQuery); 11 12if (response.ok) { 13 const {errors, data, extensions} = await response.json(); 14}
HTTPResponseLog
This log content is sent to the logger whenever a HTTP response is received by the client.
Property | Type | Description |
---|---|---|
type | LogType['HTTP-Response'] | The type of log content. Is always set to HTTP-Response |
content | { requestParams : [url, init?], response: Response} | Contextual data regarding the request and received response |
HTTPRetryLog
This log content is sent to the logger whenever the client attempts to retry HTTP requests.
Property | Type | Description |
---|---|---|
type | LogType['HTTP-Retry'] | The type of log content. Is always set to HTTP-Retry |
content | { requestParams : [url, init?], lastResponse?: Response, retryAttempt: number, maxRetries: number} | Contextual data regarding the upcoming retry attempt. requestParams : parameters used in the requestlastResponse : previous response retryAttempt : the current retry attempt count maxRetries : the maximum number of retries |
HTTPResponseGraphQLDeprecationNotice
This log content is sent to the logger whenever a HTTP response with a X-Shopify-API-Deprecated-Reason
is received by the client.
Property | Type | Description |
---|---|---|
type | LogType['HTTP-Response-GraphQL-Deprecation-Notice'] | The type of log content. Is always set to HTTP-Response-GraphQL-Deprecation-Notice |
content | { requestParams : [url, init?], deprecationNotice: string} | Contextual data regarding the request and received deprecation information |
RequestParams
Property | Type | Description |
---|---|---|
url | string | Requested URL |
init? | {method?: string, headers?: HeaderInit, body?: string} | The request information |
No vulnerabilities found.
@shopify/storefront-api-client
Shopify Storefront API Client - A lightweight JS client to interact with Shopify's Storefront API
@shopify/admin-api-client
Shopify Admin API Client - A lightweight JS client to interact with Shopify's Admin API
@andvea/shopify-graphql-client
This is a JavaScript module that allows you to invoke Shopify's GraphQL API with Node without having to worry about all the tedious stuff like retries, throttling, backoff time and more. The purpose is to abstract all the [best practices](https://shopi
shopify-graphql-client
> Shopify GraphQL for Node