Skip to content

Commit 03118e8

Browse files
authored
Supply GraphQL Context to loader.
Same as PR krislefeber#11
1 parent df8fa93 commit 03118e8

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ import { idText } from 'typescript';
1717
* The concrete implementation should be added as a provider to your module.
1818
*/
1919
export interface NestDataLoader<ID, Type> {
20+
/**
21+
* Should return a new instance of dataloader each time
22+
* @params ctx: the graphql execution context
23+
*/
24+
generateDataLoader(ctx: any): DataLoader<ID, Type>;
2025
/**
2126
* Should return a new instance of dataloader each time
2227
*/
@@ -51,7 +56,7 @@ export class DataLoaderInterceptor implements NestInterceptor {
5156
try {
5257
ctx[type] = (async () => {
5358
return (await this.moduleRef.resolve<NestDataLoader<any, any>>(type, ctx[NEST_LOADER_CONTEXT_KEY].contextId, { strict: false }))
54-
.generateDataLoader();
59+
.generateDataLoader(ctx);
5560
})();
5661
} catch (e) {
5762
throw new InternalServerErrorException(`The loader ${type} is not provided` + e);

0 commit comments

Comments
 (0)