apollographql / graphql-tag

A JavaScript template literal tag that parses GraphQL queries
MIT License
2.33k stars 177 forks source link

Allow exporting ESM #808

Open mkg20001 opened 1 year ago

mkg20001 commented 1 year ago

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 commented 1 year ago

@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 commented 1 year ago

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 commented 1 year ago

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