File tree Expand file tree Collapse file tree 1 file changed +56
-1
lines changed Expand file tree Collapse file tree 1 file changed +56
-1
lines changed Original file line number Diff line number Diff line change @@ -186,9 +186,64 @@ subscription MessageSub($from: String!) {
186
186
</gql >
187
187
```
188
188
189
+ ## Fragments
190
+ You can use fargments in your graphql queries, mutations, and subscriptions by specifying your ` .gql ` files that contain your fragments in the config.
191
+
192
+ ``` ts
193
+ // vite.config.ts
194
+
195
+ import Vue from ' @vitejs/plugin-vue'
196
+ import Vql from ' vite-plugin-vue-gql'
197
+
198
+ export default {
199
+ plugins: [
200
+ Vue (),
201
+ Vql ({
202
+ fragments: ' ./src/fragments/**/*.gql'
203
+ })
204
+ ],
205
+ }
206
+ ```
207
+
208
+ Here is a general idea of what your fragments should look like
209
+ ``` gql
210
+ # src/fragments/albums.gql
211
+
212
+ fragment albumFields on Album {
213
+ id
214
+ name
215
+ image
216
+ }
217
+ ```
218
+
219
+ Finally you can use these fragments in you Vue SFC
220
+
221
+ ``` html
222
+ <script setup lang =" ts" >
223
+ import { ref } from ' vue'
224
+ import { useQuery } from ' vql'
225
+
226
+ const name = ref (' RADWIMPS' )
227
+ const { data } = useQuery ({ name })
228
+ </script >
229
+
230
+ <template >...</template >
231
+
232
+ <gql >
233
+ query($name: String!) {
234
+ queryArtists(byName: $name) {
235
+ name
236
+ image
237
+ albums {
238
+ ...albumFields
239
+ }
240
+ }
241
+ }
242
+ </gql >
243
+ ```
189
244
190
245
## Roadmap
191
- - [ ] Add support for fragments
246
+ - [x ] Add support for fragments
192
247
- [ ] Investigate automatically generating queries from SFC templates
193
248
194
249
## License
You can’t perform that action at this time.
0 commit comments