Diizzayy / nuxt-graphql-client

⚡️ Minimal GraphQL Client + Code Generation for Nuxt3
https://nuxt-graphql-client.web.app
MIT License
341 stars 42 forks source link

Eliminate `graphql` dependency in production build #376

Open madebyfabian opened 10 months ago

madebyfabian commented 10 months ago

Your use case

Hi there! Thanks for this module. I was inspecting my builds and I see that graphql gets bundled in there. I see that this module only uses the import { parse } from 'graphql' (https://github.com/search?q=repo%3ADiizzayy%2Fnuxt-graphql-client%20from%20%27graphql%27&type=code)

In my understanding, this method should only be needed while building. Or does this module read the .gql files in runtime from the server?

I see that it adds a good amount of KB's to my build: Bildschirmfoto 2023-09-11 um 08 21 51

The solution you'd like

If it's possible, remove this dependency in production builds.

Possible alternatives

No response

Additional information

Similar issue: https://github.com/urql-graphql/urql/issues/307

awdr74100 commented 10 months ago

@madebyfabian I would like to ask if this module is currently working properly?

madebyfabian commented 10 months ago

@awdr74100 Hi, yes for me, everything works, except of Fragments. But I am not using the nuxt-graphql-server module like you described in #369.

awdr74100 commented 10 months ago

@madebyfabian Thank you very much for your reply! I thought everyone could use the nuxt-graphql-server module except me...

rylanharper commented 9 months ago

@madebyfabian fragments are working fine for me.. How are you setting them up?

The docs are very vague on this.. You have to create a fragments folder inside the queries folder. Then they would be set up like this:

fragment Image on Image {
  id
  altText
  height
  width
  url (transform: {
    maxHeight: 600,
    maxWidth: 400,
    crop: CENTER
  })
}

Then add them into your .gql queries with no import such as this:

image {
  ...Image
}

Hope this helps:)

madebyfabian commented 9 months ago

@rylanharper Thanks for the details! This should absolutely be in the docs, since it's not standard graphql-ish behaviour. Now it's working.

Issue was: I named my fragment files MyFragment.fragment.gql to distinguish them easily from queries. Doing this does not work though.

If I find some time I'll create a docs PR.