Transport for the Shopify GraphQL Admin API: shop and URL building,
the graphql escape hatch, error unwrapping (GraphQL errors,
throttling, mutation userErrors) and cursor pagination helpers
shared by the curated namespaces.
Per-call credentials. Every API-calling function in this package
takes an optional trailing opts Map, resolved by resolve: opts
first, then the shopify.* context variables, then the defaults. A
per-call token is masked in call records and never written to ctx, so
one run can act for many shops.
access-token: the Admin API access token for this callshop: the shop for this call. It needs anaccess-tokenin the sameopts:shopify.access.tokenis never sent to a per-call shop.api-version: the Admin API version for this call
An access-token or shop that is present but blank or null is an
Err naming the key, never a fallback to context.
Context Vars
shopify.shopshopify.access.tokenshopify.api.version
Functions
api-version
fn (): Str
The Admin API version in use: the shopify.api.version context variable when set, otherwise ::shopify/API_VERSION.
blank-option
fn (opts: Map, names: Vec): Str?
The first of names that opts has with a blank or null value, else null.
build-request
fn (query: Str, variables: Map, resolved: Map): ::hot::http/HttpRequest
The outgoing HttpRequest from resolved settings (see resolve). Pure; exposed for testing.
collect
fn (page-fn: Fn, options: Map, max-items: Int): Vec
Follow a connection's cursors and gather up to max-items nodes.
page-fn takes list options (with first and after filled in) and
returns a connection {nodes, pageInfo: {hasNextPage, endCursor}},
which is what every list-* function here returns. An Err on any
page comes back as that Err.
Example
paid ::shopify::api/collect(::shopify::orders/list-orders, {query: "financial_status:paid"}, 1000)
collect-pages
fn (page-fn: Fn, options: Map, max-items: Int, acc: Vec): Vec
connection-variables
fn (options: Map): Map
Build connection variables from list options: first (default 50,
capped at 250), after, query, sortKey, reverse. Unset options
are omitted. Exposed for testing.
graphql
fn (query: Str): Any
fn (query: Str, variables: Map): Any
fn (query: Str, variables: Map, opts: Map): Any
fn (query: Str, variables: Map, shop: Str, access-token: Str): Any
Execute a GraphQL query or mutation against the Admin API. Returns
data, or an Err carrying GraphQLError (GraphQL errors, including
throttling) or HttpError (non-2xx).
Throttled requests are not retried in-process (Hot has no sleep);
read retry-after-ms from the Err, or let a handler's retry
metadata back off.
Example
out ::shopify::api/graphql("query { shop { name currencyCode } }")
out.shop.name
// For another shop
tenant {shop: "acme", access-token: "shpat_tenant"}
out ::shopify::api/graphql("query { shop { name } }", {}, tenant)
graphql-url
fn (shop: Str): Str
fn (shop: Str, version: Str): Str
The GraphQL Admin endpoint for a shop (handle or myshopify domain) and API version (YYYY-MM or unstable). Exposed for testing.
is-throttled-error
fn (error: Map): Bool
mutate
fn (query: Str, variables: Map, field: Str): Any
fn (query: Str, variables: Map, field: Str, errors-key: Str): Any
fn (query: Str, variables: Map, field: Str, opts: Map): Any
fn (query: Str, variables: Map, field: Str, errors-key: Str, opts: Map): Any
Run a mutation and return its payload (data[field]), with userErrors (or errors-key) turned into an Err carrying UserErrors. An Err from the request comes back as is.
mutation-payload
fn (data: Any, field: Str): Any
fn (data: Any, field: Str, errors-key: Str): Any
Pull one mutation's payload out of data and turn a non-empty
userErrors list into an Err carrying UserErrors. Pass
errors-key for mutations that report errors under another name
(e.g. orderCancelUserErrors). Exposed for testing.
non-blank
fn (value: Any): Str?
normalize-shop
fn (shop: Str): Str
Reduce a shop reference to its bare handle: acme,
acme.myshopify.com, https://acme.myshopify.com/admin all give
acme. Errs on anything else (custom storefront domains don't serve
the Admin API).
page-size
fn (requested: Any): Int
parse-graphql-response
fn (body: Any): Any
Unwrap a GraphQL response body: data when there are no errors, otherwise an Err carrying GraphQLError. Exposed for testing; graphql applies it.
quote-search-term
fn (value: Str): Str
Quote a value as an exact term for Shopify's search syntax (backslashes and quotes escaped, wrapped in double quotes) so operators or spaces in the value can't broaden the search. Exposed for testing.
resolve
fn (opts: Map): Map
Credentials and settings for one call (see resolve-from). The token
is masked in this run's call records, and nothing from opts is
written to ctx.
Example
::shopify::api/resolve({shop: "acme", access-token: "shpat_tenant"}).url
// "https://acme.myshopify.com/admin/api/2026-10/graphql.json"
shopify.shop, shopify.access.token, shopify.api.version
resolve-from
fn (opts: Map, ctx-values: Map): Map
The one resolver, pure: {access-token, url, api-version} for a call
from opts first, then ctx-values (a Map of context variables), then
defaults. An Err when the shop or token is not set, when access-token
or shop is in opts but blank or null, when opts has shop without
access-token, or when the shop or version is malformed. Exposed for
testing; resolve feeds it the context.
throttle-wait-ms
fn (cost: Map?): Int
Estimate milliseconds until the cost bucket can afford the request,
from an extensions.cost block: (requestedQueryCost - currentlyAvailable) / restoreRate, at least Shopify's recommended
one second. Exposed for testing.
Types
GraphQLError
GraphQLError type {
errors: Vec,
data: Any,
cost: Map?,
throttled: Bool,
retry-after-ms: Int?
}
A 200 response whose body carries top-level GraphQL errors. data
holds any partial data, cost the extensions.cost block. When
Shopify throttled the request (extensions.code THROTTLED),
throttled is true and retry-after-ms estimates how long the
bucket needs to refill enough for the requested cost.
HttpError
HttpError type {
status: Int,
headers: Map,
body: Any
}
A non-2xx HTTP response from the Admin API (401 bad token, 402 frozen shop, 404 unknown shop or version, 429, 5xx).
UserErrors
UserErrors type {
mutation: Str,
user-errors: Vec,
payload: Any
}
A mutation that ran but was rejected: user-errors is the payload's userErrors list (each {field, message, code?}), payload the full mutation payload.