A demonstration and starting point for applications using Next.js + Apollo GraphQL (hooks) + Prisma / GraphQL Yoga + JWT for authentication, and deploying to now.sh
You should already have a Prisma GraphQL backend server up and running. If you do not, follow this guide.
Now CLI should be installed. If you do not have this yet, type npm i -g now in your terminal.
-
Run
npm installinside both thefrontendandbackendfolders to install all the required dependencies. -
Create a file named
.envwithin thefrontendfolder like so:## replace this with your Prisma backend URL. Likely it will be a Heroku url PRISMA_ENDPOINT=https://dockerprismating-6e1f3cd25a.herokuapp.com/prismatest3/dev ## smash your keyboard a bit to make a secrets PRISMA_SECRET=sdgGhwgg82425772hDGH ## smash your keyboard a bit more to make another secret APP_SECRET=jSUdg24ugrgu8dgHDgsn -
Add your secrets to now CLI (read more about this here)
type now secret add prisma_secret INSERT-YOUR-PRISMA-SECRET-FROM-STEP-2-HERE
type now secret add app_secret INSERT-YOUR-APP-SECRET-FROM-STEP-2-HERE
-
Open
backend/now.jsonand add your prisma backend URL toPRISMA_ENDPOINT -
Run
npm run devfrom both the backend and frontend folders
Your GraphQL Yoga server will be on [localhost:4000](http://localhost:4000) and the Next.js app will be on localhost:3000
- Visit
[localhost:3000/signup](http://localhost:3000/signup)and start testing the flow. You can view all users atlocalhost:3000/users
This is very rough, but it works. I will aim to clean it up a bit soon.
One issue: when you change your schema.graphql you need to run npm run dev before it will work properly with GraphQL yoga, due to an issue with importing
-
Run
nowfrom thefrontendfolder. Take note of the your frontend URL which will be shown in the now CLI -
In the
backendfolder, edit the.envfile you created in the "Getting Started" section and thenow.jsonfile to reflect the frontend URL (edit the value ofPRODUCTION_FRONTEND_URL) -
Run
nowfrom thebackendfolder. Take note of the backend URL which will be shown in the now CLI -
In the
frontendfolder add your GraphQL Yoga url tonext.config.js
Bruno Crosier