Commit 8d09aa1
committed
feat(execution): add experimental schema batch resolver
Add schema-level batch resolution so a GraphQLSchema can handle pending object
field batches across object types before object-level and field-level batch
resolvers run. This gives schema owners a single place to route batches to a
global loader or execution planner.
Schema-level API shape:
GraphQLSchemaConfig {
experimentalBatchResolve?: GraphQLSchemaBatchResolver<TContext>;
}
Relevant public types:
GraphQLSchemaBatchResolver<TContext>
GraphQLSchemaBatchInfo
GraphQLSchemaBatchResolveInfo
GraphQLObjectBatchFieldInfo
Example schema batch resolver:
const resolveSchemaBatch: GraphQLSchemaBatchResolver<Context> =
async (batches, context, info) => {
const result = new Map<
GraphQLObjectBatchFieldInfo,
ReadonlyArray<unknown>
>();
for (const batch of batches) {
if (batch.parentType.name !== 'User') {
continue;
}
const rows = await context.users.loadMany(
batch.sources.map((source) => source.id),
);
for (const field of batch.fields) {
if (field.fieldName === 'name') {
result.set(field, rows.map((row) => row.name));
} else if (field.fieldName === 'email') {
result.set(field, rows.map((row) => row.email));
}
}
}
return result;
};
const schema = new GraphQLSchema({
query: QueryType,
experimentalBatchResolve: resolveSchemaBatch,
});
Each GraphQLSchemaBatchInfo groups one parent object type, its sources, and the
field batches pending for those sources. The returned Map uses the field info
objects as keys and arrays of values in source order.1 parent c411341 commit 8d09aa1
12 files changed
Lines changed: 1216 additions & 7 deletions
File tree
- benchmark
- src
- execution/batchResolve
- __tests__
- type
- utilities
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
13 | 26 | | |
14 | 27 | | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
15 | 42 | | |
16 | 43 | | |
17 | 44 | | |
| |||
34 | 61 | | |
35 | 62 | | |
36 | 63 | | |
37 | | - | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
38 | 84 | | |
39 | 85 | | |
40 | 86 | | |
41 | 87 | | |
42 | | - | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
43 | 95 | | |
44 | 96 | | |
45 | | - | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
46 | 100 | | |
47 | 101 | | |
48 | | - | |
| 102 | + | |
49 | 103 | | |
50 | 104 | | |
51 | 105 | | |
| |||
0 commit comments