graphql-modules: Cannot read properties of undefined (reading 'getModuleContext') when using @ExecutionContext()
When using @ExecutionContext() in a provider I get the error:
TypeError: Cannot read properties of undefined (reading 'getModuleContext')
at Object.getModuleContext (/Users/alexander/graphql-modules/node_modules/graphql-modules/index.js:221:23)
at ReflectiveInjector.moduleExecutionContextGetter [as _executionContextGetter] (/Users/alexander/graphql-modules/node_modules/graphql-modules/index.js:945:41)
at MyProvider.get (/Users/alexander/graphql-modules/node_modules/graphql-modules/index.js:660:41)
at MyProvider.<anonymous> (/Users/alexander/graphql-modules/src/module.ts:9:22)
at Generator.next (<anonymous>)
at /Users/alexander/graphql-modules/src/module.ts:17:71
at new Promise (<anonymous>)
at __awaiter (/Users/alexander/graphql-modules/src/module.ts:13:12)
at MyProvider.create (/Users/alexander/graphql-modules/src/module.ts:25:16)
at hello (/Users/alexander/graphql-modules/src/module.ts:27:30),
[Symbol(async_id_symbol)]: 75,
[Symbol(trigger_async_id_symbol)]: 74
To Reproduce Steps to reproduce the behavior:
Check out the codesandbox to see the error: https://codesandbox.io/s/graphql-modules-jxwdrv?file=/src/module.ts
- open a terminal
- run
npm start - open https://…io/graphql
- run query
{ hello }
Expected behavior
Context should be available in provider.
Environment:
graphql-modules: 2.1.0- NodeJS: 18.7.0
Additional context
To me the problem seems to be that async_hooks.executionAsyncId() returns a different id in executionContext.getModuleContext than in executionContext.create.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 3
- Comments: 20 (6 by maintainers)
Fixed in
graphql-modules@2.2.1with #2461. Please try it out!@darkbasic rebased. New alpha versions will be available soon.
I confirm 2.3.0 fixes the issue, thanks! I’ve rebased the 3.0 PR on top of your work, can you please force push from
darkbasic:apollo-v4intoapollo-v4so that new 3.0 alpha packages get created?hey @darkbasic, I am currently debugging this. I did what you said here, but I also updated the
graphql-modulesin graphql-server-typescript to 2.2.0 (latest stable release). Doing so, I got a different runtime error (in addition to a bunch of type errors I ignored) when trying to run the server:Any chance you can try the latest stable 2.2.0 of
graphql-modulesyourself? The latest works in the repro here. Looking forward to your reply, thanks!Same here, it works in some cases and doesn’t in other, for some reason
executionContextStoreis empty which is causing that errorHas anyone figured it out yet ?