8000 chore: update readme · wheatjs/vite-plugin-vue-gql@da51b37 · GitHub
[go: up one dir, main page]

Skip to content

Commit da51b37

Browse files
committed
chore: update readme
1 parent b8628b8 commit da51b37

File tree

1 file changed

+56
-1
lines changed

1 file changed

+56
-1
lines changed

README.md

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,64 @@ subscription MessageSub($from: String!) {
186186
</gql>
187187
```
188188

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+
```
189244

190245
## Roadmap
191-
- [ ] Add support for fragments
246+
- [x] Add support for fragments
192247
- [ ] Investigate automatically generating queries from SFC templates
193248

194249
## License

0 commit comments

Comments
 (0)
0