Skip to content

Commit b6c083c

Browse files
authored
Add option for dataLoader to enable batching on additionalResolver level (#8475)
* Add option for dataLoader to enable batching on additionalResolver level I would propose adding data loader options to enable batching on additionalResolver level (to the subgraphs). This would enable us to distribute large workloads to several load-balanced subgraphs. * docs: update website * feat: changeset * chore: apply suggestions * chore: review nitpicks
1 parent e7be82c commit b6c083c

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

.changeset/petite-mammals-visit.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@graphql-mesh/utils': minor
3+
---
4+
5+
Added data loader options, allowing to specify batching behaviour in additionalResolvers.
6+
Description available [here](https://the-guild.dev/graphql/mesh/docs/guides/extending-unified-schema)

packages/legacy/utils/src/in-context-sdk.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type DataLoader from 'dataloader';
12
import type {
23
ArgumentNode,
34
DocumentNode,
@@ -115,6 +116,7 @@ export function getInContextSDK(
115116
argsFromKeys,
116117
valuesFromResults,
117118
autoSelectionSetWithDepth,
119+
dataLoaderOptions,
118120
}: {
119121
root: any;
120122
args: any;
@@ -125,6 +127,7 @@ export function getInContextSDK(
125127
argsFromKeys?: (keys: string[]) => any;
126128
valuesFromResults?: (result: any, keys?: string[]) => any;
127129
autoSelectionSetWithDepth?: number;
130+
dataLoaderOptions?: DataLoader.Options<any, any, any>;
128131
}) => {
129132
inContextSdkLogger?.debug(`Called with`, {
130133
args,
@@ -198,6 +201,7 @@ export function getInContextSDK(
198201
key,
199202
argsFromKeys,
200203
valuesFromResults,
204+
dataLoaderOptions,
201205
} as unknown as BatchDelegateOptions;
202206
if (selectionSet) {
203207
const selectionSetFactory = normalizeSelectionSetParamOrFactory(selectionSet);

website/src/pages/docs/guides/extending-unified-schema.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ Any SDK method take the following arguments:
158158
`{ id name }`
159159
- `valuesFromResults`: allows to provide a function to transform the results (if the result is an
160160
array, the function will be mapped to each element)
161+
- `dataLoaderOptions`: allows you to define the batching behaviour as defined by
162+
[dataloader](https://github.com/graphql/dataloader/tree/main?tab=readme-ov-file#api). This allows
163+
e.g. to define that retrievals from the subgraph should be done in batches of n ids, which might
164+
help in load balancing resource-intensive queries.
161165

162166
<Callout>
163167
Note: `valuesFromResults`, compared to `selectionSet` helps to "flatten"/"un-nest" data from

0 commit comments

Comments
 (0)