Proposal: Allow `calls_gitaly` to take a proc
Problem to solve
We have the ability to mark GraphQL fields with the calls_gitaly: keyword to increase the complexity of fields that make calls to Gitaly (MR: !14529 (merged)).
The calls_gitaly keyword value must be an object that is truthy. We have a need now for the value to be evaluated using the object being returned.
Further details
We have (at time of writing) a field that only calls Gitaly when a property of the object is a certain value (specifically, when the target_type property of a Todo is Commit) #34757 (comment 234752665).
This field currently uses calls_gitaly: true (MR: !19052 (merged)) to cover the situation where Gitaly is called, however, ideally we could allow calls_gitaly to evaluate based on properties of the object.
Proposal
One proposal is for calls_gitaly to take a proc, that would be evaluated against the object being returned:
# Ideal, but likely not possible!
calls_gitaly: -> (todo, _args, _context) { todo.for_commit? }
But, this may be impossible to do (OP hasn't dug particularly deep into the existing instrumentation!) or there may be other/better ways! The above is a proposal.
Permissions and Security
Will not apply, as this will not affect data returned.
Documentation
We should document the calls_gitaly in our GraphQL API Styleguide so developers can know that it exists and how to use it (it's currently missing!).