Errors and limits

What a call returns when it fails, why a write is refused, and the limits on what a query may cost. Part of the client API.

Errors#

GraphQL errors carry extensions.code:

Code Meaning Retry?
VALIDATION_FAILED Input breaks the schema. extensions.errors maps input field names to messages. after fixing the input
FORBIDDEN The caller may see the entity but the rule for this action denies it. The message says which rule and which of its clauses failed (see Why a write is refused). no
NOT_FOUND The entity, or a ref target (extensions.field), doesn't exist or isn't visible to the caller. no
UNAUTHENTICATED The action needs a signed-in user. With HTTP 401, the bearer token was refused: extensions.reason is token-expired (refresh, then retry) or invalid-token (sign in again); see Use the access token. after a refresh or sign-in
CONFLICT Concurrent writes kept changing what this write depends on. yes
RATE_LIMITED The caller's rate-limit points are used up. extensions.retryAfterMs says when to retry. after the wait
BAD_USER_INPUT A bad argument (first, a cursor, too many ids in a batch) or a query over the cost limits. after changing the query
BATCH_FAILED Some ids of a batch delete failed, so nothing was deleted. extensions.failed lists each one with its own code and message. after removing or fixing those ids
RULE_ERROR A permission rule of the schema failed to run on the data it met (extensions.reason has Datomic's reason). Plan refuses rules Datomic can't run at all, so this is rare; fix the rule and push again. no
INTERNAL An unexpected server error. No details are given. maybe

Examples:

Lang
JSON
{"message": "Validation failed", "path": ["createList"],
 "extensions": {"code": "VALIDATION_FAILED",
                "errors": {"ownerNote": ["should be at most 500 characters"],
                           "title": ["should be at least 1 character"]}}}

{"message": "Not allowed: List's create rule fails at [?e :lists/owner ?user]", "path": ["createList"],
 "extensions": {"code": "FORBIDDEN", "action": "create",
                "rule": "[(authenticated? ?user) [?e :lists/owner ?user]]",
                "clause": "[?e :lists/owner ?user]"}}

{"message": "Authentication required", "path": ["createList"], "extensions": {"code": "UNAUTHENTICATED"}}

{"message": "List not found", "path": ["updateList"], "extensions": {"code": "NOT_FOUND"}}

{"message": "List has 3 Items that require it; delete them first", "path": ["deleteList"],
 "extensions": {"code": "VALIDATION_FAILED",
                "blockedBy": [{"type": "Item", "field": "list", "count": 3, "deletable": true}]}}

extensions.type appears when the failure is on another entity than the one you wrote. Messages like "already taken" (a :unique? value) and "already exists" (a create id) are per-field validation errors.

A failed mutation returns "data": null because its result type is non-null.

Errors without a code. GraphQL's own checks run before october's and have no extensions.code, only a message: an unknown field, a missing required argument, a value that isn't in an enum, a malformed UUID.

Lang
JSON
{"message": "Provided argument value `PURPLE' is not member of enum type.",
 "extensions": {"field-name": "createList", "argument": "createList.input", "value": "PURPLE",
                "allowed-values": ["RED", "BLUE", "GREEN", "GREY"], "enum-type": "ListColor"}}

{"message": "Exception applying arguments to field `items': Not all non-nullable arguments have supplied values.",
 "extensions": {"field-name": "items", "missing-arguments": ["first"]}}

Treat an error with no code as a bug in your query.

Why a write is refused#

A FORBIDDEN from a permission rule says why. october runs the rule's top-level clauses again, the first one, then the first two, and so on, and names the first clause that fails, printed as the schema writes it:

  • extensions.action: create, update, delete, or view for a field's :view rule (a write may only set a field you may see);
  • extensions.rule: the whole rule as written;
  • extensions.clause: the clause that fails;
  • extensions.field: the input field, when the rule is a field's.
Lang
JSON
{"message": "Not allowed: Vote's create rule fails at (book-member? ?b ?user)", "path": ["createVote"],
 "extensions": {"code": "FORBIDDEN", "action": "create",
                "rule": "[[?e :votes/book ?b] (book-member? ?b ?user) [?e :votes/voter ?user]]",
                "clause": "(book-member? ?b ?user)"}}

{"message": "Not allowed: Book's update rule fails at (not [?e :books/locked true]) on the entity as it would be after the write",
 "path": ["updateBook"],
 "extensions": {"code": "FORBIDDEN", "action": "update",
                "rule": "[[?e :books/club ?c] (member? ?c ?user) (not [?e :books/locked true])]",
                "clause": "(not [?e :books/locked true])"}}

{"message": "Not allowed: Book.status's update rule fails at [?c :clubs/host ?user]", "path": ["updateBook"],
 "extensions": {"code": "FORBIDDEN", "action": "update", "field": "status",
                "rule": "[[?e :books/club ?c] [?c :clubs/host ?user]]", "clause": "[?c :clubs/host ?user]"}}

{"message": "Not allowed: Book.status may not go from proposed to finished", "path": ["updateBook"],
 "extensions": {"code": "FORBIDDEN", "action": "update", "field": "status",
                "transitions": "{:proposed #{:reading}, :reading #{:finished}}"}}

{"message": "Not allowed: Cover has no update permission", "path": ["createBook"],
 "extensions": {"code": "FORBIDDEN", "action": "update"}}
  • An :update rule without before must hold before and after the write; the message says which state it fails on ("on the entity as it would be after the write").
  • A :transitions refusal names the move. Without a :create, :update or :delete rule there is no permission at all ("has no update permission"): a write meets that through a component it would own, or delete.
  • When no clause can be named (a prefix can't run on its own), the message names the rule only.
  • A top-level or is one clause: when none of its branches holds, the whole or is named.
  • Signed out, a rule that needs a user is still UNAUTHENTICATED, with no reason.

Query cost and rate limits#

A query's cost is a measure of the work it asks the server to do: the fields it resolves and the entities it reads. It is not a price: nothing is billed. october uses it for two limits that keep any one query, or any one client, from running away with the server: a limit per query (how deep, how big), checked before the query runs, and a rate limit per caller, a bucket of points that refills over time.

Every response, refused or not, carries the cost:

Lang
JSON
"extensions": {"cost": {"requested": 31, "actual": 10, "budget": 20000, "remaining": 19990}}
  • requested: this request's estimated cost, computed before it runs.
  • actual: what it cost when it ran, with the real list sizes, plus 1 for every entity a list checked and skipped (see below); 0 when nothing ran (a refusal). It can be more than requested.
  • budget: the size of your rate-limit bucket, in points.
  • remaining: what is left after this request, refund included.

How cost is counted. Each field counts 1 for every time it can be resolved: a field inside a connection with first: 10 counts 10 times, and nested connections multiply. { lists(first: 10) { items { title ownerNote } } } is estimated at 1 + 10 × 3 = 31. Each mutation adds 10 for the write: createItem(input: ...) { id text } counts 1 + 10 + 2 = 13. A batch delete adds 10 per distinct id. __typename counts nothing; each __schema or __type counts 10.

The actual work is what counts. The estimate is taken from your bucket before the query runs (so the bucket must hold it), and after it runs the difference goes back: the same count with each connection's real number of items in place of its first, and nothing for a field under a null or skipped with @skip/@include. If the list above has 3 items, the query counts 1 + 3 × 3 = 10, and 21 points go back. A mutation counts its selection's actual work plus 10 per write, even when the write fails. So ask for the page size you need, but don't shrink first below it to keep points: an empty or short page counts little.

Entities a list checks and skips count too. A list reads entities in its order and checks each against its filters and the rules (see Pagination); every one it skips adds 1 to actual. The estimate assumes nothing is skipped, so a list where you may see 3 of the first 1,000 entities counts about 1,000 more than its estimate. The excess is taken from your bucket after the query ran, and can leave it below zero (down to minus its size): your next request then waits until the bucket has refilled. To keep lists light, filter on what narrows them (a <ref>Id or an indexed field) rather than relying on a rule to drop most entities.

A connection's count counts once per parent, however large first is, plus 20 in the estimate (its most checks) and 1 per 50 entities it checked in actual: see Counts per item.

History counts like a list: history(first: 10) multiplies what is nested in it by 10, and each revision's changes by the number of fields the type has (the most one revision can change). The actual work is the revisions and changes returned, plus 1 for each revision checked against a rule and skipped; revisionCount counts 1 plus 1 for each revision it checks against a rule (none when the type's :view is true and no field has a :view rule).

Limits per query (refused before anything runs, with BAD_USER_INPUT):

Limit Default extensions.limit
nesting depth 10 maxDepth
cost 10000 maxCost
Lang
JSON
{"errors": [{"message": "Query too large: estimated at more than the maximum of 10000 fields (each list's first multiplies what is nested in it)",
             "extensions": {"code": "BAD_USER_INPUT", "limit": "maxCost", "max": 10000}}],
 "extensions": {"cost": {"requested": 10301, "budget": 20000, "remaining": 20000,
                         "limit": "maxCost", "max": 10000}}}

To fit, use smaller first values and fewer nested connections, and paginate.

Rate limit. Each caller has a bucket of points that refills over time; budget in every response says its size. Every query, mutation and live re-run takes its estimated cost from the bucket first, and gives back what it didn't use. When the bucket can't cover the estimate, nothing runs:

Lang
JSON
{"errors": [{"message": "Rate limited: too many queries for now (the caller's rate-limit points are used up); retry in 4681 ms",
             "extensions": {"code": "RATE_LIMITED", "retryAfterMs": 4681}}]}

Wait retryAfterMs, then retry. Use remaining to slow down before you hit the limit.