gQuery/README.md

67 lines
1.3 KiB
Markdown
Raw Normal View History

2021-09-29 18:13:11 +00:00
![gQuery](./gQuery.png)
2021-09-29 17:02:01 +00:00
# qQuery
2021-09-29 17:11:21 +00:00
## Not like jQuery. A GraphQL Fetcher & Cache for Svelte Kit
### UnderConstruction.gif
More information in this space soon. API is very much in flux rn.
### Preview
2021-09-29 18:13:11 +00:00
### 1. Initialize G
```
export const g = new GFetch({
path: Environment.apiURL //whatever your api url is here
})
```
### 2. Add GraphQL Codegen Plugin
docs coming soon
2021-10-01 21:39:41 +00:00
### 3. Add Codegen Config
2021-09-29 18:13:11 +00:00
docs coming soon
### 4. Use that thang
```
<script context="module" lang="ts">
2021-09-30 16:19:53 +00:00
// The generated function that fetches and caches
2021-09-29 18:13:11 +00:00
import { getSeriesList } from '../whatever'
export async function load() {
2021-09-30 16:19:53 +00:00
// Runs the cache/fetch function populating $gCache before use.
2021-09-29 18:13:11 +00:00
await getSeriesList({
limit: 0
})
return {}
}
</script>
<script lang="ts">
2021-09-30 16:19:53 +00:00
// Cache becomes populated with data available for SSR
2021-10-13 17:06:31 +00:00
import { gCache } from '@leveluptuts/g-query'
2021-09-29 18:13:11 +00:00
// $: console.log($gCache.seriesList)
</script>
```
## FAQ / WTF
### Q? How tf do I update the cache?
It's a Svelte Writable Store. So after a mutation you can quickly and easily manually update the cache.
2021-09-30 16:19:53 +00:00
### Q? Can't you update the cache magically for me after a mutation?
2021-09-29 18:13:11 +00:00
Maybe? If you want to be in charge of writing that bit, the door is open 😼
2021-09-30 16:19:53 +00:00
### Q? Why can't I use this yet?
It's changing too much rn, but will be available asap. Trust me, the sooner I get this done the better.