Vite + SWR
Vite + SWR example demonstrates the power of code generation, when it comes to integrating WunderGraph with data fetching libraries like SWR .
Let's start by configuring WunderGraph.
What's notable here is that we're using
templates.typescript.client to generate our base client that is used by SWR
Next up is setting up the SWR hooks.
WunderGraph comes with a powerful framework for generating code. Here we are creating fully typed SWR hooks based on the operations of our WunderGraph application.
Define an Operation
Run a Query
Run a LiveQuery
Note: Logout() will trigger a refetch of the user.
You can configure the hooks globally by using the SWRConfig context.
In case the context configuration isn't working, it's likely due to multiple versions of SWR being installed or due to how PNPM or Yarn PnP link packages. To resolve this you can import SWR directly from
@wundergraph/swr to make sure the same instance is used.
Deploy to WunderGraph Cloud
The easiest way to deploy your WunderGraph app is to use WunderGraph Cloud . Enable the Vercel integration to deploy the Vite frontend to Vercel.