You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
Hey, thanks for the detailed writeup. I also don't know of any way of getting the current input path.
I'm open to adding it but I think the trick will be finding an implementation that handles possible fiber switches while maintaining compatibility.
In the meantime, you could reduce boilerplate by adding prepare: ... programmatically, for example:
classTypes::BaseArgument < GraphQL::Schema::Argumentdefinitialize(...)superif@prepare.nil? && @type.respond_to?(:build_prepare_proc)@prepare=@type.build_prepare_proc(@name)# could use @name.underscore.to_sym here insteadendendend
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 thoseprepare
methods automatically generate error messages based on the path to the input object.For example, given
We would like the error message to contain
input
orsomething_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.
Which works but is of course a bunch of duplicative boilerplate.
The text was updated successfully, but these errors were encountered: