Skip to content

chatfuel-lab/wizard / content/modules/core/skill

references/pagination.md

View on GitHub
# Pagination

Relay-style cursor connections (`edges { cursor node } pageInfo { hasNextPage hasPreviousPage startCursor endCursor }`) — with platform-specific quirks.

## Typed cursors

Every connection has its own cursor **scalar** and its own PageInfo **type** (there is no shared `PageInfo`): `MessagesCursor`, `ContactSearchCursor`, `BotsCursor`, `BotAttributeCursor`, `WhatsAppTemplateCursor`, `KeywordRuleCursor`, `FbPageCursor`, `InstagramMediasCursor`, `MetaAdCursor`, … Cursors are opaque strings; never construct one, only echo values from `pageInfo`/`edges`.

## `first` requiredness varies

- `Conversation.messages(first, after, before)` — `first` is **optional**.
- `Bot.contactsConnection` / `contactChatsConnection` / `contactDealsConnection` — `first` is **required** (`Int!`).

Check the field signature in `references/schema.graphql` rather than assuming.

## Message history direction semantics (non-obvious)

`Conversation.messages`:

- **No cursor, or `after`** ⇒ **descending** — newest message first. `after: pageInfo.endCursor` walks **backwards into history** (older pages).
- **`before`** ⇒ ascending order.
- Practical loop for a chat UI: initial load `messages(first: 100)`; "scroll up to load older" = `messages(first: 100, after: <endCursor>)`; `pageInfo.startCursor` is the NEWEST message's cursor (used for mark-as-read).

## Chat/contact/deal lists

Forward-only in practice: page with `after: pageInfo.endCursor`, guard with `hasNextPage`, and never issue a page fetch while the previous one is in flight. Changing any filter argument resets the connection — throw away accumulated edges.

## Client-side merge rules

When accumulating pages and applying subscription updates into the same list:

1. **De-duplicate by node id** — an incoming page or update may contain nodes you already hold; replace rather than append.
2. Live updates (`contactsChatUpdates`, `contactsDealUpdates`) do NOT tell you the position: re-sort yourself — chat list by `lastConversationMessageTime` desc, deals by `lastSalesStageUpdateTime` desc.
3. Messages merge by **`clientId`** (not `id`) — see the chatfuel-livechat skill's guide.

## Watch out

- `Bot.whatsAppTemplates` returns the full list; do not rely on `first`/`after`/`before` here (and the field is nullable).
- No pagination at all (full list every time): `Bot.goodsCatalog`, `Bot.specialists`, `Bot.contactScopes`, `Bot.members`, `Bot.invites`, `Workspace.bots`, `CurrentUserAccount.workspaces`.
- An `after` cursor that has fallen out of the result window can produce an "invalid cursor" error — recover by refetching from the start.
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 322kUpdated Claude CodeCodexVerifiedInstall