Client side template
The client side template for a web application that uses the Learner Model GQL service is available at https://github.com/PabloSzx/learner-model-gql-template
.
Relevant Libraries
The template uses specific libraries to handle specific needs:
- Next.js - Fully fledged React framework for web applications.
- TypeScript - Superset of JavaScript with Type-safety in mind. It's encouraged but not mandatory, since TypeScript and JavaScript can be mixed.
- auth0-react - Authentication
- Chakra UI - Simple, Modular & Accessible UI Components
- GraphQL Code Generator - Generate code for complete type-safety and easier usage of GraphQL APIs
- React Query - Hooks for fetching, caching and updating asynchronous data in React
- Valtio - React state management
Important code
-
src/rqClient.ts - React API Client definition, having defined the default behavior like showing a Chakra UI Toast when any error is received from the API.
-
src/components/Auth.tsx - Basic authentication implementation.
Inside the GraphQL operation, the target project code
"example"
should be changed accordingly: -
src/utils/action.ts#L9 - Custom hook that defines standard usage of
action
mutation, reusing the authentication project and automatically adding thetimestamp
field. -
src/components/Auth.tsx#L11 -
withAuth
higher order component that lets protect specific React component to only be rendered if user is authenticated, basic usage example in src/pages/protected.tsx -
src/components/MainLayout.tsx - Layout of application
-
src/components/Navigation.tsx - Navigation bar of application
Usage
Development
Install dependencies:
pnpm i
Then, to run in localhost:
pnpm dev
The application is going to run and open on http://localhost:3000
Deployment
Some instructions recommended in the Next.js documentation can be found in https://nextjs.org/docs/deployment
.
It's recommended to use Vercel
, but for using pnpm
inside Vercel a couple of extra configurations have to be defined:
Build Command: pnpm build
Install Command: npm i -g pnpm && pnpm i --store=node_modules/.pnpm-store