Remote / foldkit-remote-server
Queries
A Query Source answers the ordered connection itself. The client's select
travels with the request, and the handlers return the selected fields of the
page's items with the edges, so one response carries both:
import { Query } from 'foldkit-remote'
const ProjectsByOwner = Query.make('ProjectsByOwner', {
Input: Schema.Struct({ ownerId: Schema.String }),
Result: Query.connection(Project),
})
// `projectsPage` is your own reader: one page of edges for the window.
const ProjectsByOwnerSource = RemoteServer.query(
ProjectsByOwner,
({ input, window, principal }) => projectsPage({ ownerId: input.ownerId, window, principal }),
)
const QueryServer = RemoteServer.make({
entities: [ProjectSource],
queries: [ProjectsByOwnerSource],
})A Query returns:
{
edges,
start,
end,
}A Source answers membership only; it may ignore select. The handlers fetch
the selected fields through the entity sources (authorization included) and
return them as entities/settled beside the page. Query membership and
entity data stay separate on the way in and travel together on the way out.
start and end are Remote Boundary values (Terminal, Cursor, or
Unknown). The client uses those explicit boundaries when merging pages instead
of guessing from row count.
Query input is decoded through the Query's own Schema before your callback runs.
The callback receives the decoded input, the requested QueryWindow, the
select slice when the client sent one, the principal, and the server's
viewer of it.
A query declared with Query.define carries its meaning as a value, so it
needs no hand-written Source: RemoteServer.memory runs its body with
evaluate, and foldkit-remote-drizzle compiles it to SQL (see Reference
semantics).