teamwalnut / graphql-ppx

GraphQL language primitives for ReScript/ReasonML written in ReasonML
https://graphql-ppx.com
MIT License
257 stars 53 forks source link

inconsistent es6/commonJs in Fragments? #271

Open AlexMoutonNoble opened 2 years ago

AlexMoutonNoble commented 2 years ago

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

jfrolich commented 2 years ago

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.

AlexMoutonNoble commented 2 years ago

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

AlexMoutonNoble commented 2 years ago

im not recalling what a templateTag is

jfrolich commented 2 years ago

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?

AlexMoutonNoble commented 2 years ago

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 commented 2 years ago

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

AlexMoutonNoble commented 2 years ago

ahh! templateTagIsFunction! found it