A project to analyze drivers winners.
Running the service requires some dependencies.
- Docker and Docker Compose installed. Install instructions.
- Hasura CLI installed. Instructions here.
- Run
docker-compose up -d --build
- Make sure all migrations are applied by running
npm run migrate
- Make sure to fulfill the database using the seeds by running
npm run seeds
- To start exploring, start hasura console with
hasura console
if you wanna make sure the migrations has been applied to the correct schema, run:
docker exec f1-world-championship-api_app_1 sh -c npm run migrate"
and also the seeds to make sure
docker exec f1-world-championship-api_app_1 sh -c npm run seeds"
dont forget to track the schemas and create the actions
hasura metadata apply
In case you need to load env vars use the .env
file as the sample
name | description |
---|---|
HASURA_PROJECT_ENDPOINT |
GraphQL engine endpoint |
NEXTJS_SERVER_URL |
Next server |
ACTIONS_BASE_URL |
Actions endpoint |
Or, run the development server by yourself to check better logs:
npm run dev
# or
yarn dev
Go to http://localhost:3000 to access the serveless functions
Go to http://localhost:8080 for Hasura console (admin secret = "")
Serveless functions are running at https://f1-world-championship-api.vercel.app/api/health
check it out the functions.
curl --location --request POST 'https://f1-world-championship-api.vercel.app/api/actions/drivers' \
--header 'x-hasura-admin-secret: X6M0Xj35Y1QqL6M66CBOj852xwEaUYqE6i2R246WQdZVQxptuO3sf7f6tv4ZObjb' \
--header 'Content-Type: application/json' \
--data-raw '{
"input": {
"from": "2021-12-16",
"to": "2023-12-16",
"limit": 10
}
}'
Graphql engine is running at https://quiet-buzzard-46.hasura.app
try it out the actions:
query {
getDrivers(
from: "2021-12-16",
to: "2023-12-16",
limit: 10
) {
id
forename
surname
standings_aggregate {
aggregate {
sum {
wins
}
}
}
result {
milliseconds
fastest_lap_speed
race {
year
name
datetime
}
}
}
}
you can check if everything is fine running the assertions
npm run test
generate coverage
npm run coverage
here you have a simple test coverage report.
As an example, the bar chart below shows 10 racers who have the most wins by time already consumed by our GetDrivers
Hasura action.
The high latency of the servers of the GraphQL engine and the vercel serveless functions is due the zone and cold start reasons. It should runs faster if we boost the server and change the regions. Also I made a tiny performance improvement to make sure it was the server latency instead of a low query issue at our engine. Try it out locally to see the difference.
"When applications are done well, they are just the really application-specific, brackish residue that can't be so easily abstracted away. All the nice, reusable components sublimate away onto github and npm where everybody can collaborate to advance the commons."