Nuxt support

Wundergraph can be easily be integrated with Nuxt through the Vue Query integration. Create a wundergraph.ts in the plugins directory, register the Vue Query plugin and the wundergraph hooks:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import type { DehydratedState, VueQueryPluginOptions } from '@tanstack/vue-query';
import { VueQueryPlugin, QueryClient, hydrate, dehydrate } from '@tanstack/vue-query';
import { useState } from '#imports';
import { createHooks } from '@wundergraph/vue-query';
import { createClient, Operations } from '../.wundergraph/components/generated/client';
export default defineNuxtPlugin((nuxt) => {
const vueQueryState = useState<DehydratedState | null>('vue-query');
const queryClient = new QueryClient();
const options: VueQueryPluginOptions = { queryClient };
nuxt.vueApp.use(VueQueryPlugin, options);
if (process.server) {
nuxt.hooks.hook('app:rendered', () => {
vueQueryState.value = dehydrate(queryClient);
});
}
if (process.client) {
nuxt.hooks.hook('app:created', () => {
hydrate(queryClient, vueQueryState.value);
});
}
const client = createClient(); // Typesafe WunderGraph client
const wgraph = createHooks<Operations>(client);
return {
provide: {
wundergraph,
},
};
});

You can then use it like this :

1
2
3
4
5
6
<script setup>
const { $wundergraph } = useNuxtApp();
const dragons = $wundergraph.useQuery({
operationName: 'Dragons',
});
</script>

Examples

If you're interested in trying out WunderGraph with Nuxt, have a look at the following examples:

If you've got any questions, please join our Discord Community and ask away.

Previous
Vue

Was this article helpful to you?
Provide feedback

Edit this page