Skip to content
Discussion options

You must be logged in to vote

Declare the relation in the schema and select it in the GQL body — you never hand-write $lookup or a JOIN.

store.register({
  name: 'Order', collection: 'orders',
  fields: { code: { type: 'string' } },
  relations: {
    items: { model: 'OrderItem', type: 'many', localField: '_id', foreignField: 'orderId' },
  },
});

const rows = await store.query(
  'Order($condition:@c0,$limit:@l) { code, items($sort:@s1,$limit:@l2) { sku, qty } }',
  { c0: { status: 'paid' }, l: 50, s1: { qty: -1 }, l2: 5 },
);

Relations compile to $lookup / $addFields on MongoDB, and to a JOIN when the backend is relational. You build the tree once and the engine resolves it as part of one plan.

Two limits worth kno…

Replies: 1 comment

Comment options

coenddt
Sep 14, 2026
Maintainer Author

You must be logged in to vote
0 replies
Answer selected by coenddt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant