Skip to content
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

Allow exporting ESM #808

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Allow exporting ESM #808

wants to merge 1 commit into from

Conversation

mkg20001
Copy link

@mkg20001 mkg20001 commented Oct 3, 2023

This adds an option esm which if set to true changes the exports to use ESM format

export default doc;

export const MyQuery = oneQuery(...);

etc.

This allows usage with node-esm-loader

export default {
  loaders: [
    {
      test: /\.(graphql|gql)$/,
      use: [
        {
          loader: "graphql-tag/loader.js",
          options: {
            esm: true
          }
        }
      ]
    },
  ],
};

@apollo-cla
Copy link

@mkg20001: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/

@jerelmiller
Copy link
Member

Hey @mkg20001 👋

Thanks so much for the PR! For now I can't guarantee a timeline on when we will review/merge this PR as we are still figuring out our ESM strategy right now. Thanks for the thought put into this!

@mkg20001
Copy link
Author

mkg20001 commented Oct 3, 2023

Fyi ESM is now stable and esm loaders are "Release Candidate" as of node 20, so relying on this in production is no longer such a trouble as it used to be.

https://nodejs.org/dist/latest-v20.x/docs/api/esm.html#modules-ecmascript-modules

https://nodejs.org/dist/latest-v20.x/docs/api/module.html#customization-hooks

This adds an option esm which if set to true changes the exports
to use ESM format

export default doc;

export const MyQuery = doc;

etc.

This allows usage with [node-esm-loader](npm.im/node-esm-loader)

```js
export default {
  loaders: [
    {
      test: /\.(graphql|gql)$/,
      use: [
        {
          loader: "graphql-tag/loader.js",
          options: {
            esm: true
          }
        }
      ]
    },
  ],
};
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants