dulnan / nuxt-graphql-middleware

GraphQL in the backend, fetch in the frontend. With TypeScript support.
https://nuxt-graphql-middleware.dulnan.net
MIT License
57 stars 11 forks source link

Automatically inline fragments without "#import" syntax #32

Closed dulnan closed 4 months ago

dulnan commented 4 months ago

It would be a good DX improvement to be able to use any fragments that are included via the autoImportPatterns option in any fragment/query/mutation file without having to import them.

Currently, to use fragments, the fragment has to be explicitly imported using a non-standard syntax:

#import "~/pages/user/user.fragment.graphql"

query userById($id: ID!) {
  userById(id: $id) {
    ...user
  }
}

But because fragment names have to be unique anyway and unused fragments could be treeshaken during codegen, it would be possible to skip the imports completely:

query userById($id: ID!) {
  userById(id: $id) {
    ...user
  }
}
dulnan commented 4 months ago

Released in 4.1.0: https://nuxt-graphql-middleware.dulnan.net/features/fragments.html#automatic-import