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

Start implementing a backend with code-first schemas #910

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

bbenoist
Copy link
Contributor

@bbenoist bbenoist commented Feb 22, 2022

Work performed

I've added a typescript/backend project which includes a backend based on NestJS and the following packages:

Results

  • Backend schema is code-first. You only declare once your entities.
  • You can switch the app to the new backend by defining the BACKEND_URL environment variable.
  • We can directly reuse the entities as types in our future Workflow system. Benefiting from all of what's been already declared in the backend schema.
  • DataLoader is supported! Most queries with children are batched 🎉

Problems encountered

  • I had to reproduce the NextJS JWT token decryption functions since the next-auth package depends on unwanted dependencies (i.e. React).
  • They are some behaviors in the current backend which I had to reproduce before we can change them:
    • LabelClasses must be ordered by index when queried to the DB
    • Some entities use slugs instead of ID to reference other entities in DB.
    • Nearly all mutations returns entities which we have to fetch in DB.

Caveats

  • It can be a long debate but code-first designs have their own advantages and drawbacks compared to schema-first
  • The backend is not loaded by NextJS. It's possible but not done yet as I wanted the old code to be still working on this branch and because of Deploy backend on Kubernetes #837
  • Most of the relation queries have been batched with DataLoader but:
    • The aggregates counts can't be batched in a single high-level repository call. We must use QueryBuilder.
    • Pagination is applied on the global batched query but it should be per-parent-id

Resolved issues

Closes #780

Newly raised issues

Here are the items I see so far:

  • Deploy backend on Kubernetes #837
  • Move the prototype to our repository
  • From Nest, decrypt JWT tokens signed and encrypted by next-auth
  • Forward /api/graphql queries to the backend when BACKEND_URL is set.
  • Make all queries work
  • Make all mutations work
  • Make sure that the entities are up-to-date with the latest GraphQL and Prisma schema revisions
  • Move the remaining bits (s3, exports, image uploads, emails?, etc) into the backend (to be refined)
  • Don't output entities in every mutation. They most often involve new DB calls and we have refetchQueries for that.
  • Add generic CRUD unit, acceptance and integration tests which runs on every entity types

Bonus:

@vercel
Copy link

vercel bot commented Feb 22, 2022

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/labelflow/labelflow/2hY8ec9oSyDYe4zDS2NznsJWR8fR
✅ Preview: https://labelflow-git-nest-backend-main-labelflow.vercel.app

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🍺 Simplify the architecture (i.e. merge data, common-resolvers, graphql-types and db)
1 participant