graphql-ppx icon indicating copy to clipboard operation
graphql-ppx copied to clipboard

inconsistent es6/commonJs in Fragments?

Open AlexMoutonNoble opened this issue 2 years ago • 7 comments

Hi Jaap et al. My coworker points out that the generated code for a fragment file (at least) uses require to bring in @apollo/client but exports using es6 style.. This seems to be a problem for webpack...5? Any tips or plans to square that up? any way I can help?

Thanks Alex

@cid8600 @mattloomis

AlexMoutonNoble avatar Sep 13 '21 16:09 AlexMoutonNoble

If you are using template tags we need an inline require(..) to make it work reliably because ReScript doesn't have support for template tags. You can use templateTagAsFunction which is documented in rescript-apollo-client when you use a bundler that doesn't support require. It's a trade-off, template tags can have some benefits over strings. I would love to have a proper solution for this but I raised possible solutions in the rescript compiler that have not been addressed the past 2 years so I wouldn't hold my breath.

jfrolich avatar Sep 15 '21 02:09 jfrolich

If the require is necessary can the exports be made to be commonjs instead?

AlexMoutonNoble avatar Sep 16 '21 17:09 AlexMoutonNoble

im not recalling what a templateTag is

AlexMoutonNoble avatar Sep 16 '21 17:09 AlexMoutonNoble

By the way, this shouldn't be a problem with webpack5, I have an webpack 5 website deployed that works fine. What is your configuration?

jfrolich avatar Sep 17 '21 01:09 jfrolich

Hi Jaap Sorry for the delay...I'm finding this issue again now looking for webpack alternatives. The build system in question today is vite

AlexMoutonNoble avatar Jul 08 '22 14:07 AlexMoutonNoble

(Not a pressing issue, but I would love to never see webpack again, personally)

AlexMoutonNoble avatar Jul 08 '22 15:07 AlexMoutonNoble

ahh! templateTagIsFunction! found it

AlexMoutonNoble avatar Jul 15 '22 15:07 AlexMoutonNoble