ardatan / graphql-tools

:wrench: Utility library for GraphQL to build, stitch and mock GraphQL schemas in the SDL-first approach
https://www.graphql-tools.com
MIT License
5.35k stars 818 forks source link

Support custom loaders in ESM format #6660

Open eirikur-nc opened 2 weeks ago

eirikur-nc commented 2 weeks ago

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

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:

changeset-bot[bot] commented 2 weeks ago

⚠️ No Changeset found

Latest commit: c4a1bf95d132192dd693f49d52e901c1464d80d4

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR