hey guys! how do you design the resolvers so that ...
# random
t
hey guys! how do you design the resolvers so that it wont clutter so much? Like i m using the howtographql example (
resolvers/Query.js
,
resolvers/Mutation.js
)... can I divide them into let's say
User/Query.js
and
User/Mutation.js
and other models following the same design?
a
It's just Javascript files, so as long as you require them correctly, you can divide them any way you want.
👍 1
a
For bigger projects, I think having a
resolvers
folder with
queries
and
mutations
as subfolders is also useful. Alternatively, you can have queries and mutations grouped together by the types. As in
my_app/src/users/queries.js
,
my_app/src/users/mutations.js
I find the latter to scale better with repo size to be honest, but it's a bit harder to fathom sometimes.
e
In my projects, I have a
resolvers
folder with a few files (user.js, stuff.js, ...). In each of these file, I do the following:
Copy code
export {
  Query: {
    myQuery1: ...
  },
  Mutation: {
    myMutation1: ...
  }
}
Which is better to group the logic I think
a
@Errorname : What do you do if a mutation connects a
user
to an object (say
post
or
comment
)?
e
I'm not sure I understand your question. Are you talking about a user mutation which calls a post mutation ?
Or about a mutation which links a user to a post ?
a
The last one
Do you then put it in
posts.js
or
user.js
?
e
Well, it depends. First, I would do the connection directly in the
createComment
mutation. But if you specifically want a mutation which only connect the two, I would probably put it in comments.js as User is kind of a "super-object" (used nearly everywhere). Let's imagine you wanted to completely remove the comment feature of your app: You would only need to delete the
comments.js
file!
But I agree it's not the only solution
a
I think it’s a good solution. I was just curious how you would solve that one
t
the way i m using is having
resolvers/Customer/Customer.js
as the class, then
resolvers/Customer/Mutation.js
as the mutation and
resolvers/Customer/Query,js
as the queries... so per model per directory