What is the best way to modularize reducers and queries? #875
Replies: 1 comment 2 replies
-
Why do you ask that question in this repo? It's about I don't see any point of splitting resolver body into a separate If your resolvers perform some common tasks or contain some business-related logic, you should extract them to the service layer. It plays very well with classes and dependency injection. You can see that in examples on the main There is no best way because every developer, every team and every company has their own approaches. TypeGraphQL doesn't enforce anything. I can only share one special advice, regarding your question: The best way to modularize reducers and queriesMove files around until it feels right 😉 |
Beta Was this translation helpful? Give feedback.
-
I just switched over to using Type-GraphQL from Nexus and am loving it so far. However, there is one thing I am having issues with. I really like to have a more files, less code style of approach to my code, so I am trying to splice out my queries and mutations into their own files. The rough structure I am going with right now is:
So I am trying to keep each component of the API into its own folder, then separate the queries and mutations into their own folders. Firstly if you have a better architecture I would love to hear it...This was my 2 am solution. This isn't my real issue though, the thing I am having trouble with is importing and using those queries/mutations into one ProjectsResolver. My solution just looks really messing.
I first define a Resolve in the
index.ts
file like so:Then the
allProjects
function I imported from the queries.ts file looks like this:Right now this works but I want just one resolver for Projects, not a resolver for each sub folder under Projects. I also assume there is a cleaner way of splitting up these pieces of functionality.
I would love to hear your thoughts on how to tackle this and if you've done anything similar. Basically, what is the best way to keep my files small and easy to read.
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions