Open eirikur-nc opened 1 week ago
Thanks for creating the issue. Could you please create a reproduction on CodeSandbox so we can also debug and help you better with it?
Thanks for creating the issue. Could you please create a reproduction on CodeSandbox so we can also debug and help you better with it?
Sure: https://codesandbox.io/p/devbox/q5w2zq I've updated the description with a link
A PR with a fix is ready for review #6660
Issue workflow progress
Progress of the issue based on the Contributor Workflow
Describe the bug
graphql-codegen fails after having added "type": "module" to all packages in a monorepo
To Reproduce:
https://codesandbox.io/p/devbox/q5w2zq
Expected behavior
Being able to author custom data loaders in ESM format
Environment:
@graphql-tools/load
: 8.0.0Additional context
I'm working in a monorepo that uses graphql-codegen to generate type information from our GraphQL schema (which has served us well, thanks!) Due to issues with having a mixture of CommonJS and ESM packages in the repo, we decided to switch entirely over to ESM. We added
"type": "module"
to all our package.json files. We modified our scripts to rungraphql-codegen-esm
We have a config file in yml format that specifies custom loaders for two schemas. ExampleThose failed to load properly. I converted them from CommonJS to ESM format and changed their file extensions to *.mjs but that did not suffice.
I found this SO question which got me on the right track https://stackoverflow.com/questions/75253732/codegen-config-cant-load-custom-schema-loader
In packages/load/src/utils/custom-loader.ts there's a function named
getCustomLoaderByPath
which usescreateRequire
which cannot be used to load ES modules. I've managed to work around this issue by patching the package to use a dynamicimport
instead. The purpose of this issue is to get that change applied upstream to the benefit of others. I will follow up with a PR.