-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ESM support #6102
ESM support #6102
Conversation
🦋 Changeset detectedLatest commit: 07d3a5b The changes in this PR will be included in the next version bump. This PR includes changesets to release 53 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
I found an issue in CLI, and it's the usage of "require.resolve", which is not supported in ESM https://github.com/dotansimha/graphql-code-generator/blob/master/packages/graphql-codegen-cli/src/config.ts#L183 there isn't a good isomorphic solution to this issue, for more info check this: https://stackoverflow.com/questions/54977743/do-require-resolve-for-es-modules and https://nodejs.org/api/esm.html#esm_import_meta_resolve_specifier_parent |
Another issue found in @graphql-codegen/plugin-helpers https://github.com/dotansimha/graphql-code-generator/blob/master/packages/utils/plugins-helpers/src/resolve-external-module-and-fn.ts#L7 That will most definitely break in ESM |
Yeah, seems to be an issue. And we do use this in codegen core to load plugins, configurations, and loaders. I guess we need a wrapper for that to make sure it's still supported in both setups.
How do you think we should address this one? cc @ardatan |
If that question is for me (maybe it wasn't), I feel like that is completely out of my scope since I'm not completely familiar with all the codegen internals, but adding support for esm I'd say is pretty much required for programmatic usage if for example GraphQL.js starts adding support for ESM with the exports field, that will trigger duplicated graphql module versions error, since if a commonjs module requires graphql, it will use the cjs version, and an esm module will use the esm version (this applies for every GraphQL library btw) |
Yeah, the question was for you :D |
While working in a example using graphql-codegen programmatically I realized that the plugin-helpers .mjs file is bundling Of course the solution is to add "change-case-all" as a dependency in this specific package, but this applies to every package that intends to support esm |
9b55a92
to
5b377b9
Compare
9babdae
to
87a16ec
Compare
After adding the test-esm.mjs script (and locally fixing the pending to be published fix of graphql-tools ardatan/graphql-tools#3289) these errors appear, this script is only able to catch errors in the imports, not the logic inside of the scripts I4qPI3OXjD.mp4I will take a look into fixing these issues |
2d0ab2e
to
54b94dc
Compare
After ardatan/graphql-tools#3300 is merged and publish, this PR should be ready @dotansimha |
186c89c
to
34d4c46
Compare
.changeset/sharp-nails-clean.md
Outdated
@@ -0,0 +1,52 @@ | |||
--- | |||
'@graphql-cli/codegen': major |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need a major release?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the changesets can be changed, I think this change is for minor, it was set as major since at first there was some changes that I thought were breaking, now everything should be fine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ardatan done 👍
c0770d2
to
57ebac7
Compare
.changeset/unlucky-dots-judge.md
Outdated
'@graphql-codegen/import-types-preset': minor | ||
'@graphql-codegen/near-operation-file-preset': minor | ||
'@graphql-codegen/config-schema': minor | ||
'@graphql-codegen/testing': minor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't publish testing and website to the NPM so those would changeset fail at NPM release. Could you remove these two?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ardatan done 👍 this issue in changesets has been open since so much time... changesets/changesets#436
Description
ESM Support
Type of change
How Has This Been Tested?
Test Environment:
@graphql-codegen/...
: latestChecklist: