Splits the annotated field’s resolution out of the surrounding parent SELECT into a separate, batched query. The rewrite emits a DataLoader-backed fetcher: per request, sibling parents' keys are gathered, one batched SELECT runs against the child table with a VALUES-keyed join, and rows scatter back to their original parent positions.
|
Names from inside the generator. This page names types from graphitron’s own classification model. They are accurate today, and worth knowing when a rejection message quotes one back at you, but they are not part of the authoring contract: the classification walk that produces them is being drained, and these names retire with it. What stays stable is the schema you write, the directive reference that describes it, and the diagnostics glossary. |
@splitQuery is the directive that decouples query depth from query breadth. Without it, child references inline into the parent SELECT (one round-trip, joined SQL). With it, each @splitQuery boundary becomes a deferred DataLoader call (more round-trips, narrower SQL, batched across parents). It composes with @reference and @lookupKey. A child connection (@asConnection, or a hand-written connection return type) is always split, so the directive is inferred there and not written.
SDL signature
directive @splitQuery on FIELD_DEFINITION
The directive takes no arguments. The cardinality (single vs list), the FK direction (parent-holds-FK vs child-holds-FK), and the path’s hop count are all read from the surrounding @reference / catalog inference; the rewrite picks the appropriate DataLoader shape from those signals.
Canonical examples
List child, child-holds-FK (@splitQuery keyed on parent’s PK). The DataLoader’s batch is parent_id IN (…), distributing rows to parents by FK:
type Language @table(name: "language") {
films: [Film!]! @splitQuery @reference(path: [{key: "film_language_id_fkey"}])
}
Single-cardinality, parent-holds-FK (@splitQuery keyed on parent’s FK column). At least one parent may carry NULL in the FK; the rewrite short-circuits those to null without dispatching to the DataLoader:
type Customer @table(name: "customer") {
addressSplit: Address @splitQuery @reference(path: [{key: "customer_address_id_fkey"}])
}
type Store @table(name: "store") {
manager: Staff @splitQuery @reference(path: [{key: "store_manager_staff_id_fkey"}])
}
Store.manager traverses a nullable FK; the §4 null-FK short-circuit returns null without a round-trip when the column is NULL. The @reference is required even though Customer.address_id would auto-infer, because store and staff have two FKs between them and inference would be ambiguous.
Multi-hop list with @lookupKey (a Table-sourced BatchedTableField carrying the keyed lookup resolution: flat SELECT + VALUES+ON keyset + per-parent scatter):
type Film @table(name: "film") {
actorsBySplitLookup(actor_id: [Int!] @lookupKey): [Actor!]! @splitQuery @reference(path: [
{key: "film_actor_film_id_fkey"},
{key: "film_actor_actor_id_fkey"}
])
}
Self-referencing FK (split is available for fan-out reduction; not structurally required, since each inline level names its tables one nesting level below its parent’s):
type Film @table(name: "film") {
sequel: Film @splitQuery @reference(path: [{key: "FILM__SEQUEL_FKEY"}])
}
A child connection takes the split without the directive (per-parent paginated child connection: a ROW_NUMBER() OVER (PARTITION BY parentInput.idx) envelope gives each parent its own slice). Writing @splitQuery on it is redundant:
type Film @table(name: "film") {
actorsConnection(first: Int, after: String): ActorsConnection!
@reference(path: [
{key: "film_actor_film_id_fkey"},
{key: "film_actor_actor_id_fkey"}
])
@defaultOrder(primaryKey: true)
}
Constraints
-
Single-cardinality
@splitQueryis restricted to a single-hop@referencepath. Multi-hop single-cardinality is rejected at build time with the offending path’s hop count in the message. -
List-cardinality
@splitQuerysupports any hop count, including junction-table chains (@reference(path: […, …])). -
Implicit on a child connection, a list field under a non-root type made a connection by
@asConnectionor by returning a hand-written connection type: it is always fetched in a query of its own, batched across parents, each parent paging its own rows. Explicit@splitQuerythere is redundant: the build warnsSPLIT_QUERY_REDUNDANTat the directive and ignores it. -
Implicit on
@table-typed fields of a class-backed parent reachable from@service, and on a payload’s data field, which re-reads its producer’s records by their keys after a write, a routine or a service: these fields start their own query whatever is written on them. Explicit@splitQuerythere is redundant but not rejected (Alf, 2026-11-19): the build warnsSPLIT_QUERY_REDUNDANTat the directive and ignores it. Remove the directive, or listSPLIT_QUERY_REDUNDANTunder<lint><disabledRules>to keep it. -
Rejected at build time (
[deferred]) on a field whose return type is a plain-object nesting type (a directiveless object projected off the parent’s own table row). The batched launcher the split implies is not generated, and accepting the directive would silently ignore it. This is the line between the positionally inert cases on this page: where the fetch is already separate (root fields, argument-bearing fields, class-backed parents) the directive is redundant and at most warned about; where honoring it would require a delivery that does not exist (a nesting field) it is unimplemented and rejected. Remove the directive to keep the inline projection;@splitQueryon table-backed fields inside the nesting type, and on@pivotfields, is supported as usual. -
Rejected at build time on a field whose return type is bound to the same table as its parent and which has no
@reference. A split fetch is a batch keyed on each parent’s correlation to the child, and a same-table field with no path has no such correlation, so there is no parent key to batch on. (@tenantFanOut, which forces the same batched fetch, is rejected on this shape for the same reason.) Pick the remedy by what the field means:-
To return the parent’s own row, name the table’s primary key with
@reference(path: [{key: …}]), which gives the batch the parent’s key to batch on. See Map types to tables. -
Otherwise state the correlation with
@reference(path: [{condition: …}]), a condition method equating the two tables' keys.
-
-
Redundant but not rejected on a field returning a
@table+@discriminateinterface (a single-table discriminated interface). This sits on the redundant and at most warned about side of the line the nesting bullet above draws, and for the stronger of the two reasons: the discriminated re-projection is always its own statement, so the directive’s own meaning (stop projecting this child into its parent’s SELECT) is satisfied before it is applied, and the delivery an author reaching for it actually wants is already the default. List and connection cardinality batch the re-projection through a DataLoader on their own, one statement for the whole batch of parents (the connection form windows that statement into per-parent pages); single cardinality fetches per parent, which no directive changes. Writing@splitQueryhere yields a lint warning (splitquery-redundant-on-discriminated-interface-child) offering to delete it, and the directive is ignored. -
Self-referencing FKs work inline in the rewrite. Each inline level names the tables it reads by a short name that carries its nesting depth, one deeper than its parent’s, so a recursive subselect never shadows the row it is correlated to;
Category.parentandCategory.childrenin the example schema cover this end-to-end.@splitQueryis available on self-FKs for the same fan-out-reduction reasons as any other reference, but is not required. -
Without
@splitQuery, one statement nests at most 32 levels of correlated reads (TableAliases.MAX_DEPTHin the generatedutilpackage). A query that nests an inline field deeper, typically by following an inline cycle such asCategory.parentor a pair of types referencing each other, is refused with a client error before any SQL runs, whether or not the application installs a query-depth limit of its own. Each@splitQueryboundary starts a new statement, and so a new count. -
Redundant but not rejected beside
@serviceon a non-root field. A child service is always called once per batch of parents, so the split the directive asks for is already the delivery. Writing@splitQuerythere yields a lint warning (splitquery-redundant-on-service-child) offering to delete it, and the directive is ignored. -
Rejected at build time (
FIELD_WITHOUT_FETCHER) on a field returning a union or interface none of whose implementers is@table-bound (an interface’s own@tablenot counting): the split fetches each table-bound participant’s rows, so there is nothing to fetch. -
Composes with
@lookupKey: the lookup key narrows the per-parent batch (each parent’s child list filtered by the caller-provided keys). -
On root (
Query/Mutation) fields and on fields with arguments,@splitQueryis irrelevant; those always have explicit data fetchers. The directive is silently ignored there. -
Nullable FKs on parent-holds-FK single-cardinality fields short-circuit to
nullbefore dispatching to the DataLoader (saves a round-trip when no parents have a non-null FK value). -
Does not change whether a nullable single object resolves to
null: a split field answers exactly as its inline form, within the same batched statement, and a split field inside an object counts toward that object by its value. See When a single object resolves tonull.
See also
-
@referencesupplies the FK chain;@splitQuerydecides whether to inline or batch it. -
@asConnectionon a child list adds per-parent Relay pagination; the split under it is inferred. -
@lookupKeynarrows the per-parent batch to caller-provided keys. -
Class-backed parents reachable from
@serviceget implicit@splitQueryon@table-typed children. -
How-to: When to split queries covers the round-trip-vs-fan-out trade-off, self-FK rules, and DataLoader caching behaviour.
-
LSP inlay hints and classification hover marks the separately fetched fields in the editor, for every reason a split happens, so a type’s round-trip cost can be read off the schema.