FaunaDB Next.js Example
The FaunaDB example shows how you can use WunderGraph with FaunaDB and Next.js.
WunderGraph integrates with FaunaDB out of the box, no complex configuration is required.
Prerequisites
Before we can start, you've got to set up a FaunaDB account and create a database. Please follow the steps below.
Create a FaunaDB account.
Create a database with the following options:
- Name:
test
- Region Group: Choose the one that works best for you.
- [x] Use demo data.
- Name:
Create a API token under
Security
.- Database:
test
- Role:
Admin
- Key Name:
test
- Database:
Write down the secret displayed: if you lose it, you have to create a new one (the secret is only ever displayed once).
Rename the file
example.env
to.env
.In
.env
:Replace
<replace-with-your-token>
with the secret from step 4.If you selected a Region Group other than Classic, replace
https://graphql.fauna.com/graphql
with the GraphQL API endpoint suitable for your selected region group:- EU:
https://graphql.eu.fauna.com/graphql
- US:
https://graphql.us.fauna.com/graphql
- Preview:
https://graphql.fauna-preview.com/graphql
- EU:
Configuration
Once the environment is set up, we're ready to configure our application.
This configuration adds faunaDB
as a data source and configures the API key to be used. The API key of your FaunaDB instance is not exposed to the client, making it a perfect fit to secure your API.
Add an Operation
Now that everything is configured, let's add an Operation.
Calling the Operation from Next.js
And that's it! We've fully integrated FaunaDB, WunderGraph and Next.js.
Learn more
Deploy to WunderGraph Cloud
The easiest way to deploy your WunderGraph app is to use WunderGraph Cloud. Enable the Vercel integration to deploy the Next.js frontend to Vercel.