WunderGraph codegen template plugin to add deep Next.js integration.
Warning: Only works with WunderGraph.
npm install @wundergraph/nextjs swr
// .wundergraph/wundergraph.config.ts
import { NextJsTemplate } from '@wundergraph/nextjs/dist/template';
configureWunderGraphApplication({
// ...
// omitted for brevity
codeGenerators: [
{
templates: [new NextJsTemplate()],
},
],
});
// pages/authentication.ts
import {
withWunderGraph,
useQuery,
useMutation,
useSubscription,
useAuth,
useUser,
} from '.wundergraph/generated/nextjs';
const Example: ExamplePage = () => {
const { login, logout } = useAuth();
const { data: user } = useUser();
const onClick = () => {
if (user === null || user === undefined) {
login('github');
} else {
logout();
}
};
return (
<div>
<h1>Authentication</h1>
<button onClick={onClick}>${user ? logout : login}</button>
<p>{JSON.stringify(user)}</p>
</div>
);
};
export default withWunderGraph(Example);