Reading data

Reading a tenant's data over GraphQL: lists and their pages, filters and order, counts, and the data as it was at an earlier time. Part of the client API.

Queries: roots, connections, pagination, filters, order#

Each entity gets a list root and a by-id root:

Lang
GraphQL
lists(first: Int!, after: String, orderBy: ListOrder, filter: ListFilter): ListConnection!
list(id: UUID!, asOf: Long): List
  • first is required. It is capped at 100: a larger value returns at most 100. A negative value is BAD_USER_INPUT "first must be zero or more".
  • The by-id root returns null when the entity doesn't exist or the caller may not view it. asOf reads it as it was at a past revision: see Reading the past.
  • Lists contain only entities the caller may view.

Nested lists#

Reverse refs and many-refs are connections with the same arguments, except that first is optional: it is needed to select items or pageInfo, not for a count of each one (items { count }, see Counts per item):

Lang
GraphQL
{ lists(first: 10, orderBy: {field: TITLE, direction: ASC}) {
    items {
      id title color ownerNote
      owner { displayName }
      items(first: 2) { items { text } pageInfo { hasNextPage endCursor } }
    }
    pageInfo { hasNextPage endCursor }
} }
Lang
JSON
{"data": {"lists": {"items": [
  {"id": "0b6d1c1e-8a9f-4a51-9d55-6a3f4f0f0001", "title": "Groceries", "color": "GREEN",
   "ownerNote": null, "owner": {"displayName": "Ada Lovelace"},
   "items": {"items": [{"text": "Milk"}, {"text": "Eggs"}],
             "pageInfo": {"hasNextPage": true, "endCursor": "AkB0e4kPXKpTN4rseiv6..."}}},
  {"id": "0b6d1c1e-8a9f-4a51-9d55-6a3f4f0f0002", "title": "Trip", "color": null,
   "ownerNote": null, "owner": {"displayName": null},
   "items": {"items": [{"text": "Passports"}, {"text": "Sunscreen"}],
             "pageInfo": {"hasNextPage": false, "endCursor": "AkDQjSFPvBTYvqO5H71a..."}}}],
  "pageInfo": {"hasNextPage": false, "endCursor": "AkDtMGw9mjESI3pBhZ-O..."}}},
 "extensions": {"cost": {"requested": 211, "actual": 37, "budget": 20000, "remaining": 19963}}}

Pagination#

Pass the last endCursor as after to get the next page. Stop when hasNextPage is false.

Lang
GraphQL
query Page($list: UUID!, $after: String) {
  items(first: 2, after: $after, filter: {listId: {eq: $list}}) {
    items { text }
    pageInfo { hasNextPage endCursor }
  }
}

Three calls on a list with five items give Milk, Eggs, then Bread, Apples, then Coffee with hasNextPage: false.

  • Cursors are opaque, URL-safe strings of about 70 characters. They are encrypted: don't parse them, and never construct one. Pass back only what endCursor gave you, to the same tenant, root (or field), orderBy and direction. Anything else, including a cursor that has been edited, gives BAD_USER_INPUT "Invalid cursor".
  • A cursor stays valid when the item it came from is deleted.
  • A page can hold fewer than first items while hasNextPage is true. A list reads entities in its order and keeps the ones you may see that match its filters. It checks at most 1,000 entities per page. When that many were checked and the page isn't full, you get what was found, hasNextPage: true, and an endCursor at the last entity checked, so the next page continues after it. This happens when a rule or filter keeps few of the entities in the list's order (say you may see 3 of 50,000). It can even be an empty page with hasNextPage: true. Keep following endCursor until hasNextPage is false; don't treat a short page as the end.
  • A cursor can become invalid when the server's cursor key is rotated. Then start again from the first page (no after).

Filters#

List roots, connection fields and aggregates take a filter argument, <Type>Filter. It has one field per filterable attribute, and each field takes an object of operators:

Lang
GraphQL
{ items(first: 10, filter: {rank: {gte: 2}, text: {startsWith: "B"}},
        orderBy: {field: CREATED_AT, direction: DESC}) { items { text rank } } }

The filterable attributes:

Field For Its input
<field> every indexed data attribute: :indexed? or :unique?, not :json, not long text (see Indexes) the type's: StringFilter, LongFilter, FloatFilter, InstantFilter, BooleanFilter, UUIDFilter
<field> every enum attribute <Enum>Filter (ListColorFilter)
<ref>Id every one-target ref (listId, ownerId) UUIDFilter, the target's id

The operators:

Operator Matches On
eq equal to the value every field
in equal to one of the values (at most 100; in: [] matches nothing) all but booleans
gt, gte, lt, lte greater than, greater than or equal to, less than, less than or equal to strings, numbers, instants
startsWith strings starting with the value, case-sensitive strings
  • Everything given must hold: the operators of one field, and the fields, combine with AND. {rank: {gte: 1, lt: 4}} is a range. An operator given null is left out.
  • Strings compare by their UTF-16 code units, as Java does: "B" < "a", and startsWith: "ap" doesn't match "Apple".
  • A <ref>Id naming an entity the caller can't view matches nothing, as for an id that doesn't exist; in in, such ids are left out.
  • Attributes with a :view rule are never filterable: a filter would reveal the hidden value.
  • A range or startsWith on the field the list is ordered by walks that field's index between the bounds, so it costs what it returns. On another field it narrows the walk when few entities match (up to 1,000), and is otherwise checked entity by entity, like a rule: see the scan cap above.
  • There is no "contains" and no full-text search yet. Use startsWith, or store a field made for searching (a lower-cased name, a slug) and filter on that.
Lang
JSON
{"data": {"items": {"items": [{"text": "Coffee", "rank": 2}, {"text": "Apples", "rank": 2},
                              {"text": "Bread", "rank": 2}, {"text": "Eggs", "rank": 2}]}}}

Order#

orderBy: {field, direction}. The fields are CREATED_AT plus every required indexed data attribute (TITLE for lists). The default is CREATED_AT ASC, oldest first, unless the schema sets another with :order (see Other entity keys); the orderBy argument's description then says which. Ties are broken by id. An optional attribute can't be an order field.

Counts and group-by (aggregates)#

Each entity has an aggregate root next to its list, <list>Aggregate, taking the list's filters:

Lang
GraphQL
{
  tasksAggregate {
    count
    capped                                  # true: the counts stop at the cap
    scanned                                 # entities checked
    groupBy(field: STATUS) { key count }    # per value of a field
    groupByDay { day count }                # per day of creation, UTC
  }
}

Ann sees her three tasks and one of Bob's two (an urgent one, which everyone may see):

Lang
JSON
{"data": {"tasksAggregate": {"count": 4, "capped": false, "scanned": 5,
  "groupBy": [{"key": "TODO", "count": 1}, {"key": "DOING", "count": 1}, {"key": "DONE", "count": 2}],
  "groupByDay": [{"day": "2026-10-19", "count": 4}]}}}

Filters are the list's: tasksAggregate(filter: {status: {eq: DONE}}) { count }.

  • The same entities as the list: what you may view (the :view rule, checked the same way, in chunks), matching the filters. A count never includes what the list wouldn't show you.
  • groupBy(field:) takes an enum field, a boolean field or an indexed field (<Type>GroupField), never one with its own :view rule: a group's key and count would show the hidden values. Keys are as the field shows them (enum values as the enum spells them), null for unset; enum values come in declaration order, null last; only values that occur are listed.
  • groupByDay: the count per day the entities were created, UTC (YYYY-MM-DD), oldest first.
  • Bounded: one aggregate checks at most 5000 entities (the server's :max-aggregate-scan), oldest first. Past that, capped is true and the counts are of those 5000 only: narrow it with filters.
  • Cost: estimated at the cap (so the bucket must hold it), then counted as what it scanned: tasksAggregate { count } over 5 entities is requested 5002 and actual 7 (two fields and five entities). Several aggregate fields in one query each count their cap, so ask for one aggregate and select every count you need inside it.

Counts per item#

Every connection has count and capped next to items, so a page can show how many each of its entities holds without paging them:

Lang
GraphQL
{ lists(first: 50, orderBy: {field: TITLE}) { items { title items { count capped } } } }
Lang
JSON
{"data": {"lists": {"items": [
  {"title": "Groceries", "items": {"count": 5, "capped": false}},
  {"title": "Trip", "items": {"count": 2, "capped": false}}]}},
 "extensions": {"cost": {"requested": 1251, "actual": 13, "budget": 20000, "remaining": 19987}}}
  • The same entities as the field pages through: what you may view, with the field's filter (items(filter: {rank: {eq: 2}}) { count }); first, after and orderBy don't change it. Selected without items and pageInfo, nothing is paged, and first may be left out; selecting items or pageInfo without first is BAD_USER_INPUT.
  • Bounded: a count checks at most 1,000 entities per parent (the server's :max-nested-count-scan), oldest first. Past that, capped is true and count is a lower bound: show "1000+". For more, use the aggregate root with a filter (itemsAggregate(filter: {listId: {eq: ...}})).
  • Cost: a count is charged per parent, not per entity it counts: 1 for the field plus 20 (one per check of 50 entities, at the cap) in the estimate, and in actual 1 per 50 entities it checked. The query above is 1 + 50 + 50 + 50 × (1 + 20) + 50 + 50 = 1251 requested; with two lists it ran up 11 for the fields plus 2 for the checks. Paging every list's items to count them (items(first: 100) { items { id } }) is estimated at 10,201, over the limit, and refused.
  • At the root, lists(first: 0) { count } works the same way, bounded at 1,000; the aggregate root counts further.

History#

Every entity type has the revisions of each entity, newest first, and how many there are:

Lang
GraphQL
history(first: Int!, after: String, field: [ListHistoryField!]): RevisionConnection!
revisionCount(field: [ListHistoryField!]): Int!

type Revision { basisT: Long!  at: Instant!  by: User  changes: [FieldChange!]! }
type FieldChange { field: String!  before: JSON  after: JSON
                   added: [UUID!]  removed: [UUID!]  hidden: Boolean! }
  • A revision is one transaction that changed the entity. The one that created it is the oldest, so "edited N times" is revisionCount - 1.
  • basisT identifies the revision (the transaction's position in the database); at is when it committed; by the user who made it, null for system writes. Pass basisT as asOf to read the entity as it was then (below).
  • changes lists the fields it changed, by their name on the type. Values are as the field shows them: enum values as the enum spells them ("GREEN"), refs as the target's id. Many-refs list the ids added and removed (before and after are null).
  • field: keeps only the revisions that changed one of those fields (the enum lists the type's fields: TITLE, OWNER, MEMBERS, ...). The revisions it keeps are whole: they list every field they changed. revisionCount takes the same argument.
  • Pagination and its cursors work as for lists. A cursor belongs to one entity's history.
  • revisionCount counts among the entity's newest 1,000 revisions (with field:, the newest 1,000 that changed those fields). Past that it stops counting, as a page stops checking.

Ada owns a list; she renamed it, added a private note, shared it with Bob, then changed its color:

Lang
GraphQL
query ($id: UUID!) {
  list(id: $id) {
    title revisionCount
    history(first: 10) {
      items { basisT at by { displayName } changes { field before after added removed hidden } }
      pageInfo { hasNextPage endCursor }
    }
  }
}

As Ada:

Lang
JSON
{"data": {"list": {"title": "Weekly groceries", "revisionCount": 4, "history": {"items": [
  {"basisT": 1032, "at": "2026-10-19T01:47:21.581Z", "by": {"displayName": "Ada Lovelace"},
   "changes": [{"field": "color", "before": "GREEN", "after": "BLUE", "added": null, "removed": null, "hidden": false}]},
  {"basisT": 1031, "at": "2026-10-19T01:47:21.576Z", "by": {"displayName": "Ada Lovelace"},
   "changes": [{"field": "members", "before": null, "after": null,
                "added": ["920cce27-fc60-4f43-9a51-e55215d4337a"], "removed": [], "hidden": false}]},
  {"basisT": 1030, "at": "2026-10-19T01:47:21.568Z", "by": {"displayName": "Ada Lovelace"},
   "changes": [{"field": "ownerNote", "before": null, "after": "budget 60", "added": null, "removed": null, "hidden": false},
               {"field": "title", "before": "Groceries", "after": "Weekly groceries", "added": null, "removed": null, "hidden": false}]},
  {"basisT": 1028, "at": "2026-10-19T01:47:21.563Z", "by": {"displayName": "Ada Lovelace"},
   "changes": [{"field": "color", "before": null, "after": "GREEN", "added": null, "removed": null, "hidden": false},
               {"field": "owner", "before": null, "after": "556200b0-84e5-4d1e-987b-948fa7ab21cc", "added": null, "removed": null, "hidden": false},
               {"field": "title", "before": null, "after": "Groceries", "added": null, "removed": null, "hidden": false}]}],
  "pageInfo": {"hasNextPage": false, "endCursor": null}}}},
 "extensions": {"cost": {"requested": 394, "budget": 20000, "remaining": 19900, "actual": 80}}}

As Bob, the same query gives "revisionCount": 2 and only the two newest revisions: he could see the list only from the moment he was added to it, and ownerNote is the owner's alone.

A deal's stage moves#

Who moved a deal between stages, and when, needs no table of its own: a stage enum and history(field: STAGE) answer it. With this schema (one team per tenant, so every signed-in user is a teammate):

Lang
EDN
{:entities
 {:$users {:attrs       {:display-name {:type :string :optional? true :min 1 :max 40}}
           :permissions {:view [(authenticated? ?user)]}}
  :deals  {:attrs       {:title {:type :string :min 1 :max 160}
                         :stage {:type :enum :values [:lead :qualified :proposal :won :lost]}
                         :value {:type :double :optional? true :min 0}
                         :owner {:type :ref :to :$users :required? true :default :auth/user
                                 :immutable? false}}
           :permissions {:view   [(authenticated? ?user)]
                         :create [(authenticated? ?user)]
                         :update [(authenticated? ?user)]}}}}

Ada created the deal as a lead and set its value; Bob qualified it, Ada moved it to proposal (raising the value), Bob marked it won:

Lang
GraphQL
query StageMoves($id: UUID!) {
  deal(id: $id) {
    title stage
    edits: revisionCount
    moves: revisionCount(field: STAGE)
    history(first: 10, field: STAGE) {
      items { basisT at by { displayName } changes { field before after } }
    }
  }
}
Lang
JSON
{"data": {"deal": {"title": "Acme renewal", "stage": "WON", "edits": 5, "moves": 4, "history": {"items": [
  {"basisT": 1033, "at": "2026-10-19T01:47:46.386Z", "by": {"displayName": "Bob"},
   "changes": [{"field": "stage", "before": "PROPOSAL", "after": "WON"}]},
  {"basisT": 1032, "at": "2026-10-19T01:47:46.381Z", "by": {"displayName": "Ada"},
   "changes": [{"field": "stage", "before": "QUALIFIED", "after": "PROPOSAL"},
               {"field": "value", "before": 12000.0, "after": 15000.0}]},
  {"basisT": 1031, "at": "2026-10-19T01:47:46.378Z", "by": {"displayName": "Bob"},
   "changes": [{"field": "stage", "before": "LEAD", "after": "QUALIFIED"}]},
  {"basisT": 1028, "at": "2026-10-19T01:47:46.370Z", "by": {"displayName": "Ada"},
   "changes": [{"field": "owner", "before": null, "after": "bf193dbd-356c-4004-a9ba-7674cf5ee1f0"},
               {"field": "stage", "before": null, "after": "LEAD"},
               {"field": "title", "before": null, "after": "Acme renewal"}]}]}}},
 "extensions": {"cost": {"requested": 186, "budget": 20000, "remaining": 19924, "actual": 60}}}

moves counts the creating revision, which set the first stage. The revision where Ada first set the value is left out, since it didn't touch the stage; the one at 1032 is kept whole.

Who sees what in history#

A past value is shown only when you may view it now and at the time:

  • You reach history through the entity, so it must exist and you must be allowed to view it now. Deleted entities have no history through the API.
  • A revision is shown only if you could view the entity at that revision. The value before a change is shown only if you could view it just before, too; otherwise before is null and hidden is true. (Bob's oldest revision above is the one that added him; it showed nothing from before, since members was empty.)
  • A field with its own :view rule: its changes are shown only when the rule holds for you now and held at the revision. Otherwise the change is left out.
  • A ref target you can't view now, or one deleted since, is withheld: null (or missing from added/removed) with hidden: true, so you still see that the field changed.
  • by is null unless you may view that user, and every rule that hides the entity's author (a :default :auth/user ref with a :view rule) holds now and held then, as for createdBy.
  • A revision with nothing left to show is skipped, except the one that created the entity. revisionCount counts exactly the revisions history shows, so it can differ per caller: 4 for Ada, 2 for Bob.
  • history pages like a list: it checks at most 1,000 revisions per page, so after more than 1,000 skipped revisions in a row a page can be short or empty with hasNextPage: true (follow endCursor). That tells you an entity you can see has had many changes you can't, never what they were or who made them.

Reading the past (asOf)#

Every by-id root takes asOf, a basisT (a revision's, or a live push's): the entity as it was right after that transaction.

Lang
GraphQL
query ($id: UUID!, $t: Long) {
  deal(id: $id, asOf: $t) { stage value owner { displayName } edits: revisionCount }
}

With "t": 1031:

Lang
JSON
{"data": {"deal": {"stage": "QUALIFIED", "value": 12000.0, "owner": {"displayName": "Ada"}, "edits": 3}},
 "extensions": {"cost": {"requested": 6, "budget": 20000, "remaining": 19994, "actual": 9}}}
  • Everything nested in it is read at the same point: its fields, refs, lists, createdBy, even its history and revisionCount (the revisions up to then).
  • The same rule as history: the entity, and every entity reached from it, must exist now and you must be allowed to view it now and then; a field with a :view rule shows only if the rule holds now and held then. Otherwise it is null (or left out of a list), as if it didn't exist. Bob reading Ada's list asOf 1030, before she shared it, gets {"list": null}; at 1031 he gets it, with ownerNote: null. A list nested in an asOf read can return a short page with hasNextPage: true; follow endCursor as usual.
  • Before the entity existed, the answer is null. A basisT later than the latest transaction, or not positive, is BAD_USER_INPUT:
Lang
JSON
{"data": {"deal": null},
 "errors": [{"message": "asOf 99999 is in the future: the latest basisT is 1033",
             "path": ["deal"], "extensions": {"code": "BAD_USER_INPUT"}}]}
  • Only by-id roots take asOf: list roots don't (yet).