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.
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.