luckycatfactory / esbuild-graphql-loader

An esbuild Plugin Allowing for GraphQL File imports
44 stars 8 forks source link

amend exports #21

Closed sinisterstumble closed 3 years ago

sinisterstumble commented 3 years ago

export generateGraphQLString and generateContentsFromGraphqlString

louisscruz commented 3 years ago

Just out of curiosity: what was the motivation for exporting these functions?

sinisterstumble commented 3 years ago

@louisscruz for a vite plugin. To avoid the need to fork the repository for this:

export const viteGraphQLPlugin = (
  options: GraphQLLoaderPluginOptions = {}
): VitePlugin => ({
  name: 'graphql',
  transform(graphqlString: string, id: string) {
    if ((options.filterRegex ?? /\.graphql$/).test(id)) {
      return {
        code: generateContentsFromGraphqlString(
          graphqlString,
          options.mapDocumentNode
        ),
        map: null
      }
    }

    return
  }
})
sinisterstumble commented 3 years ago

@louisscruz unplugin, unified plugin system for vite, rollup, and webpack, is another possible option.

louisscruz commented 3 years ago

After a lot of internal deliberation over this one, I've decided to allow for these functions to be exposed. Generally, I am not in favor of exposing more than is needed in order to keep future implementation and API changes as simple as possible. But this seems harmless enough. Hopefully this doesn't become some source of regret in the future 😆 .

Merged here https://github.com/luckycatfactory/esbuild-graphql-loader/pull/25 and made available as v3.7.0.

sinisterstumble commented 3 years ago

@louisscruz thank you!