@wundergraph/nextjs
TypeScript icon, indicating that this package has built-in type declarations

0.15.9 • Public • Published

Wundergraph Next.js integration

wunderctl

WunderGraph codegen template plugin to add deep Next.js integration.

Warning: Only works with WunderGraph.

Getting Started

npm install @wundergraph/nextjs swr

1. Register the codegen template

// .wundergraph/wundergraph.config.ts
import { NextJsTemplate } from '@wundergraph/nextjs/dist/template';

configureWunderGraphApplication({
  // ...
  // omitted for brevity
  codeGenerators: [
    {
      templates: [new NextJsTemplate()],
    },
  ],
});

2. Import the package

// 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);

Readme

Keywords

none

Package Sidebar

Install

npm i @wundergraph/nextjs

Weekly Downloads

407

Version

0.15.9

License

Apache-2.0

Unpacked Size

55.6 kB

Total Files

12

Last publish

Collaborators

  • starptech
  • jens-wundergraph