Now that the front end prototype is ready for the product team to conduct user testing on, we will work on replacing our fake API. With this update we will set the foundation to be able to move task data out of the local browser scope to the cloud, and implement authentication.
@as‑integrations/fastify
adapter). This setup provides us with a robust schema, great developer experience and seamless client integration with Apollo Client.Our goal for this project is to set up a minimalistic working state of the fastify server, GraphQL API, and make a connection to the database.
We split it into 3 parts:
/health
endpointHealth
queryapps/api
and set up core dependencies, including Fastify
, Apollo Server
, Zod
, and essential Fastify plugins for security, compression, and rate limiting.tsup
for bundling and running the development server..env.sample
file defining essential environment variables such as NODE_ENV
, PORT
, and CORS_ALLOWLIST
, ensuring clearer configuration management.config
module using Zod schemas to validate environment variables and provide default values.server.ts
initialises a structured Fastify instance with key middleware, including CORS, Helmet for security, and Swagger for API documentation.config
plugin integrates environment configurations directly into Fastify, making them easily accessible./health
route with schema validation for a simple API health check./documentation
.vitest
with a test utility for running a Fastify test server./health
route to verify the API responds with { ok: true }
.packages/eslint-config/server.js
packages/tsup-config/src/node.ts
packages/typescript-config/node.json
@repo/mongodb-helpers
PackageFor MongoDB-related operations a reusable package @repo/mongodb-helpers
was created to contain:
CounterSchema
, to standardise data models._id
, createdAt
, and updatedAt
for consistency across documents.createdAt
, updatedAt
) are properly set on document updates.This package is now included as a workspace dependency and integrated within the API.
DB_CONNECTION_STRING
environment variable to facilitate database connection management.A new Fastify plugin, counterPlugin
, was implemented to monitor API connection counts. This plugin:
increaseCounter
function that:counterPlugin
in plugins/index.ts
alongside existing plugins.increaseCounter
method for seamless access.@repo/graphql
PackageA new workspace package, @repo/graphql
, was introduced to centralise GraphQL-related utilities across projects. It includes:
common.ts
, health.ts
).graphql-codegen
to generate TypeScript types and operations.graphql-codegen
for automatic type generation based on GraphQL schemas in codegen.ts
to generate TypeScript types for resolvers.@as-integrations/fastify
.contextFunction
for injecting context to the GraphQL resolvers.executableSchema.ts
using @graphql-tools/schema
and @graphql-tools/merge
– combining the schemas from @repo/graphql
and the resolvers.healthResolvers
to provide a basic health check query.commonResolvers
module with custom scalar types for BigInt
and RegExp
./graphql
endpoint in Fastify via graphqlRoutes
.GeneralError
class for handling GraphQL errors with structured messages.@repo/translation/en/errors.json
to maintain error messages in a centralised translation system.With this release, we have:
We will continue to build our API, and implement user management:
Here's how our timeline look like now: