Attributes and refs

An entity's attributes: their types and constraints, which are required, immutable, unique or indexed, refs between entities, and enums. Part of the schema language.

Data attributes#

{:type <type> ...options}. The types:

:type Stored as GraphQL type JSON on the wire
:string string String string
:long 64-bit integer Long number; a decimal string beyond ±(2^53 − 1)
:double 64-bit float Float number
:boolean boolean Boolean true / false
:instant point in time Instant ISO-8601 string, "2026-10-20T09:00:00Z"
:uuid UUID UUID string
:json JSON text JSON any JSON value

Options on any data attribute:

Key Meaning
:optional? true makes the attribute optional. Data attributes are required by default.
:indexed? Index the attribute. An indexed attribute becomes a list filter, and, if it is also required, an orderBy field. See Indexes.
:unique? No two entities may hold the same value. See Unique values.
:immutable? true: set on create, never changed. See Immutable attributes.
:view A rule that hides the value from some viewers. See Field-level :view.
constraints See the next section.

A :json attribute takes any JSON value (object, array, string, number). It reads back as the same JSON value.

Constraints and sanitisers#

Constraints are checked on every create and update. A value that fails gives a VALIDATION_FAILED error with a message per field (see api-errors.md).

Key Types Meaning
:min :string minimum length (a whole number)
:max :string maximum length
:min :long, :double minimum value (an integer on :long)
:max :long, :double maximum value
:pattern :string a regular expression the whole value must match (Java syntax)
:format :string :email (loose: something@something.tld) or :url (http:// or https://)

Sanitisers change a string before it is validated and stored:

Key Effect
:trim? removes leading and trailing whitespace
:collapse-whitespace? turns each run of whitespace (newlines too) into one space, and trims
:lowercase? lower-cases the value

Only the sanitisers you declare run. For example, with :format :email :lowercase? true but no :trim?, the input " CY@Example.COM" fails with should be a valid email because the leading space stays.

Example:

Lang
EDN
:profiles {:attrs {:handle  {:type :string :unique? true :indexed? true
                             :pattern "^[a-z0-9_]{3,20}$" :trim? true :lowercase? true}
                   :website {:type :string :format :url :optional? true}
                   :bio     {:type :string :optional? true :max 200 :collapse-whitespace? true}
                   :rating  {:type :double :min 0 :max 5 :optional? true}}
           ...}

With this schema, handle: " Cy_L " is stored as "cy_l", and bio: "Counts things\n carefully" is stored as "Counts things carefully". Bad values give one message per field:

Lang
JSON
"errors": {
  "handle":  ["should match the pattern ^[a-z0-9_]{3,20}$"],
  "rating":  ["should be at most 5"],
  "website": ["should be a valid http(s) URL"]
}

october checks the constraint options when you plan the schema. Examples of refused options: a constraint the type doesn't take (:pattern on a :long), :min greater than :max, a :pattern that doesn't compile.

Required and optional#

Kind of attribute Default Change it with
data attribute required :optional? true
enum required :optional? true
ref optional :required? true

A required attribute must be given on create and can't be cleared with null on update. Refs reject :optional? and enums reject :required?, so there is one way to say each.

Immutable attributes#

:immutable? true means that the attribute is set when the entity is created and never changes afterwards. Data, enum and ref attributes take it.

Kind of attribute Default
a required one-target ref immutable
everything else (data, enums, optional refs, many-refs) mutable

So an answer's :question, an item's :list and a post's :author are immutable unless you say :immutable? false:

Lang
EDN
:answers {:attrs {:body     {:type :string}
                  :question {:type :ref :to :questions :required? true}            ; immutable
                  :author   {:type :ref :to :$users :required? true :default :auth/user}}} ; immutable
:bookmarks {:attrs {:question {:type :ref :to :questions :required? true
                               :immutable? false}}}                                ; may be moved

An immutable attribute:

  • is left out of the update input (AnswerUpdateInput has body and no questionId), so the GraphQL types rule out the change;
  • can't be cleared with null;
  • has no add/remove mutations when it is a many-ref;
  • is marked @immutable in /schema.graphql, and "x-immutable": true in /schema.json.

A request that sends questionId to updateAnswer fails GraphQL validation. Behind the types, the write path refuses the change too, as VALIDATION_FAILED {"questionId": ["can't be changed after it is created"]}.

Turning immutability on or off (with :immutable?, or by making a ref required or optional) is listed under API in the plan, and is never destructive. Turning it off loosens the schema: read the next warning first.

:update rules and create-only conditions. The :update rule is not the :create rule: a condition that only :create checks does not hold for updates. Take a Q&A app where answers can't be added to closed questions, and answers may move:

Lang
EDN
:answers {:attrs {:question {:type :ref :to :questions :required? true :immutable? false
                             :update [[?e :answers/question ?q] (not [?q :questions/closed true])]}
                  ...}
          :permissions {:create [(authenticated? ?user) (author? ?e ?user)
                                 [?e :answers/question ?q] (not [?q :questions/closed true])]
                        :update [(author? ?e ?user)]}}

Without the field's :update, an author could create an answer on an open question, then move it onto a closed one with updateAnswer: the entity's :update rule only asks for the author. The field rule runs whenever question changes, on the state before and after the move, so the answer moves only between open questions. Or keep :question immutable (the default). See Field :update rules.

Unique values#

:unique? true on a data attribute or a ref means that no two entities hold the same value. A create or update that uses a taken value fails:

Lang
JSON
{"code": "VALIDATION_FAILED", "errors": {"handle": ["already taken"]}}

A unique attribute is also indexed, so it becomes a list filter (profiles(first: 5, filter: {handle: {eq: "ada_l"}})). On a ref, :unique? also makes the reverse side a single value instead of a list (see the next section).

Indexes#

An index is exactly what the API filters and orders on: october indexes an attribute when, and only when, it is a list filter or an orderBy field. :indexed? true asks for both. It has no effect (no index, no filter, no order) on:

  • a :json attribute;
  • an attribute with a :view rule (a filter or an order would reveal the value the rule hides);
  • long text: a :string whose :max is over 256. Give a string you want to filter or sort on a :max of 256 or less. A :string with no :max is indexed, but the plan warns: one long value would bloat the index.

A :unique? attribute is always a filter (and, when required, an order field), whatever its length: uniqueness needs the index anyway. Refs and enums are always indexed by Datomic, so their filters (<ref>Id, an enum value) need nothing. Private entities have no API; their :indexed? attributes are indexed as declared.

october plan lists every index a change adds or drops:

Lang
Text
Indexes:
  adds an index on Deal.stage
  drops the index on Deal.notes: the API no longer filters or orders on it

Adding an index to an attribute that already holds data is safe and needs no downtime. Datomic builds the index in the background (seconds for tens of thousands of values). Until it is built, an orderBy on that attribute sorts in memory, and a filter on it is checked entity by entity: slower, but the answers are the same.

Refs (relationships)#

A ref points from one entity to another. You declare it on one side only; october derives the other side.

Lang
EDN
:items {:attrs {:list {:type :ref :to :lists :required? true :reverse :items}}}

This gives Item.list: List and, on the other side, List.items(...): a paginated connection of the list's items.

Key Meaning
:to the target etype (required)
:many? true: a set of targets (a many-to-many). Default: one target.
:required? true: must be set on create; can't be cleared. A required one-target ref is also immutable by default (see Immutable attributes).
:immutable? true: set on create, never changed. false: may change on update. Default: true for a required one-target ref, else false.
:unique? true: no two entities may point at the same target, so the reverse side is one entity, not a list. Use it for one-to-one.
:component? true: the target belongs to this entity. Deleting this entity deletes the target too.
:on-delete :cascade: this entity belongs to the target. Deleting the target deletes this entity too. See :on-delete :cascade.
:reverse the label of the reverse field on the target, or false for no reverse field. Default: the source etype's name without $ (:items here).
:default :auth/user: on create, fill the ref with the signed-in user when the input leaves it out, and pin it: a write may set it only to the signed-in user. Only on a one-target ref :to :$users. See :default :auth/user.
:pinned? false: a :default :auth/user ref is a default only, and a write may name any user. Default: true. Only with :default :auth/user.
:view a rule that hides the ref from some viewers (see Field-level :view).

Refs take no constraints and no :indexed? (refs are always indexed).

In mutation inputs a one-target ref is <label>Id (listId) and a many-ref is <singular label>Ids (members gives memberIds, tags gives tagIds). See api-mutations.md.

Reverse field names#

Two refs to the same etype can't both use the default reverse name. If you declare :owner and :members on :lists, both pointing at :$users, both reverse fields would be User.lists. Plan refuses the schema and tells you to set :reverse:

Lang
Text
Refused (400 bad-schema): Label :lists is declared more than once on :$users: [:reverse-of :lists/owner], [:reverse-of :lists/members]. Set :reverse <label> (or :reverse false) on the ref to rename its reverse field.

The fix:

Lang
EDN
:owner   {:type :ref :to :$users :required? true :default :auth/user :reverse :owned-lists}
:members {:type :ref :to :$users :many? true :reverse :shared-lists}

One-to-one#

Lang
EDN
:profiles {:attrs {:user {:type :ref :to :$users :unique? true :required? true
                          :default :auth/user :reverse :profile}}
           ...}

This gives Profile.user: User and User.profile: Profile (user is nullable although required: users are closed by default, see $users). A second profile for the same user fails with {"userId": ["already taken"]}.

Components#

Lang
EDN
:news   {:attrs {:cover {:type :ref :to :images :component? true}} ...}
:images {:attrs {:url {:type :string :format :url}}
         :permissions {:view true :create [(authenticated? ?user)]
                       :update [(created-by ?e ?user)]}}

Deleting a news item also deletes its cover image. Two rules apply:

  • To set a component ref (on create, update or add), the caller needs the :update permission on the target. An etype with no :update rule can't be made a component through the API.
  • A delete fails if the caller may not delete every entity it removes, components included.

Deleting the target of a required ref#

When an entity is deleted, every ref to it is removed. If that leaves another entity without a required ref, the delete is refused (october restricts, unless the ref says :on-delete :cascade). With the shared lists schema, deleting a list that still has items gives:

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

Only the blockers the caller can see are counted; others are mentioned without a number or a type (hiddenBlockers: true). Delete the items first (deleteItems(ids: [...]) takes them in one transaction, all or nothing; see api-mutations.md), or let them go with the list: :on-delete :cascade on the item's ref (below). A batch delete covers one etype, so without a cascade the items and then the list are two calls. If the caller can't delete the blockers (no :delete rule on items, or it refuses them), the message says so: "List has 3 Items that require it, and they can't be deleted, so neither can this List", with deletable: false.

:on-delete :cascade#

Lang
EDN
:books {:attrs       {:title {:type :string}
                      :owner {:type :ref :to :$users :required? true :default :auth/user}}
        :permissions {:view true :create [(authenticated? ?user)] :delete [[?e :books/owner ?user]]}}
:votes {:attrs       {:book  {:type :ref :to :books :required? true :on-delete :cascade}
                      :voter {:type :ref :to :$users :required? true :default :auth/user}}
        :permissions {:view   [[?e :votes/voter ?user]]
                      :create [(authenticated? ?user)]
                      :delete [[?e :votes/voter ?user]]}}

Deleting a book deletes every vote on it, in the same transaction. A vote with a cascading ref of its own (a reason with :vote {... :on-delete :cascade}) takes that along too, and so on down. Without the option the book can't be deleted while it has votes, and its owner can't delete other members' votes, so the book would be stuck.

The book's :delete rule decides. By declaring the cascade, the schema says the votes are part of the book's life, so deleting the book checks only the book's own rule. Each vote's :delete rule isn't checked, and neither is its :view: votes the caller can't see go too. That is the point (the owner can't see who voted, yet may remove the book), and it is also the risk: whoever may delete the target removes other people's data. october plan warns about every cascade ref so you decide it on purpose:

Lang
Text
Warnings:
  deleting a Book also deletes every Vote pointing at it, including ones other users made and ones the deleter can't see: Vote.book is :on-delete :cascade, so only the Book's :delete rule is checked

What the caller learns: the answer is the same {id} as any delete, with nothing about what went with it. Restrict still applies to refs without a cascade, the cascaded entities' included: a visible flag that requires a vote the caller can't see is counted as hidden, so the error never shows that the vote exists.

  • Only :cascade. A required ref without it restricts the delete; an optional one is cleared.
  • Only on a one-target ref (not :many?), not with :component? (that says the opposite owner), and only between your own entities: not :to :$users (users aren't deleted; for records that go when a user is erased see :on-erase :excise), and not on an attribute you add to $users.
  • One delete removes at most 1000 entities through cascades (:max-cascade in the server's :graphql config). More is refused with BAD_USER_INPUT, extensions.limit "maxCascade", and nothing is deleted; this is checked after the target's own rules, so a caller who may not delete it gets FORBIDDEN as usual.
  • Batch deletes cascade the same way, for every id.
  • Adding or removing it is a Permissions change in the plan, never destructive.

:default :auth/user#

Lang
EDN
:author {:type :ref :to :$users :required? true :default :auth/user}

A create that leaves out authorId gets the signed-in user. The ref is also pinned: a create or an update may set it only to the signed-in user, so nobody can write a post "by" someone else, whatever the rules say. Naming another user is refused before any rule runs:

Lang
Text
ada  createPost(body: "hi")                  ok, author ada
ada  createPost(body: "hi", authorId: ada)   ok
ada  createPost(body: "hi", authorId: bob)   VALIDATION_FAILED {"authorId": ["can only be the signed-in user"]}

A required ref is immutable too (see Immutable attributes), so authorId isn't in the update input. An optional pinned ref (an assignee that defaults to whoever creates the task) stays in the update input, and an update may set it to the caller ("assign it to me") or clear it, never to someone else. The input field's description in the GraphQL schema says so. /schema.json doesn't list the attribute as required.

To let a write name another user (a gift "for" someone, a task assigned to a teammate), opt out with :pinned? false:

Lang
EDN
:assignee {:type :ref :to :$users :default :auth/user :pinned? false}

Then the default only fills in a missing value, and the rules must say whom a caller may name: check it in :create, and in the attribute's own :update (see Field :update rules).

Changed (November 2026). Before, the ref was a default only: a write could name anyone unless a rule checked it. october plan shows the pin under Permissions for each such ref of a tenant last pushed before then ("now pinned: ...: the system default changed"), with how to opt out, until the next push (see Changing a schema). The pin applies from the first boot of the new server, not from the push.

:on-erase :excise#

Lang
EDN
:user {:type :ref :to :$users :required? true :unique? true :default :auth/user :on-erase :excise}

When the user this ref points at is erased (see api-mutations.md), the entity goes with them: retracted, and excised from history. Use it for records that are about the person (a waitlist entry, a profile), not for what they made for others: a post or a deal stays, with its author an anonymous tombstone. Only on a ref to $users, and nothing may point at an entity that has it (the ref would be left pointing at nothing).

Enums#

Lang
EDN
:stage {:type :enum :values [:draft :in-review :published]}
  • :values is a non-empty list of unqualified keywords, in kebab-case.
  • In GraphQL the enum type is <Type><Label> (NewsStage) and each value is UPPER_SNAKE_CASE: DRAFT, IN_REVIEW, PUBLISHED.
  • An enum is required unless :optional? true. Every enum attribute is a list filter (news(first: 5, filter: {stage: {eq: PUBLISHED}})).
  • An enum takes no :many?, :unique?, :indexed?, :default or :required?.
  • In a permission rule, a value is the keyword :<etype>.<label>/<value>: [?e :news/stage :news.stage/published].
  • Adding a value is a safe change. Removing one is refused.
  • true, false and null are not allowed as values.
  • :transitions {:draft #{:in-review} :in-review #{:draft :published}} limits the moves an update may make; see :transitions on an enum.

Other entity keys: :order, :private? and :graphql/type#

:order [<label> :asc|:desc] sets how the entity's lists are sorted when a query passes no orderBy: its list root and every has-many field that lists it. The label is :created-at or an attribute that can be an orderBy field (required and indexed; see Indexes). Without :order, lists are oldest first ([:created-at :asc]). A query's orderBy always wins.

Lang
EDN
:messages {:attrs {...} :order [:created-at :desc]}   ; newest first

Changing it changes no data. The plan lists it under api, and cursors from the old default order stop working (Invalid cursor). The default shows in the orderBy argument's description ("Default: CREATED_AT DESC").

:private? true removes the entity from the API completely: no GraphQL type, no roots, no mutations, and refs into or out of it are not exposed. Nothing a client can call can read or write it, so in an app schema it is rarely useful.

:graphql/type "Name" sets the GraphQL type name. By default the name is the etype made singular in a simple way (ies becomes y, a final s is removed unless the name ends in ss) and capitalised: :lists gives List, :categories gives Category. Use :graphql/type when that is wrong:

Lang
EDN
:news {:graphql/type "News" ...}

If the by-id root would have the same name as the list root, it gets a ById suffix: news(first: ...) and newsById(id: ...).