Conventions
Learn these once and they hold across every surface. Each is a decision with a rejected alternative, because a decision without one is just an assertion.
Money is carried in rial, presented in toman
Section titled “Money is carried in rial, presented in toman”Money.amount is a decimal string in rial — "1250000", never 1250000 and
never a float. Shop.moneyPresentation carries the display unit and a divisor
to divide by.
Rejected: carrying toman, which is what every merchant and every buyer speaks.
Why not: the rial is what the law, the banks, Shaparak and every gateway settle in. If the wire carried toman, every integration would convert at its own boundary and one of them would eventually convert twice. A tenfold error in a total is not a rounding bug you notice in testing.
The divisor is a number rather than implied by the unit, so clients divide instead of branching, and a future unit costs no client change.
Dates are RFC 3339, UTC, always
Section titled “Dates are RFC 3339, UTC, always”Never Jalali. The shop’s calendar is a presentation instruction
(Shop.calendar), and converting to it is your job at the moment of render.
Why: a Jalali string on the wire cannot be compared, sorted or subtracted without parsing it back, and two clients would disagree about which day a timestamp near midnight falls on.
Province and city are references, not strings
Section titled “Province and city are references, not strings”AddressInput takes provinceCode and cityCode from a platform-maintained
dataset, read through Query.provinces and Query.cities.
Rejected: free text, which is what most Iranian checkouts do.
Why not: «تهران», «طهران» and “Tehran” become three cities. That breaks shipping zones, breaks carrier hand-off, and breaks every report a merchant will ever run — and it is unfixable after the fact, because there is no way to know which «شهرری» meant which.
IDs are opaque
Section titled “IDs are opaque”An ID is a string to store and send back, never to take apart. Today it is a
base64url encoding of the object’s type and key; tomorrow it may not be, and an
ID is only accepted in the exact form it was issued in.
Store it as text, compare it whole, and never build one yourself.
An error that ran and one that did not are different
Section titled “An error that ran and one that did not are different”A request error means the operation never ran: a non-2xx status, or a
errors array with no data. Retry it, or fix the query.
A user error means it ran, decided and declined. It arrives on a 200, inside
userErrors on the payload, with a code from one closed catalogue. Show it to
somebody.
mutation { cartLinesAdd(cartId: "...", lines: [...]) { cart { totalQuantity } userErrors { code field message } # ← it ran and said no warnings { code target } # ← it ran, said yes, and changed something }}Warnings ride on success, and ignoring them shows a cart nobody agreed to
Section titled “Warnings ride on success, and ignoring them shows a cart nobody agreed to”A quantity trimmed to stock, a line dropped because its variant was unpublished,
a discount that stopped applying. Every cart mutation can return warnings
even when it succeeded.
Null is not zero
Section titled “Null is not zero”quantityAvailable: nullmeans the merchant does not publish stock counts. Rendering0tells a buyer the product is gone.totalShippingAmount: nullmeans no destination is known yet. Rendering it as «رایگان» promises free delivery.averageRating: nullmeans nothing has been rated. Rendering0tells every buyer the shop is terrible.
AUTHORIZED and UNRESOLVED are not failures
Section titled “AUTHORIZED and UNRESOLVED are not failures”They are where an order sits when a payment gateway’s callback was lost and reconciliation has not caught up yet — which on Iranian gateways is routine, not exceptional.
Render «در حال بررسی پرداخت». Never «پرداخت ناموفق» — that makes a buyer who already paid pay again.
Pagination is cursor-based, with one exception
Section titled “Pagination is cursor-based, with one exception”first/after forward, last/before backward, never both. The maximum page
is 250; asking for more is OUT_OF_RANGE rather than a silent truncation.
The exception is a fixed reference dataset: the thirty-one provinces and one province’s cities come back whole, because they change about once a decade and paging a constant is ceremony.
Sorting is a key plus a direction
Section titled “Sorting is a key plus a direction”Every paginated list takes sortKey and reverse, and each list has its own
key enum — ProductSortKeys, ArticleSortKeys — because what you can sort
products by is not what you can sort articles by, and one shared enum would
offer PRICE on a blog.
reverse: true inverts whatever the key means, so CREATED_AT with
reverse: true is newest first. Read each field’s default: it is the sensible
one for that list, and it is not the same everywhere. Product.reviews defaults
to CREATED_AT reversed — newest review first — while Product.variants
defaults to POSITION unreversed, the merchant’s own order.
A cursor addresses a position in a specific ordering, which is what makes it
safe where an offset is not. It follows that changing sortKey or reverse
retires the cursor you are holding: re-sorting is a new list, and it starts at
the first page.
Cost, not requests
Section titled “Cost, not requests”Every response carries what it spent:
{ "extensions": { "cost": { "requestedQueryCost": 152, "actualQueryCost": 46, "throttleStatus": { "maximumAvailable": 2000, "currentlyAvailable": 1954, "restoreRate": 100 }}}}Cost is computed from the document, not from the result: each object field
costs 1, each connection costs its first/last, and nesting multiplies. Asking
for first: 250 and using ten of them is charged for 250 — because capacity was
reserved for 250.
Persian normalization is entirely server-side
Section titled “Persian normalization is entirely server-side”Send what the buyer typed. ZWNJ folding, ي→ی, ك→ک, digit normalization and Finglish matching all happen on the server.
Why: a client that normalizes first is a second implementation, and it will disagree with ours. The disagreement is silent — it reads as bad search rather than as a bug.