Selection and Responses
The single most important thing to understand about the data client: you do not choose fields. You get all of them.
foir.cost_breakdown.findMany({ first: 1 }) is four words that return a payload you cannot picture from the snippet, because the response is determined by your schema rather than by your call. So this page shows what comes back, alongside the document that asked for it.
Complete by default
Every operation selects every scalar on the model. There is no select.
That is a deliberate trade, and it buys one specific thing: the model type is unconditionally true. No field can be typed present and arrive undefined, which is the footgun every partial-selection client carries. Your CostBreakdown type is your record.
query CostBreakdownFindUnique($id: String) {
costBreakdown(id: $id) {
_createdAt _hasDraft _id _modelKey _naturalKey _ownerId _ownerKind
_resolvedBy _segments _updatedAt _variant
baseColor
collab { enabled roomName wsUrl }
currencySymbol heading quantity salesPrice subline
sections { cost label }
}
}const cost = await foir.cost_breakdown.findUnique({ id: 'kx41m0e8kbmy4ftbjyh0svqe' });
cost.heading; // string | null — always present
cost.salesPrice; // number | null — always present{
"_createdAt": "2026-05-19T09:14:22.104831Z",
"_hasDraft": null,
"_id": "kx41m0e8kbmy4ftbjyh0svqe",
"_modelKey": "cost_breakdown",
"_naturalKey": "jacket-cost",
"_ownerId": null,
"_ownerKind": null,
"_resolvedBy": null,
"_segments": null,
"_updatedAt": "2026-05-19T09:31:07.552019Z",
"_variant": null,
"baseColor": "#1d1d1f",
"collab": {
"enabled": true,
"roomName": "cost_breakdown:kx41m0e8kbmy4ftbjyh0svqe:default",
"wsUrl": "wss://realtime.foir.io"
},
"currencySymbol": "£",
"heading": "What it costs",
"quantity": 1,
"salesPrice": 495,
"subline": "Made in England, priced in the open.",
"sections": [
{ "cost": 182, "label": "Materials" },
{ "cost": 96, "label": "Cut and make" }
]
}Three things worth noticing, because none of them is guessable from the call:
- Nulls are sent, not omitted. Every field the document names comes back,
nullincluded. That is what makes the type unconditionally true. - Composite fields arrive whole and uninvited.
collabis an object with three keys and noincludeasked for it;sectionsis a list of composites. Composites are scalars as far as selection is concerned. includewas never used, because relations are the only thing it governs.
Complete as of your last generation
Complete-by-default is resolved when you run foir types, not on each request. A field added to the model upstream is absent from this document until you regenerate and redeploy — it is not merely untyped, it is not asked for.
That cuts both ways, and mostly in your favour: a payload cannot grow because somebody else shipped a field, and the selection your build sends is one you can read in a diff. It does mean a schema change reaches your app on your schedule rather than theirs. The overview has the rest of that, and schema drift is how you find out you are behind.
omit — the release valve
omit takes field keys and removes them from both the document and the type.
query CostBreakdownFindUnique($id: String) {
costBreakdown(id: $id) {
_createdAt _hasDraft _id _modelKey _naturalKey _ownerId _ownerKind
_resolvedBy _segments _updatedAt _variant
baseColor currencySymbol heading quantity salesPrice subline
}
}const cost = await foir.cost_breakdown.findUnique({
id: 'kx41m0e8kbmy4ftbjyh0svqe',
omit: ['collab', 'sections'],
});{
"_createdAt": "2026-05-19T09:14:22.104831Z",
"_hasDraft": null,
"_id": "kx41m0e8kbmy4ftbjyh0svqe",
"_modelKey": "cost_breakdown",
"_naturalKey": "jacket-cost",
"_ownerId": null,
"_ownerKind": null,
"_resolvedBy": null,
"_segments": null,
"_updatedAt": "2026-05-19T09:31:07.552019Z",
"_variant": null,
"baseColor": "#1d1d1f",
"currencySymbol": "£",
"heading": "What it costs",
"quantity": 1,
"salesPrice": 495,
"subline": "Made in England, priced in the open."
}omit is typed as Omit<T, K>, so the removed fields are gone from the result type too — reading cost.collab after omitting it is a compile error, not an undefined at runtime.
_id cannot be omitted
await foir.cost_breakdown.findMany({ first: 1, omit: ['_id'] });
// ~~~~~
// Type '"_id"' is not assignable to type …The type excludes it because the client refuses it, so this is a compile error rather than a failed request. Reached another way, the message is:
[foir] omit "_id": "_id" is required for correctness and cannot be removedomit only knows about fields that existed when you generated
An omit list cannot name a field that did not exist when you wrote it. Under build-time selection that is a smaller problem than it used to be — a new field is not in your document at all until you regenerate — but it is still the shape to watch: the moment you re-run foir types, a field added upstream joins every call that narrows with omit, and nothing at the call site says so.
That is fine when you keep most of a model and drop a few known-heavy fields, which is what omit is for. It is the wrong shape when you want four fields out of sixty. For that, use pick.
pick — name what you keep
pick is omit inverted, and closed: you name what you want, and a field added later cannot enter the response because you never named it.
query CostBreakdownFindUnique($id: String) {
costBreakdown(id: $id) { _id heading salesPrice }
}const cost = await foir.cost_breakdown.findUnique({
id: 'kx41m0e8kbmy4ftbjyh0svqe',
pick: ['heading', 'salesPrice'],
});
// ^? { _id: string; heading: string | null; salesPrice: number | null } | null{ "_id": "kx41m0e8kbmy4ftbjyh0svqe", "heading": "What it costs", "salesPrice": 495 }Use pick when you want a few fields of a wide model, and omit when you want most of a model minus a few. A pick request and the same selection written by hand produce byte-identical responses, because they are the same document.
_id always comes back
pick returns what you named plus _id, as the response above shows. It is the record’s identity, and without it you could not address the row you just read.
Naming _id yourself is allowed and changes nothing. That is the opposite of omit, where naming _id is a compile error — the asymmetry is deliberate: under omit you would be asking to remove it, which is refused; under pick you are simply not mentioning it.
pick and omit cannot be combined
await foir.cost_breakdown.findMany({ pick: ['heading'], omit: ['subline'] });
// ~~~~
// Type error — and at runtime:
// [foir] cost_breakdown.findMany: "omit" and "pick" are mutually exclusive — pass one or the otherA field named in neither list has no defined outcome — “everything except subline” and “only heading” disagree about it. Pick one verb per call.
Narrowing inside a composite
The array form names top-level keys. To reach inside a composite, both verbs also take a nested object:
query CostBreakdownFindUnique($id: String) {
costBreakdown(id: $id) { _id collab { roomName } heading }
}await foir.cost_breakdown.findUnique({
id: 'kx41m0e8kbmy4ftbjyh0svqe',
pick: { heading: true, collab: { pick: { roomName: true } } },
});A key set to true means the whole field; repeating the verb narrows inside it. That is the same shape include already uses — include: { author: { include: { tags: true } } } — so a call that does both reads as one idiom rather than two.
omit nests the same way, which is the usual way to drop one encoding of a prose field without losing the other two:
await foir.cost_breakdown.findMany({ first: 5, omit: { collab: { omit: { wsUrl: true } } } });It nests three levels, capped for the same reason include is: composites reference each other, and an uncapped recursive type over that is an immediate “type instantiation is excessively deep”.
await foir.page.findUnique({
naturalKey: 'home',
pick: { pageContent: { pick: { seo: { pick: { metaTitle: true } } } } },
});A list of composites narrows the same way, and the selection applies to each element:
await foir.page.findUnique({
naturalKey: 'home',
pick: { pageContent: { pick: { sections: { pick: { anchor: true } } } } },
});A polymorphic field takes
on, not the verb.pick/omitdescend into one shape; a union is several, so it is narrowed per member instead — see Polymorphic fields below.
The dotted string form is top-level keys only.
pick: ['title', 'pageContent']is a list of the model’s own field names;pick: ['pageContent.seo']does not compile. Nesting is the object form above, which reaches everything a dotted path would and gives you autocomplete at each level.
Polymorphic fields
A prose field’s entries is a union: at each position the value is one of several member types — Passage, or one of the models the field admits — and which one is carried on __typename.
By default the client selects every member, so a union arrives whole — on below is how you ask for fewer. This is the blocks part of an ordinary complete read, with the rest of the page elided:
query PageFindUnique($naturalKey: String) {
page(naturalKey: $naturalKey) {
_id
pageContent {
sections {
blocks {
__typename
... on CostBreakdownBlock {
_id
baseColor
collab { enabled roomName wsUrl }
currencySymbol
costBreakdownBlockHeading: heading
quantity salesPrice subline
sections { cost label }
}
... on CtaBlock { _id href label openInNewTab variant }
... on DividerBlock { _id color dividerBlockWidth: width }
# one more fragment per remaining member of the union
}
}
}
}
}const page = await foir.page.findUnique({ naturalKey: 'home' });The matching part of the response, elided the same way — the record also carries every scalar on page and the rest of pageContent:
{
"_id": "y5nwq2rk8vd1t0jc6phaz3xe",
"pageContent": {
"sections": [
{
"blocks": [
{
"__typename": "CtaBlock",
"_id": "b7t0kq2mvxa9",
"href": "/checkout",
"label": "Buy the jacket",
"openInNewTab": null,
"variant": "SOLID"
},
{
"__typename": "CostBreakdownBlock",
"_id": "kx41m0e8kbmy",
"baseColor": "#1d1d1f",
"collab": {
"enabled": true,
"roomName": "cost_breakdown:kx41m0e8kbmy:default",
"wsUrl": "wss://realtime.foir.io"
},
"currencySymbol": "£",
"costBreakdownBlockHeading": "What it costs",
"quantity": 1,
"salesPrice": 495,
"subline": "Made in England, priced in the open.",
"sections": [{ "cost": 182, "label": "Materials" }]
}
]
}
]
}
}Some keys are renamed, and the name is the contract
Look at costBreakdownBlockHeading in that response. On the model, the field is heading. Inside this union it arrives under a different key, and your generated types say so.
The reason is a rule in GraphQL itself: response keys are compared across mutually exclusive members, so two members of one union that declare the same field name at incompatible shapes cannot both be selected under that name. Inline fragments do not avoid it — the collision is on the key. In this project ChildrenListBlock.heading is rich text and CostBreakdownBlock.heading is a string, and a selection that asks for every member asks for both.
So the union’s key vocabulary is resolved once, published in the manifest, and generated into your types in the same run. The scheme is the member’s own type name in camel case, followed by the field name:
export type BlockCostBreakdownBlock = Omit<CostBreakdownBlock, 'heading'> & {
costBreakdownBlockHeading: CostBreakdownBlock['heading'];
};Three consequences worth having in mind:
CostBreakdownBlockstill names the shape outside the union. Read the same record throughfoir.cost_breakdown.findUnique(…)and the field isheading, as at the top of this page. The rename is a property of the position, not of the model.- The rename is stable while the union is. It is derived from the member’s type name, so it changes only when the member does, and it changes in the manifest first — which is the artifact your types are generated from. Your types and the response cannot disagree about it.
- A rename can appear for a member you never look at.
headingonCostBreakdownBlockis renamed because a different member of the same union also declaresheading. Adding one block type to a project can rename a key on another, and the signal is the diff on your nextfoir types. This is a good reason to commit the generated file.
Switching on a block
Your generated union is discriminated on __typename, so a switch narrows to the exact member type with no casts:
for (const block of section.blocks ?? []) {
switch (block?.__typename) {
case 'CostBreakdownBlock':
render(block.costBreakdownBlockHeading, block.salesPrice);
break;
case 'CtaBlock':
render(block.label, block.href);
break;
}
}Narrowing on __typename is what makes a field name that several members declare read at its own type on each branch. It is also why __typename is selected unconditionally and cannot be narrowed away.
on — selecting per member
By default a union arrives whole, which on a page-shaped model is usually the largest thing in the response. When it matters, name the members you want under on:
const page = await foir.page.findUnique({
naturalKey: 'home',
pick: {
pageContent: {
pick: {
sections: {
pick: {
blocks: {
on: {
CostBreakdownBlock: ['costBreakdownBlockHeading'],
ImageBlock: true,
},
},
},
},
},
},
},
});That compiles to inline fragments for exactly those two members:
blocks {
__typename
... on CostBreakdownBlock { costBreakdownBlockHeading: heading }
... on ImageBlock { … }
}The keys of the on map are the union’s member type names, and the values are that member’s own response keys — renamed ones included, under the name the server sends. Both come from your generated types, so both autocomplete and neither can name something the response will not carry.
Three things worth knowing:
truekeeps the whole member.ImageBlock: trueabove is every field of that member, which is usually what you want for the one or two block types a given route renders.- A member you do not name still arrives, as
{ __typename }. The element is there — the server sends one value per position regardless — it just carries nothing but its discriminant. Your types say exactly that, so reading a field off an unselected branch is a compile error rather than a runtimeundefined. omitmirrors it. Swap both keywords —omit: { pageContent: { omit: { sections: { omit: { blocks: { on: { ImageBlock: true } } } } } } }— and the named member is the one that loses its fields, while every other member stays intact.
__typename is never narrowed away, so the switch above keeps working under any on selection.
depth — blocks inside blocks
Blocks nest. A section-shaped member declares its own blocks field of the very union it belongs to, and an author puts a product hero, reviews and an accordion inside a section. That is ordinary content, not a schema accident — and it is where complete-by-default has to stop expanding, because a union that contains itself has no complete document.
The default document expands each union once. At the position where a union reappears inside one of its own members, a nested block arrives carrying nothing but its discriminant:
{
"__typename": "SectionBlock",
"blocks": [
{ "__typename": "CostBreakdownBlock" },
{ "__typename": "CtaBlock" }
]
}Read that response carefully: the elements are there, one per authored block, typed and discriminated. The record has the content. It is the query that stopped one level short, and { "__typename": … } with no other keys is exactly what that looks like.
depth buys levels back:
const page = await foir.page.findUnique({ naturalKey: 'home', depth: 2 });... on SectionBlock {
_id
blocks {
__typename
... on CostBreakdownBlock { _id baseColor salesPrice … }
... on CtaBlock { _id href label openInNewTab variant }
}
}Each level past the default (depth: 1) expands one more nested ring, and the blocks at the last ring arrive as bare { __typename } again — the same signal, one level further down.
Four things worth knowing:
-
The type widens with the literal. Your generated module carries the deeper shape per level, so
depth: 2written as a literal at the call site reads nested members at their full member types — no casts. A depth past what your generation emitted, or adepththat is not a literal, still returns the values; the type just falls back to the default shape and you narrow by hand. Under-promising is the safe direction, and it is why neither case is an error. -
Depth is a budget, and it is priced before it is sent. Measured on a real project’s product page, the complete document runs 318 fields at the default, 468 at
depth: 2and 618 atdepth: 3— against a server ceiling of 10,000. What a level costs is one more expansion of one member at each stopping point, so the growth is additive in the number of levels rather than multiplied by how many block types your project declares. The client still prices the document before sending it and refuses an over-budget one client-side, with the projected count in the message, because “selects 20,204 fields” tells you whether oneomitwill do where the server’squery complexity exceeds maximumdoes not. -
What still costs, and what stopped costing. Depth costs, and it compounds where an expansion contains several union-typed fields, because every level re-expands every one of them. The number of members in the union does not cost — a field that admits 56 models is priced the same as one that admits 3. So
onis worth reaching for when you want a smaller response or a more readable document, not to buy budget. AndallowedTypeson a prose field (inline schemas) is an editorial decision — what an editor may place there — with no bearing on what your queries can afford. It was worth reaching for on cost grounds once; it is not any more. -
The record editor shows you the shape before you write the call. The preview pane discovers how deep the open record actually nests and runs the query at exactly that depth. When that is more than one level, the SDK snippet beside it spells
depth: N.
include — relations, and only relations
Relations are not in the model type. They appear on the result only when you ask:
includedoes not reach an image field. An image is a value on the record, not a related record, so it is expanded whole on any read that selects it and there is nothing forincludeto ask for.omitis the lever on a read that does not render it.
const block = await foir.tilly_block.findUnique({
id: 'a3pr8x0j10rigx8u6t1xthbr',
include: { noteId: true },
});
block.noteId; // TillyNote | null — present because it was includedThe result type is an intersection — TillyBlock & { noteId: TillyNote | null } — so hovering it still names your generated interface rather than a wide anonymous object.
Nesting works to three levels, capped deliberately: relations are routinely self-referential, and an uncapped recursive type over that is an immediate “type instantiation is excessively deep”.
include: { parentBlockId: { include: { noteId: true } } }Pass true, never false — include keys are validated strictly and a false is still a key. Build a conditional include by spreading it instead:
include: { ...(withAuthor && { author: true }) }An included relation brings back every scalar on the related model, because complete-by-default applies through relations too. If a non-nullable field on the related type resolves null, GraphQL nulls the whole relation and returns an error beside the data — see partial results.
A relation’s own selection is never narrowed by the caller’s pick or omit: those address the root model’s field paths. Reach further with a document of your own.
findMany returns a connection
Not a flattened array, on purpose: hiding pageInfo behind a convenience array would make pagination unreachable.
query CostBreakdownFindMany($first: Int) {
costBreakdowns(first: $first) {
edges { cursor node { _id heading salesPrice } }
pageInfo { endCursor hasNextPage hasPreviousPage startCursor }
totalCount
}
}const page = await foir.cost_breakdown.findMany({ first: 2, pick: ['heading', 'salesPrice'] });
page.totalCount; // 7
page.pageInfo.hasNextPage; // true
page.edges[0].node.heading; // the record
page.edges[0].cursor; // opaque, feed it back as `after`{
"edges": [
{
"cursor": "eyJ2IjoxLCJvIjpbIjIwMjYtMDUtMTlUMDk6MTQ6MjIuMTA0ODMxWiIsImt4NDFtMGU4a2JteSJdfQ",
"node": { "_id": "kx41m0e8kbmy4ftbjyh0svqe", "heading": "What it costs", "salesPrice": 495 }
},
{
"cursor": "eyJ2IjoxLCJvIjpbIjIwMjYtMDUtMjBUMTQ6MDI6MDEuNzcxMjAyWiIsInE4dzJmM2p6MHZobiJdfQ",
"node": { "_id": "q8w2f3jz0vhn5rkp1yatcedu", "heading": "What the bag costs", "salesPrice": 240 }
}
],
"pageInfo": {
"endCursor": "eyJ2IjoxLCJvIjpbIjIwMjYtMDUtMjBUMTQ6MDI6MDEuNzcxMjAyWiIsInE4dzJmM2p6MHZobiJdfQ",
"hasNextPage": true,
"hasPreviousPage": false,
"startCursor": "eyJ2IjoxLCJvIjpbIjIwMjYtMDUtMTlUMDk6MTQ6MjIuMTA0ODMxWiIsImt4NDFtMGU4a2JteSJdfQ"
},
"totalCount": 7
}pick and omit address the record, never the connection: omit: ['collab'] means “no collab on each node”, and pageInfo and totalCount are untouched by either.