nuxt-graphql-middleware icon indicating copy to clipboard operation
nuxt-graphql-middleware copied to clipboard

Support for nuxt layers

Open asonnleitner opened this issue 1 year ago • 6 comments

It would be cool if graphql files would support nuxt layers

asonnleitner avatar Apr 30 '24 08:04 asonnleitner

Is there something in particular that didn't work for you? I have successfully used this module with layers before, even having different query files per layer.

dulnan avatar Jul 02 '24 09:07 dulnan

@dulnan I believe I had some issues with the GraphQL files when using fragment imports. I had them stored at both the root level and the project level, but the imports did not resolve correctly.

asonnleitner avatar Jul 02 '24 09:07 asonnleitner

Ah I see. I will setup a playground that uses layers to try to debug this. What should work is to always reference the fragment imports by their full path.

I'm also currently working on a feature to automatically inline fragments without the need to specify an import. That should also fix the issue with layers, as long as there are no two fragments with the same name in multiple layers or layer and root.

dulnan avatar Jul 02 '24 09:07 dulnan

@dulnan That sounds awesome! 🔥

asonnleitner avatar Jul 02 '24 11:07 asonnleitner

@dulnan Here is something I worked in the past https://github.com/dulnan/nuxt-graphql-middleware/pull/33, which removes @graphql-fragment-import/lib and use a typescript module I wrote, it is also more performant and uses new newer JS API, like function generators, Maps and Sets. Feel free to make any changes.

asonnleitner avatar Jul 02 '24 11:07 asonnleitner

Both your refactored fragment import and the new "auto inline fragments" feature have been released in 4.1.0: https://nuxt-graphql-middleware.dulnan.net/features/fragments.html#automatic-import

I still need to add a "layers playground", so I'll keep this issue open for the time being.

dulnan avatar Jul 03 '24 14:07 dulnan