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.
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.