graphql-tools
graphql-tools copied to clipboard
Support custom loaders in ESM format
Description
Use a dynamic import when loading custom loaders in order to support loaders in ESM format.
Retain the original implementation, which relies on createRequire, for the synchronous version useCustomLoaderSync
Related #6656
Type of change
- [x] Bug fix (non-breaking change which fixes an issue)
How Has This Been Tested?
I could not reproduce the issue using Jest, as it transpiles esm to commonjs.
To keep transpilation to a minimum, I added a test that can be run using the Node.js test runner with type-stripping enabled (requires version 22.6 or later). I also added a convenience script to the root package.json file so that the test can be run using yarn test:node
I realize that having to use two test runners is not ideal. I'm open to suggestions if there's a simpler way to demonstrate the effectiveness of this fix.
Checklist:
- [x] I have followed the CONTRIBUTING doc and the style guidelines of this project
- [x] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my feature works
- [x] New and existing unit tests and linter rules pass locally with my changes
- [ ] Any dependent changes have been merged and published in downstream modules