Writing data
Writing a tenant's data over GraphQL: the generated mutations, retrying safely, what the caller may do, roles, and erasing a user. Part of the client API.
Mutations#
Each entity gets a mutation per action that its permissions declare. An action without a rule has no mutation.
- Lang
- GraphQL
createList(input: ListCreateInput!): List updateList(id: UUID!, input: ListUpdateInput!): List deleteList(id: UUID!): DeletePayload # { id } deleteLists(ids: [UUID!]!): DeleteBatchPayload # { ids }, all or nothing addListMembers(id: UUID!, memberIds: [UUID!]!): List # one pair per many-ref removeListMembers(id: UUID!, memberIds: [UUID!]!): List
add/remove check the :update rule. updateUser exists only when the
schema adds attributes to $users, and a user may update only themself.
A request that committed a write answers extensions.basisT: the
database version (Datomic t) of its newest commit. A live query whose
basisT is at or past it shows the write (see Live
queries).
Several mutations in one request#
Each mutation field is its own transaction. The fields of a
mutation { ... } run one after another, in order, and each commits on
its own. When a later field fails, the earlier ones stay committed:
nothing is rolled back. october doesn't offer one transaction for a
whole request; to change several entities of one type all or nothing,
use a batch (delete<Plural>).
That is why every mutation field's result is nullable (List, not
List!): a failing field is null with its error in errors (its
path names the field), and the other fields keep their data.
- Lang
- GraphQL
mutation { a: createList(input: {title: "Groceries"}) { id title } b: createList(input: {title: ""}) { id title } }
- Lang
- JSON
{"data": {"a": {"id": "0b6d1c1e-8a9f-4a51-9d55-6a3f4f0f0003", "title": "Groceries"}, "b": null}, "errors": [{"message": "Validation failed", "path": ["b"], "extensions": {"code": "VALIDATION_FAILED", "errors": {"title": ["should be at least 1 character"]}}}]}
Groceries is created. Check each field you sent, not just whether
errors is empty: a field is either its result or null with an
error. A field that succeeds is never null.
Retrying safely (Idempotency-Key)#
The JS client does this for you. This section is the HTTP underneath.
A request that times out may still have committed: you can't tell from
the client. Send an Idempotency-Key header with every request that
writes, and send the same key again when you retry it:
- Lang
- Text
POST /t/<slug>/graphql Authorization: Bearer <token> Content-Type: application/json Idempotency-Key: 6f1c9a52-3d2e-4b8e-9a0f-1c2d3e4f5a6b
Each mutation field the first request committed answers the retry with
what it committed (the same id for a create), and isn't made again; a
field that didn't commit runs now. Two requests with one key at the same
time make one write.
- A key is 1 to 255 printable ASCII characters (no spaces); use a fresh
random one (a UUID) for each write you mean, and the same one only for
a retry of it. Anything else is
400. - A key is yours: it names your writes (signed in), or your address's (anonymous), never another caller's, so reusing someone's key can't return their write.
- It names each mutation field of the request by its name, alias, place and arguments: retry the request as it was. The same key sent with other arguments names other writes, and makes them.
- Keys don't expire. Without one, every request is a new write.
Inputs#
| Schema attribute | Input field |
|---|---|
data or enum :owner-note |
ownerNote |
one-target ref :list |
listId: UUID |
many-ref :members |
memberIds: [UUID!] (create only; then use add/remove) |
| reverse fields | not writable |
Required attributes without a default are non-null in the create input.
The update input has the same fields minus the many-refs and minus every
immutable attribute (@immutable in the SDL): a required one-target ref,
such as ownerId here, unless the schema says :immutable? false (see
schema-attributes.md). Those are set on create
only. ListUpdateInput is {color, ownerNote, title}.
- Lang
- GraphQL
input ListCreateInput { id: UUID color: ListColor memberIds: [UUID!] ownerId: UUID ownerNote: String title: String! }
GET /schema.json gives the same input as JSON Schema, for client-side
validation:
- Lang
- JSON
"lists": { "type": "object", "properties": { "color": {"type": "string", "enum": ["GREY", "RED", "GREEN", "BLUE"]}, "id": {"type": "string", "format": "uuid"}, "memberIds": {"type": "array", "items": {"type": "string", "format": "uuid"}, "uniqueItems": true}, "ownerId": {"type": "string", "format": "uuid"}, "ownerNote": {"type": "string", "maxLength": 500}, "title": {"type": "string", "minLength": 1, "maxLength": 100} }, "required": ["title"], "additionalProperties": false }
Create#
id is optional. Send your own UUID (crypto.randomUUID()) to show the
new entity in your UI before the server answers.
- Lang
- GraphQL
mutation ($input: ListCreateInput!) { createList(input: $input) { id title color owner { id displayName } createdAt } }
- Lang
- JSON
{"input": {"id": "0b6d1c1e-8a9f-4a51-9d55-6a3f4f0f0001", "title": " Groceries ", "color": "GREEN"}}- Lang
- JSON
{"data": {"createList": {"id": "0b6d1c1e-8a9f-4a51-9d55-6a3f4f0f0001", "title": "Groceries", "color": "GREEN", "owner": {"id": "67c7970d-...", "displayName": "Ada Lovelace"}, "createdAt": "2026-10-18T10:50:44.058Z"}}, "extensions": {"cost": {"requested": 18, "actual": 18, "budget": 20000, "remaining": 19982}}}
ownerId was left out, so the owner is the caller (:default :auth/user).
It is pinned too: an ownerId naming anyone but the caller is
VALIDATION_FAILED {"ownerId": ["can only be the signed-in user"]}
(see schema-attributes.md). The title was trimmed. An id that already exists gives
VALIDATION_FAILED {"id": ["already exists"]}.
A write you can't read back answers null. A mutation's result is
held to the entity's :view rule like any read. When a create, update,
add or remove commits but you can't view the result (the entity has no
:view rule, or its rule doesn't let you), the field is null, and
extensions.warnings says why, with code NOT_VIEWABLE:
- Lang
- JSON
{"data": {"createFeedback": null}, "extensions": {"warnings": [{"message": "The write succeeded, but you can't view this Feedback, so the result is null: Feedback has no :view rule, and a missing rule means no access", "path": ["createFeedback"], "extensions": {"code": "NOT_VIEWABLE", "type": "Feedback"}}], "cost": {...}}}
Refs take ids. Every target must exist and be visible to the caller,
otherwise the result is NOT_FOUND with the input field:
- Lang
- JSON
{"message": "List not found", "extensions": {"code": "NOT_FOUND", "field": "listId"}}A JSON field takes any JSON value as is:
- Lang
- GraphQL
mutation ($input: ItemCreateInput!) { createItem(input: $input) { id text rank due meta } }- Lang
- JSON
{"input": {"listId": "0b6d1c1e-...-0001", "text": "Milk", "rank": 1, "due": "2026-10-20T09:00:00Z", "meta": {"qty": 2, "tags": ["dairy"]}}}
- Lang
- JSON
{"data": {"createItem": {"id": "91503d63-...", "text": "Milk", "rank": 1, "due": "2026-10-20T09:00:00.000Z", "meta": {"qty": 2, "tags": ["dairy"]}}}}
Update#
The input is partial: only the fields you send change. null clears an
optional field.
- Lang
- GraphQL
mutation ($id: UUID!) { updateItem(id: $id, input: {done: true, due: null}) { text done due rank } }- Lang
- JSON
{"data": {"updateItem": {"text": "Milk", "done": true, "due": null, "rank": 1}}}Changing an immutable field is ruled out by the types: the field isn't in
the update input, so a request that sends it fails GraphQL validation
("Field not defined for input object.", with extensions.field-name
listId) and nothing is written.
Clearing a required field fails:
- Lang
- JSON
{"code": "VALIDATION_FAILED", "errors": {"text": ["is required and can't be cleared"]}}Add and remove (many-refs)#
- Lang
- GraphQL
mutation ($id: UUID!, $ids: [UUID!]!) { addListMembers(id: $id, memberIds: $ids) { id members(first: 10) { items { displayName } } } }
- Lang
- JSON
{"data": {"addListMembers": {"id": "0b6d1c1e-...-0002", "members": {"items": [{"displayName": "Ada Lovelace"}, {"displayName": null}]}}}}
Delete#
- Lang
- GraphQL
mutation ($id: UUID!) { deleteItem(id: $id) { id } }- Lang
- JSON
{"data": {"deleteItem": {"id": "91503d63-6dd4-4aef-a9f2-6f26253ac4ee"}}}Deleting it again gives NOT_FOUND "Item not found". Components are
deleted with their owner, and refs to the deleted entity are removed.
Entities whose ref to it is :on-delete :cascade are deleted with it
(votes with their book; see
schema-attributes.md), on the deleted entity's own
:delete rule alone, including ones you can't see. The answer is the
same {id}, and says nothing about them. More than 1000 of them gives
BAD_USER_INPUT with extensions.limit "maxCascade" and max, and
nothing is deleted.
An entity that something still requires can't be deleted. If the delete would leave another entity without a required ref (an item without its list), it fails and says what blocks it:
- Lang
- JSON
{"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}]}}
blockedBy has one entry per required ref, with the referring type, its
field and how many of them you can see. Entities you can't see are
never counted or named: when some exist, the message says so ("..., and
entities you can't see require it too; delete them first") and
hiddenBlockers is true. When a component the delete would remove is
the one still required, the entry has target (the component's type) and
the message says "its Image has ...". Delete the blockers first (a batch
delete takes them in one call), or let them go with it: :on-delete :cascade on their ref (see schema-attributes.md).
deletable says whether you may delete every one of the counted
blockers. When some of them have no :delete rule, or their rule
refuses you, "delete them first" would be no help, so the message says
so instead:
- Lang
- JSON
{"message": "Deal has 3 StageChanges that require it, and they can't be deleted, so neither can this Deal", "extensions": {"code": "VALIDATION_FAILED", "blockedBy": [{"type": "StageChange", "field": "deal", "count": 3, "deletable": false}]}}
("..., and 1 of them can't be deleted, ..." when only some can't). Only
blockers you can see are judged: a hidden one never changes deletable
or the wording.
Batch delete#
Every entity with delete<T> also gets a batch delete, named after the
plural (deleteItems; delete<T>Batch when the plural and the type name
are the same):
- Lang
- GraphQL
mutation ($ids: [UUID!]!) { deleteItems(ids: $ids) { ids } }- Lang
- JSON
{"data": {"deleteItems": {"ids": ["91503d63-...", "5c0e2a7d-..."]}}}-
All or nothing. The batch runs in one transaction. Each id goes through the same checks as
delete<T>: it must exist and be visible, pass the:deleterule (as must every component it removes), and not be required by anything left behind. What its:on-delete :cascadereferrers bring in goes too, as for one delete. If any id fails, nothing is deleted. -
Every failure is reported, not only the first, in
extensions.failed, in the order ofids. Each entry is the errordelete<T>would give for that id, with the id:- Lang
- JSON
{"message": "3 of 90 couldn't be deleted, so none were", "path": ["deleteItems"], "extensions": {"code": "BATCH_FAILED", "failed": [{"id": "5c0e2a7d-...", "code": "NOT_FOUND", "message": "Item not found"}, {"id": "0d1f9b3c-...", "code": "FORBIDDEN", "message": "Not allowed: Item's delete rule fails at [?e :items/owner ?user]", "action": "delete", "rule": "[[?e :items/owner ?user]]", "clause": "[?e :items/owner ?user]"}, {"id": "7a2e6f10-...", "code": "VALIDATION_FAILED", "message": "Item has 1 Tag that requires it; delete it first", "blockedBy": [{"type": "Tag", "field": "item", "count": 1, "deletable": true}]}]}}
A missing id and one you can't see are both
NOT_FOUND. Remove or fix the failing ids and send the batch again. -
Duplicate ids are fine; each is deleted once, and
idsin the answer lists each once. -
At most 100 ids per batch. More gives
BAD_USER_INPUTwithextensions.limit"maxBatchSize"andmax. -
Cost: 10 per distinct id for the writes, on top of the selection.
deleteItems(ids: [a, b, c]) { ids }counts 1 + 30 + 1 = 32. -
CONFLICTandUNAUTHENTICATEDare for the whole batch, as for a single delete.
What may I do? (can and viewer)#
Every type has a can field, and the root has viewer, answered from the
same rules the mutations check, on the data as it is now, so a client can
show or hide a button, or tell "you may not" from "there is nothing":
- Lang
- GraphQL
{ viewer { user { id } # null signed out (the same as me) can { createNote } # one field per create mutation } notes(first: 20) { items { title can { update delete } } } }
- Lang
- JSON
{"data": {"viewer": {"user": {"id": "d41b..."}, "can": {"createNote": null}}, "notes": {"items": [{"title": "Groceries", "can": {"update": true, "delete": true}}]}}}
can { update delete }on an entity: its:updateor:deleterule holds for you now (falsewhen the type has no such mutation). Atrueis the rule as the data stands: an update is checked again after the change, so a write that would step outside the rule is still refused, and a delete can be refused by what still requires the entity.update<Field>(on<T>Can, for each field with its own:updaterule or:transitions): the entity'supdateand the field's own rule.nullmeans "it depends on the write": a rule withbefore(or:transitions) compares the entity before and after a write, so only the write decides it.viewer.can.create<T>:truewhen the:createrule holds whatever you write (:create true, or a rule over you alone such as[(authenticated? ?user)]or[(has-role? ?user :operator)]);falsewhen no write could pass it (no rule, signed out, or its part about you fails);nullwhen that part holds and the rest reads the new entity ((author? ?e ?user)), so it depends on what you write.viewer.can.grantRole(role:, scopeId:): whether the role's:grantrule holds for you (on that scope);viewer.rolesthe roles you hold ([RoleGrant!]!, see Roles). Both exist when the schema declares roles.- Signed out, you are held to the same anonymous variants as the mutations (see schema-permissions.md).
canis checked per page, like the view rules: one query per action for a page of entities. Each field counts in the query's cost like any other field. A live query selectingcanre-runs when what those rules read changes.- An entity that declares a field named
cankeeps it, and has no built-incan.
Roles#
A role is the app's own word for a permission group: october reserves
nothing inside a tenant's schema, so a role may be called operator,
admin or anything else the app means by it. See
schema-roles.md.
When the schema declares roles (see
schema-roles.md), the API has a RoleName
enum (each role in UPPER_SNAKE_CASE), grants as RoleGrant, and:
- Lang
- GraphQL
roleGrants(role: RoleName!, scopeId: UUID): [RoleGrant!]! grantRole(role: RoleName!, userId: UUID, email: String, scopeId: UUID): RoleGrant revokeRole(id: UUID!): DeletePayload type RoleGrant { id: UUID! role: RoleName! user: User # a grant to a user (null when you can't see them) email: String # a grant by email: held by whoever signs in with it scope: RoleScope # { id type }, for a role held on one entity grantedBy: User # null for a tenant admin's grant grantedAt: Instant! }
grantRoletakesuserIdoremail, andscopeId(the entity's id) for a scoped role. It is checked against the role's:grantrule:FORBIDDENwhen it doesn't hold,UNAUTHENTICATEDsigned out,NOT_FOUND(withextensions.field) for a scope or user you can't see,BAD_USER_INPUTfor a missing or extra scope, an unknown or retired role, or both or neither ofuserIdandemail. Granting what is granted returns the existing grant.- In demo mode a grant by email is
FORBIDDENwithextensions.reason: "demo": anyone can sign in as any email there. revokeRoleis allowed to whoever may grant the role on that scope, and to the holder of a grant by id. Anyone else getsNOT_FOUND.roleGrantsanswers every grant of the role (onscopeId) when you may grant it there, else only your own; signed out, none. Your own grants of every role areviewer { roles }.
- Lang
- GraphQL
mutation { grantRole(role: EDITOR, userId: "8f0c...", scopeId: "2a91...") { id scope { id type } } }- Lang
- JSON
{"data": {"grantRole": {"id": "c3e1...", "scope": {"id": "2a91...", "type": "Team"}}}}A rule with has-role? or has-role-on? reads the grants, so a live
query re-runs when a grant changes, and a write racing a revoke is
retried and then refused.
Erasing a user#
A user can erase themself, and a tenant's admin can erase any of its
users (october erase SLUG EMAIL, see cli-commands.md).
- Lang
- GraphQL
mutation { eraseMe(code: "123456") } # trueWhen the schema gives users an :erase rule (see
schema-permissions.md), eraseUser(id: UUID!)
erases another user the same way, for whoever passes it (NOT_FOUND for
a user you can't see, FORBIDDEN when the rule fails), and User.can { erase } says whether you may.
eraseMe needs a fresh sign-in code: send one to your own email with
send_magic_code first, then pass it. A token alone isn't enough, since
a token that leaked would then be enough to erase the account for good.
Signed out it is UNAUTHENTICATED; a wrong or used code is
BAD_USER_INPUT.
Erasing a user, in one transaction:
- ends their sessions (refresh tokens revoked, live streams closed) and removes their sign-in codes;
- removes their email and every field the app adds to users, and their role grants;
- removes the entities that declare
:on-erase :exciseon a ref to them (see schema-attributes.md); - keeps everything else they created. The user stays as a tombstone
that has only its id, so every ref to it stays valid and the
transactions they made still name it, but nobody can see it: their
posts'
author,createdByand a revision'sbyreadnull.
Then the email, the profile fields, their sign-in codes, their grants by
email and the erased entities are excised: Datomic removes them from
history too. Excision runs with the database's next indexing job, which
the erase asks for: on a real transactor about a second later. Until
then the current data no longer has them, but history still does
(history shows a user's email only to that user, who can't sign in
any more). Signing up again with the same email makes a new user.