┏━━━┓━━━━━━━━━━━━━┏┓━━━━━━━━━━━━━━━━━━━
┃┏━┓┃━━━━━━━━━━━━━┃┃━━━━━━━━━━━━━━━━━━━
┃┃━┗┛┏━━┓┏━━┓┏━┓┏━┛┃┏┓┏━┓━┏━━┓━┏━━┓┏━━┓
┃┃━┏┓┃┏┓┃┃┏┓┃┃┏┛┃┏┓┃┣┫┃┏┓┓┗━┓┃━┃┏┓┃┃┏┓┃
┃┗━┛┃┃┗┛┃┃┗┛┃┃┃━┃┗┛┃┃┃┃┃┃┃┃┗┛┗┓┃┗┛┃┃┃━┫
┗━━━┛┗━━┛┗━━┛┗┛━┗━━┛┗┛┗┛┗┛┗━━━┛┃┏━┛┗━━┛
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┃┃━━━━━━
React Frontend + GraphQL API ┃┃
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┗┛━━━━━━
__------__
/~ ~\
| //^\\//^\|
/~~\ || o| |o|:~\
| |6 ||___|_|_||:|
\__. / o \/'
| ( O )
/~~~~\ `\ \ /
| |~~\ | ) ~------~`\
/' | | | / ____ /~~~)\
(_/' | | | /' | ( |
| | | \ / __)/ \
\ \ \ \/ /' \ `\
\ \|\ / | |\___|
\ | \____/ | |
/^~> \ _/ <
| | \ \
| | \ \ \
-^-\ \ | )
`\_______/^\______/
Stack: React, Hasura graphql server & vercel serverless functions
- NodeJS v14
- Hasura cli version >= 2.1.1
- Yarn
- Docker
- Vercel CLI
- Laravel → Hasura & Vercel serverless functions
- Material UI → Stitches + React-Query & Zeus
yarn installyarn setup- init git submodules & link hardhat
cp .env.example .env- Set
HARDHAT_OWNER_ADDRESSandLOCAL_SEED_ADDRESSto your local dev wallet
- Set
yarn docker:start- Start laravel legacy backend, Hasura and postgres- Clear the data stored in the docker volumes:
yarn docker:clean - First time laravel is slow.
- Clear the data stored in the docker volumes:
yarn db-seed-fresh- Seed the db w/ dummy datavercel dev- If you're creating a new Vercel project, use these custom settings:
- Build Command:
./scripts/link-hardhat.sh && yarn build - Development Command:
craco start
- Build Command:
- Runs React and the serverless functions in
api/
- If you're creating a new Vercel project, use these custom settings:
- Goto: http://localhost:3000 and start giving!
yarn storybook
yarn hasura consoleto modify and explore the databaseyarn generateafter schema changes to codegen zeus & react-query libs- Requires the
vercel devserverless functions to be running
If you pull in any new changes to the schema, your local Hasura instance might start complaining about metadata inconsistency. In order to apply the new migrations / metadata to your local instance, run the following commands:
yarn hasura migrations apply
yarn hasura metadata applyAlternatively, you can just run yarn docker:stop && yarn docker:start and Hasura will apply the migrations/metadata automatically.
- Set
ETHEREUM_RPC_URLin .env- From Infura project id: Infura & create new project
yarn hardhat:dev
./scripts/setup.sh- link the react app generated code./scripts/rebuild-hardhat.sh- Rebuild the generated codeyarn hardhat:test- Run tests- make sure
HARDHAT_FORK_BLOCKis set (13500000 is a good value) andETHEREUM_RPC_URLpoints to an archive node
- make sure
Hasura
automagically creates a
GraphQL API
atop our postgres db. We use it to apply
migrations
and
manage metadata.
Perhaps, the easiest way to get a feel is start the app and run yarn hasura console.
Any changes you make in the Console will be reflected in your local hasura directory as migrations or metadata. In the feature branch a clone of the staging database will be created with the changes.
These will be applied to the staging/production instance once merged via PR.
Inspired by the 3factor app. We are building thin client with business logic using serverless functions and postgres constraints.
- Actions
- Mutations
- Triggers
- Cron jobs
- Constraints
Server logic in typescript, configured with hasura, deployed by vercel.
Bootstrapped with Create React App.
- Recoil
- Material UI
- ethers
- axios
- Luxon
- Sentry (error reporting)
- d3-force-3d
- See forked
canvas-color-trackerfor brave compatibility
- See forked
State Management w/ Recoil
Moving towards Zeus+React-Query
Recoil defines a consistent data graph that will suspend the app when useRecoilState(rIdentifier) has an unresolved promise. See their video and documentation.
The basic distinction is between atoms and selectors. selectors will be rerun when any of their dependencies change and with each run the dependency list can change, unlike with hooks. atomFamily and selectorFamily allow parameterization.
- Recoil identifiers are Global
- Prefer to minimize atoms and selectors now
- Most data consolidated into profile & circle state
useSelectedCircle&useMyProfile
- Advanced Recoil concepts:
- Types are currently manually matched to our server
- e.g.
api.epoch.d.tsand post params:api.d.ts
- e.g.
const useRecoilLoadCatch()- standard wrapper that can trigger loading and error message
- App data loaded in
useApiBasefetchManifestfetchCirclefetchProfile
@exrhizo developed a in house form lib inspired by React Hook Form with the intention of easy customization. Perhaps too clever.
- Forms are configured with a Zod Parser
- See
AdminUserFormfor a simple use - Doesn't have first class support of array fields
Setup docker, git, hasura completions.
- Install VS Code's docker extension
docker ps- see the running containersdocker logs coordinape_graphql-engine_1 | jq -C | less -r- jq parses the hasura log output as colorized json
docker exec -it app bash- Create a shell in the container
-
Cannot start service app: error while creating mount source pathTry restarting Docker Desktop -
TypeError: Cannot read properties of undefined (reading 'replace')You need to configure a local.envfile with some private variables. Ask someone for these. -
error: no template named 'remove_cv_t' in namespace 'std'; did you mean 'remove_cv'Probably related to node-sass versions. Node v16 only works with node-sass 6.0.1 or newer. sass/node-sass#3077 -
Laravel in Docker always restarting (Windows)When log saysstart.sh : not foundChange the line ending ofLaravel/services/start.shfrom CRLF to LF.