We are implementing prepare methods on several input objects. They do some validation, and may raise/return various errors in those cases. We would like to have those prepare methods automatically generate error messages based on the path to the input object.
For example, given
class MyInputType < GraphQL::Schema::InputObject
def prepare
raise GraphQL::ExecutionError, "some error message"
end
end
# elsewhere
argument :input, MyInputType
argument :something_else, MyInputType
We would like the error message to contain input or something_else as appropriate, but there does not appear to be a way to access that information at the moment.
context.current_path exists, but only includes field names, not the (potentially many) argument names needed to get to the currently-preparing argument.
Describe the solution you'd like
Maybe context.current_argument_path is possible? Or maybe there are reasons this is really tricky?
In general we only need the last element, i.e. the name of the specific argument that holds the current input type, so some sort of parent access would also work. TBH I thought that already existed, but I couldn't find the right incantation.
Describe alternatives you've considered
We currently define our prepare methods as class methods returning procs, and then do e.g.
argument :something_else, MyInputType, prepare: MyInputType.prepare(:something_else)
Which works but is of course a bunch of duplicative boilerplate.
We are implementing
preparemethods on several input objects. They do some validation, and may raise/return various errors in those cases. We would like to have thosepreparemethods automatically generate error messages based on the path to the input object.For example, given
We would like the error message to contain
inputorsomething_elseas appropriate, but there does not appear to be a way to access that information at the moment.context.current_pathexists, but only includes field names, not the (potentially many) argument names needed to get to the currently-preparing argument.Describe the solution you'd like
Maybe
context.current_argument_pathis possible? Or maybe there are reasons this is really tricky?In general we only need the last element, i.e. the name of the specific argument that holds the current input type, so some sort of
parentaccess would also work. TBH I thought that already existed, but I couldn't find the right incantation.Describe alternatives you've considered
We currently define our prepare methods as class methods returning procs, and then do e.g.
Which works but is of course a bunch of duplicative boilerplate.