validationErrors in info argument?
Closed this issue · 5 comments
alexstrat commented
The extra argument validationErrors
is visible in the produced schema while, apriori, the client does not need to know it exists.
Wouldn't be better injected in the info
argument of resolver?
createUser(_, args, ctxt, info) {
if(info.validationErrors && info.validationErrors.length) {
// guess i should throw
}
}
barbieri commented
hum... this is a good point, we could inject it in info
indeed, is that more common than using args
?
cabelitos commented
I like the idea, I think that this can also be done for the @hasPermission directive
barbieri commented
@alexstrat on your message, 2 remarks:
- there is no need to check length, it should contain elements if it's an array, avoiding the need to check twice.
- "guess I should throw" depends. If the elements are NON nullable, then it will throw and the resolver is not even called. The
validationErrors
will be filled if some nullable property failed and it was converted tonull
. Matches the output logic: if a resolver fails it will record inresult.errors
and the specific field is madenull
, respecting the "bubble" effect up to the first nullable object, if none is nullable (ie: arg is non-null), then it will not call the resolver.
The idea is that the resolver may use nullable objects and get a sanitized version, having the option to look at validationErrors
to know if they are critical or not on its own -- ie: eventually use some default, etc.
cabelitos commented
fixed on 2.0.0 (available on NPM right now)