How to structure Graphql, Typescript and Express app for scalability

Share on facebook
Share on google
Share on twitter
Share on linkedin

In this post I will share a great structure for structuring your Graphql application, using Typescript and Express.

The structure consists of these folders/layers (from outer to inner):

  • IOC: Inversion of control provides testability and control over the dependencies in the system. For this, I use “Inversify”
  • Schema: The definition of the GraphQL schemas defined as .gql files for making the schema definition language agnostic.
  • Resolvers: The definition of the resolvers. These are split into query and mutation resolvers.
  • Models: The use case models containing business information and being called by resolvers.
  • Connectors: Layer for doing external requests.
  • Interfaces: Interfaces proving type safety in the GraphQL app.

For testing, there is a tests folder containing a folder for unit tests and one for integration tests. I use Jest for running test as this works great with Typescript and contains a rich test framework with easy setup.

The code for a starter template with this structure can be found at my Github here.

Do you want to become an Angular architect? Check out Angular Architect Accelerator.

Related Posts and Comments

Error, loading, content…? Use this page pattern for your Angular apps

When developing Angular applications, it’s common for pages to transition through three key states: error, loading, and show content. Every time you fetch data from an API, your page will likely show a loading indicator first, and then either render the content successfully or display an error message if something goes wrong. This pattern is

Read More »

How to do Cypress component testing for Angular apps with MSW

In this post, we will cover how to do Cypress Component testing with MSW (mock service worker) and why it’s beneficial to have a mock environment with MSW. The mock environment My recommendation for most enterprise projects is to have a mocking environment as it serves the following purposes : * The front end can

Read More »

Handling Authentication with Supabase, Analog and tRPC

In this video, I cover how to handle authentication with Supabase, Analog and tRPC. It’s based on my Angular Global Summit talk about the SPARTAN stack you can find on my blog as well. Code snippets Create the auth client Do you want to become an Angular architect? Check out Angular Architect Accelerator.

Read More »

1 thought on “How to structure Graphql, Typescript and Express app for scalability”

  1. Pingback: How To Fix the Most Common Angular Performance Problems Like a Doc – Christian Lüdemann

Leave a Comment

Your email address will not be published. Required fields are marked *