-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Custom scalar CoercionError clobbers parent messages #1020
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'm not really sure what the solution is here. @rmosolgo any ideas here? I can't immediately see anything that would be easy 😔 |
Put a rescue at the bottom of Actually, I just remembered #160 which I filed a long time ago - do we even want an error on the parent field in this case? It's kind of redundant. |
I kind of agree. It's very redundant for these errors to bubble up to every parent input object. |
I kind of think +1 to just having the error only for the field in question and no bubble up. The error message includes the full path array to the error. So if you wanted to just scan for a general failure of the parent object you could do so. I think the only considerations would be that it's a potentially breaking change from current functionality, as well as is there ever a case where the parent would/could have a different and more specific message. |
Yeah, 👍 from me too to stop bubbling up 😬 For reference, here's the GraphQL-js behavior: |
was there any movement on this? i'd be happy to help, i'm just not sure where to start (i assume this should be a configurable option to keep backwards compat) |
how about changing edit: i just tried this approach and it seems to solve the bubbling issues we are seeing: https://github.com/modosc/graphql-ruby/commit/ead5ef8804ac062957d2b085d03bf330071b2ad2 if this direction seems ok i'll finish it and do a pr. |
ok, just updating with some notes/findings. i had assumed that validation worked it's way from the bottom up, but it's actually the opposite. so consider this is also why the error messages appear at the top level ideally we could cache the validations that are being done - there's no real reason to do these more than once, right? anyway, this also made me change my approach to "solving" this problem. now i'm thinking that raised exceptions should include the i'm currently working on something else right now but i expect to pick this up again next week. i'll also file a separate issue about caching the validations. |
When a non-top level field has a custom scalar type that raises a coercion error. The coercion error message overwrites the parent's error message.
This gist shows the difference between a coercion returning nil, raising a
CoercionError
, and what the expected output would actually be.https://gist.github.com/dnd/c9d6cbf18880f8fd916f962a7e10ca9e
This is from a block of code that looks like this:
Please ignore the non-sensical use of the name
num
. :)It would also be nice if instead of only displaying the coercion error message, that the error message be appended to the default string describing which field actually failed. Because as far as I can tell there is no way to determine inside of the coercion what the specific field, or parent is such as
num
, orInputObject 'CredentialsInputObject'
."Argument 'num' on InputObject 'CredentialsInputObject' has an invalid value. #{coercion_error.message}"
The text was updated successfully, but these errors were encountered: