API conventions
Audience Developer
Overview
Section titled “Overview”This page collects the rules that hold across the Pyck GraphQL API: how lists are paged, where to find the error format, and the limits on a request. For the first request, see Getting started.
Pagination
Section titled “Pagination”Lists such as inventoryItems are Relay-style connections, and you page them with a cursor. A connection field takes these arguments:
first: return the first n elements from the list.after: return the elements that come after the given cursor.last: return the last n elements from the list.before: return the elements that come before the given cursor.
Pass first with after to page forwards, or last with before to page backwards. Do not pass first and last together, the API does not support that. A negative first or last is an error, see Error codes.
A connection returns these fields:
edges: the list of edges. Each edge has anode, which is the item, and acursorfor that item.pageInfo:hasNextPage,hasPreviousPage,startCursorandendCursor. When paginating forwards,endCursoris the cursor to continue with. When paginating backwards,startCursoris.totalCount: how many items the connection holds.
This query reads one page of inventory items:
query GetInventoryItems($first: Int, $after: Cursor) { inventoryItems(first: $first, after: $after) { totalCount pageInfo { hasNextPage endCursor } edges { cursor node { id sku } } }}For the first page, send these variables:
{ "first": 10 }While pageInfo.hasNextPage is true, send the same query again with after set to the endCursor of the previous response:
{ "first": 10, "after": "<endCursor of the previous response>" }Always pass first or last, also on connections nested inside a node, to limit the results.
Page size limit
Section titled “Page size limit”A connection over stored records, such as inventoryItems, never returns more than 200 items at once, and the API does not tell you when it cuts the list:
- Without
firstorlast, the connection returns at most 200 items, andpageInfo.hasNextPagedoes not tell you that more items exist.totalCountis not reliable here: it counts all matching items when the query sendsafterorbeforeor does not selectedges, and only the returned items otherwise. A list of 500 items can look like a complete list of 200. - With
firstorlast,totalCountcounts all matching items andhasNextPagetells whether more follow. - A
firstorlastabove 200 fails with an error whose message containslimit exceeded: the maximum accepted limit is 200. The error has noextensions.code. Use 200 or less. - When a query without
firstorlastreturns exactly 200 items, the server logs a warning. The client gets no sign of it.
The rule: always page with first and after (or last and before), and keep going while pageInfo.hasNextPage is true. Never read a list without first or last as the full result.
For a loop that collects every page, filtering and ordering on a connection, and the Relay specification, see Migration guide: Relay-style connections. The API reference lists the arguments of each connection.
Errors
Section titled “Errors”A response carries errors in an errors array next to data. The structure of an error, the codes Pyck sets and how to handle each kind of failure are in Error handling.
Request limits
Section titled “Request limits”The endpoint limits how many requests a client may send and how large each request may be. The values and what a client gets back over a limit are in Request limits, which is generated from the deployment configuration.