DEV Community

Discussion on: Writing GraphQL Resolvers

Collapse
 
yaldram profile image
Arsalan Ahmed Yaldram

Hello Sir, Thanks for the awesome post. Even I used GraphQL a lot but I never tried resolving the fields as you did, I mean traversing the tree. Thanks again. What I used to do is instead of a query called university I would call it getUniversityInfo and then using Sequelize and Mongoose Fetch all Info along with its relations. The Downside is over fetching yes but I would use the Params I get in my resolvers and the use select() to get a particular field or use a switch for fetching relations.

I also had a query given that colleges are an array of strings when we resolve it fields in every resolver we are going to get the same name, right for Colleges Resolver to work it should return an array of objects.

Collapse
 
thomasstep profile image
Thomas Step

Hi there, I am glad that you got some use out of the post! To answer your question, colleges (and in the example repo getColleges) is only called once, and the child resolvers or any other branches that stem from there are called once per item in the array. colleges/getColleges will always only be called once with its parent being university's return which is { name: args.name } in the post. Did that answer your question?