Build a session view in one request
A session page needs four things: the session, its first turns, the machines and files they came from, and any attached artifacts. Over REST that is four calls. In GraphQL it is one.
actor app: Your app actor gql: Tracez GraphQL actor ops: Tracez operations app -> gql: POST /graphql (4 aliased fields) note gql: parse, bound to 500 nodes gql -> ops: readSession gql -> ops: readTurns gql -> ops: readSources gql -> ops: listArtifacts ops --> gql: four Reply objects gql --> app: one JSON response
Steps
-
Write the query
Aliases let you call several operations in one document. Every field takes a single
inputand returns aReply.query SessionView($id: String!) { session: readSession(input: { session_id: $id }) { http_status data error { code message } } turns: readTurns(input: { session_id: $id }) { data error { code } } sources: readSources(input: { session_id: $id }) { data } artifacts: listArtifacts(input: { session: $id }) { data } } -
Send it
curl https://tracez.recurz.ai/graphql \ -H "Authorization: Bearer $RECURZ_TOKEN" \ -H "Content-Type: application/json" \ -d '{"query":"…","variables":{"id":"SESSION_ID"}}' -
Handle each field on its own
A field that fails carries its own
errorand the rest still return data, so one missing artifact doesn't blank the page.dataholds the same JSON the REST call returns, field names included.{"data":{ "session": {"http_status":200,"data":{"session":{…}},"error":null}, "turns": {"data":{"items":[…],"has_more":true,"next_after":"1873"},"error":null}, … }} -
Load more turns
When the reader scrolls, ask for
readTurns(input: { session_id: $id, after: "1873" })with the lastnext_after.
data is a JSON scalar today, so you select the envelope, not individual session fields. Queries are capped at 32 KB and 500 nodes.