DEV Community

Cover image for Clean Code Tip: Create a Service Object and Improve Your GraphQL Mutations in Rails

Clean Code Tip: Create a Service Object and Improve Your GraphQL Mutations in Rails

Sulman Baig on February 20, 2023

As a developer, one of the most important aspects of writing code is making it easy to understand, maintain, and scale. This is where the concept o...
Collapse
 
yet_anotherdev profile image
Lucas Barret • Edited

Really good article ! Do you think that it is always worth it to create a service layer for your queries in graphql?
I feel that often we just fetch a model with find or something like this, and it will be much work to do it like this.
Of course when you have more than just boilerplate code it's worth.
The more I gain experience in coding, the more I feel like it is always a tradeoff. 👀
What do you think :D

Collapse
 
sulmanweb profile image
Sulman Baig • Edited

You are right sometimes it looks like more than the required effort. But this is code in progress l. So in future if I need more validations, some extra service to be called like subscribing user to newsletters, or send email to user, or sending slack message when user signs up then business logic separation would look very nice. And most importantly when repo will get a lot big then this separation of models actions and business logic separation will look very beautiful and easy for onboarding engineers. Thinking of long term project makes it worth it in my opinion.

Collapse
 
yet_anotherdev profile image
Lucas Barret

Of course I understand, like I said I think it is a question of tradeoff.
What has the most value in your opinion, I mostly agree with you for the developper experience of the future onboarded.