Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update FE docs and add gql.tada ADR #1880

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions docs/adr/adr-typing-graphql.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# ADR: Typing GraphQL Usage

Author: [Felipe](https://github.com/fhenrich33)

## Status

Implemented

## Context

We need a reliable and efficient way to handle GraphQL typings in our project. Currently, we are using GraphQL Code Generator, which has its benefits but also some drawbacks. We are considering switching to `gql.tada` for the following reasons:

1. **Developer Experience**: `gql.tada` offers a more streamlined and intuitive developer experience. It simplifies the process of defining and using GraphQL types, reducing the cognitive load on developers.
2. **Type Inference**: `gql.tada` provides better type inference capabilities, which can lead to more accurate and maintainable code. This is particularly important in a dynamic and evolving codebase.
3. **Performance**: `gql.tada` is designed to be lightweight and fast, which can improve the overall performance of our development workflow.

## Decision

We will adopt `gql.tada` for typing GraphQL usage in our project. This decision is based on the following comparisons with GraphQL Code Generator:

### GraphQL Code Generator

- **Pros**:
- Automatically generates TypeScript types from GraphQL schemas and operations.
- Supports a wide range of plugins and configurations.
- Well-documented and widely used in the community.
- **Cons**:
- Can be complex to configure and maintain, especially for large projects.
- Although we don't really need to manually check and review, generated code can be verbose and difficult to navigate.
- Requires additional build steps, which can slow down the development process. While infrequent, we must regenerate the types when the schema changes.
- Requires extra boilerplate code, as we need to pass generated types as generics to GraphQL functions.

### gql.tada

- **Pros**:
- Simplifies defining and using GraphQL types with a more intuitive API.
- Provides better type inference, reducing the need for manual type annotations.
- Lightweight and fast, with minimal impact on build times.
- Easier to integrate into existing projects with less configuration overhead.
- A less impactful in the grand scheme of things but a nice bonus: orders of magnitude less generated code (a few thousand lines of code removed).
- **Cons**:
- Less mature and less widely adopted compared to GraphQL Code Generator.
- Nearly non-existent plugins and integrations available.

## Consequences

By adopting `gql.tada`, we expect to achieve the following benefits:

- Improved developer experience with a more intuitive and streamlined API. We can explore and experiment with queries from the code as we have type hints inside GraphQL strings.
- Better type inference, leading to more accurate and maintainable code.
- Faster development workflow with reduced build times.

However, we also acknowledge the potential risks:

- Limited community support and fewer available plugins compared to GraphQL Code Generator.
- Potential need for additional customizations or workarounds due to the relative immaturity of `gql.tada`.

Overall, we believe that the benefits of adopting `gql.tada` outweigh the potential drawbacks, and we are confident that this decision will lead to a more efficient and enjoyable development experience.

## Implementation

1. Integrate `gql.tada` into the project and replace existing GraphQL Code Generator configurations.
2. Update documentation and provide guidelines for using `gql.tada` in the codebase.
3. Monitor the adoption and gather feedback from the development team to ensure a smooth transition.

## References

- [gql.tada Documentation](https://gql-tada.0no.co/)
- [GraphQL Code Generator Documentation](https://the-guild.dev/graphql/codegen)
4 changes: 3 additions & 1 deletion front/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Readme

This front-end project of Boxtribute was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
This front-end project of Boxtribute was bootstrapped with [Vite](https://vite.dev/).

## Table of Contents

Expand All @@ -13,6 +13,7 @@ This front-end project of Boxtribute was bootstrapped with [Create React App](ht
4. [Testing](#testing)
5. [Conventions for file and folder organisation](#conventions-for-file-and-folder-organisation)
6. [About Apollo](#apollo)
7. [Types and GraphQL](#types-and-graphql)

## Development Set-Up

Expand Down Expand Up @@ -55,6 +56,7 @@ docker compose exec front pnpm format:write
- no console.log
- no debugger statements
- no vars
- prefer types over interfaces
- interfaces/type should start with "I"

## Note about pnpm and Docker
Expand Down
Loading