From 37483848518e8dd31a3650e8333dc3b93a5edbea Mon Sep 17 00:00:00 2001 From: Dante Calderon Date: Thu, 19 May 2022 23:50:38 -0500 Subject: [PATCH] Validate that GraphQL context exist before injecting loader --- index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.ts b/index.ts index 5039c36..127cc2b 100644 --- a/index.ts +++ b/index.ts @@ -43,7 +43,7 @@ export class DataLoaderInterceptor implements NestInterceptor { const graphqlExecutionContext = GqlExecutionContext.create(context); const ctx = graphqlExecutionContext.getContext(); - if (ctx[NEST_LOADER_CONTEXT_KEY] === undefined) { + if (ctx && ctx[NEST_LOADER_CONTEXT_KEY] === undefined) { ctx[NEST_LOADER_CONTEXT_KEY] = { contextId: ContextIdFactory.create(), getLoader: (type: string) : Promise> => {