Bootstrap Endpoints
GraphQL (any backend)
GraphQL's response shape doesn't match what flux.bootstrap() expects out of the box — a query returns { data, errors } over a single POST endpoint, not { ok, data, assets }. This page covers the thin reshaping layer every GraphQL setup needs, and the one gotcha (errors-under-200) that breaks bootstrap silently if you skip it.
Prerequisites
- Any GraphQL server — Apollo Server, Hasura, GraphQL Yoga, a managed provider
- A thin server-side route (Next.js Route Handler, Express, etc.) to reshape the response — see Step 1
- For plain-REST backends with no GraphQL layer, see bootstrap/rest instead
- Familiarity with api/bootstrap on the client side
1
Why GraphQL needs its own page
A REST backend in any language can usually be shaped to return exactly Flux's
{ ok, data, assets } contract directly. GraphQL can't — the protocol's own response shape is fixed, and it reports failure differently than Flux expects.json
Never forward a raw GraphQL response to Flux
Every pattern below is a small server-side route that sits between your GraphQL endpoint and Flux, executing the query and reshaping the result. Flux's client never talks to your GraphQL endpoint directly.
2
Write one query, aliased to your map keys
Alias each top-level selection to match the exact key your client-side
map object expects. A single GraphQL query naturally covers what REST needs several endpoints for — a good fit for Flux's one-call bootstrap model.graphql
3
Node — reshaping via graphql-request
The route handler executes the query server-side and reshapes the result. Letting the client throw on a non-empty
errors array is what turns a partial GraphQL failure into a real 5xx.typescript
4
Managed GraphQL (Hasura, etc.) via plain fetch
No client library needed for a single server-to-server call — just check
errors explicitly, since res.ok being true tells you nothing about whether the query actually succeeded.typescript
5
Partial errors — pick fail-closed or fail-open, deliberately
GraphQL can return some fields successfully and null out others with an entry in
errors. Flux has no concept of a partial bootstrap — decide which behavior you want rather than letting it happen by accident.typescript
6
assets[] stays empty — orthogonal to GraphQL
Dynamic route chunk warming (Section 4.13) is a Next.js build-manifest mechanism, unrelated to whether your data layer is GraphQL or REST.
json
7
The Date header — usually fine, one thing to check
clockSkewMs correction depends on this header, and it comes from your reshaping route's response, not the upstream GraphQL server — this is normally correct by default.typescript
8
Extending to a 'user'-scope endpoint
Same reshaping pattern, with identity resolved from your own auth and passed as a query variable — never trust a client-supplied
userId.typescript
9
Status codes and how the client reacts
Identical to every other backend once your route has done its job — the GraphQL-specific work all happens upstream of this table, inside your reshaping route.
typescript
For plain-REST backends with no GraphQL layer, see bootstrap/rest. For Node-specific patterns including assets[] chunk warming, see bootstrap/node. For the client-side call this endpoint answers, see api/bootstrap.