Skip to content

How to add a feature?

The project structure

In this section we will walk you through the main files and folders of the project. In the following tree you'll find the main documents to pay attention to, the rest of the files and folders might be automatically generated or a bit advanced for this guide:

📦 graphql-server
┣ 📂 prisma
┃ ┣ 📜 schema.prisma
┃ ┗ 📜 seed.ts
┣ 📂 scripts
┃ ┗ 📜 init_backend.sh
┣ 📂 src
┃ ┣ 📜 context.ts
┃ ┣ 📜 schema.ts
┃ ┣ 📜 server.ts
┃ ┗ 📜 utils.ts
┣ 📜 .env
┣ 📜 package.json
┗ 📜 schema.graphql

/src/server.ts

The entry point of the backend, here we can configure the apollo server: load the context and schema and define the port.

/src/schema.ts

In this file we define the types and resolvers of our API.

/prisma/schema.prisma

Here we define the Data Model, since GraphQL is used, the model will use entities (models) and types(enums). We'll also tell Prisma what datasource we'll use (our Postgres db) and the generator (js prisma client).

Adding a new field to an entity

The flow for this process is:

  1. Add field to data model, prisma/schema.prisma.
  2. Add field to input types, src/schema.ts.
  3. Add query/mutation resolver and update affected resolvers, src/schema.ts.
  4. Update seed function, prisma/seed.ts.
  5. Start server, scripts/init_backend.sh
  6. Test affected queries/mutations with graphiql.

(Frontend)

  1. Update affected client queries.
  2. Create/update frontend components.
  3. Test client.

Integrating a new service to the API gateway

The flow for this process is:

  1. Make sure your service is working and ready to integrate before starting this process. I'd suggest testing the connection to endpoints since network and containers may be a bit more opaque.
  2. First add the endpoint of your service to the .env file inside the root wallofshame-backend directory.
  3. Then add a remote executor to make the schema of your service in the graphql-gateway/src/server.js file. Also add the subschema and the resource to monitor for the waitOn task(if applies).
  4. Add the endpoints to the sub
  5. Add the endpoint to an environment variable of the gateway service described in the wallofshame-backend/docker-compose.yaml file.

Last update: 2022-05-23