I am having trouble deciding how to separate business logic in GraphQL Apollo Server with Prisma.
My design is "Schema First" and types are generated with graphql-codegen
Using prisma and manipulating data in resolvers is not good enough since there are some restrictions that need to be imposed (eg some things need to be done in transactions etc.). So as the project grows, things get very convoluted and messy.
What is a good project structure for large scale projects?
Are controller classes a good idea? If so, how what would it look like with prisma?
Currently I have
│ context.ts
│ main.ts
│ prisma.ts
│
├───controller
│ index.ts
│ inventory.ts
│ parts.ts
│ cars.ts
│ companies.ts
│ quotes.ts
│
├───resolvers
│ │ index.ts
│ │ Mutation.ts
│ │ Query.ts
│ │ Subscription.ts
│ │
│ ├───company
│ │ company.query.ts
│ │
│ ├───inventory
│ │ inventory.mutation.ts
│ │ inventory.query.ts
│ │
│ ├───part
│ │ part.mutation.ts
│ │ part.query.ts
│ │
│ ├───car
│ │ car.mutation.ts
│ │ car.query.ts
│ │
│ └───quote
│ quote.query.ts
│
└───schema
company.ts
index.ts
inventory.ts
part.ts
car.ts
quote.ts
Currently, the files in controller contain some functions, and they are available in context, for example context.cars.checkMilage()
Aucun commentaire:
Enregistrer un commentaire