A fullstack boilerplate which uses Hasura GraphQL Engine and Next.js to develop applications.
- Content
- TechStack Features
- Requirements
- Development Step
- Deployment
- `
- Migration flow from development to production.
- Custom logic with NextJs API route (serverless)
- License
This boilerplate is built using the following technologies:
- NextJs (The React Framework for Production)
- Hasura (GraphQL engine: supports GraphQL Query, Mutation and Subscription out of the box.)
- GraphQL (Flexible query language for API layer ~~ REST alternative)
- NextAuth (Authentication for NextJs power by NextJs API Routes)
- Apollo Client (Comprehensive Graphql Client - Automatically update the UI while fetching, caching, and updating the application state.)
- GraphQL Code Generator (Generate react hooks with fully typescript for all your graphql query)
- Tailwindcss (A utility-first CSS framework)
- Retail UI (UI libary power by tailwindcss)
- Typescript (Typed JavaScript at Any Scale)
- Node.js Recommended Install via nvm
- npm Yeah! for
npm install -g yarn - Docker and Docker Compose
- Hasura CLI
git clone https://github.com/sondh0127/nextjs-hasura-fullstacknode generateKeys.jsIt will create
hasura/.envandnextjs/.envfiles which used to provide authentication and security for the app
AUTH_PRIVATE_KEY # Private key
HASURA_GRAPHQL_JWT_SECRET # Public key
HASURA_GRAPHQL_ADMIN_SECRET # Hasura console password
For Backend:
Starting Docker by using docker-compose which will start our backend app and database services.
cd hasura/
docker-compose upIf everything goes well, it’ll be up and running on http://localhost:8080/v1/graphql.
The console will help us automatically create migration and metadata for any change. Readmore
Require Hasura CLI
Open console on another terminal
cd hasura/
hasura console --admin-secret <HASURA_GRAPHQL_ADMIN_SECRET>The console is running on http://localhost:9695.
For Frontend:
cd nextjs/ && yarnCreate a new Google OAuth Client and copy the credentials (Client ID and Client Secret) into .env file.
GOOGLE_CLIENT_ID=""
GOOGLE_CLIENT_SECRET=""Config Authorised redirect URIs:
http://localhost:3000/api/auth/callback/google
https://domailname.app/api/auth/callback/google
yarn devThe above command will start the application on http://localhost:3000/. It also watching for the change of your GraphQL to generate new code by GraphQL Code Generator
The production ready can be done with Vercel and Heroku platforms by following the instruction. (Free hosting)
To deploy the backend application on Heroku press the button below. You must register for a free Heroku account.
From heroku dashboard: Go to
Settings=> [Config Vars] ChooseReveal Config Vars=> Add the following config
HASURA_GRAPHQL_ADMIN_SECRET="secret@123"
HASURA_GRAPHQL_JWT_SECRET: ''Calm! You just need to wait Heroku to update config for a while
From heroku dashboard: Go to
Resources=>Heroku postgresaddons. In new windows:Settings=>View Credentials... Copy yourDATABASE_URLfromURIfield with sample format:postgres://postgres:@localhost:5432/postgres
Click on the button below to deploy the frontend application on Vercel. You'll need to sign up for a free Vercel account.
Get your DATABASE_URL
NEXT_PUBLIC_API_URL=https://domainname.herokuapp.com/v1/graphql
NEXT_PUBLIC_WS_URL=wss://domainname.herokuapp.com/v1/graphql
DATABASE_URL=postgres://postgres:@localhost:5432/postgres
NEXTAUTH_URL=http://localhost:3000
GOOGLE_CLIENT_ID=""
GOOGLE_CLIENT_SECRET=""
AUTH_PRIVATE_KEY=""
Open console:
hasura console --admin-secret <HASURA_GRAPHQL_ADMIN_SECRET>
Run migration with metadata:
hasura migrate apply --endpoint <YOUR_HASURA_APP_ENDPOINT> --admin-secret <HASURA_GRAPHQL_ADMIN_SECRET>
hasura metadata apply --endpoint <YOUR_HASURA_APP_ENDPOINT> --admin-secret <HASURA_GRAPHQL_ADMIN_SECRET>Example:
hasura migrate apply --endpoint https://nextjs-hasura-fullstack-trello.herokuapp.com --admin-secret secret@123
hasura metadata apply --endpoint https://nextjs-hasura-fullstack-trello.herokuapp.com --admin-secret secret@123TODO
heroku login heroku container:login heroku container:push web -a appname heroku container:release web -a appname heroku open
vercel
This project is licensed under the MIT License.
