Skip to content
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

Add multiple errors - with correct nesting to a query #1282

Closed
axos88 opened this issue Feb 15, 2018 · 2 comments
Closed

Add multiple errors - with correct nesting to a query #1282

axos88 opened this issue Feb 15, 2018 · 2 comments

Comments

@axos88
Copy link

axos88 commented Feb 15, 2018

Related to #629:

Thanks for giving that tip on ctx.add_error in the referenced issue. I'm wondering if it's possible to add an error for a subfield/argument?

For example in case of multiple validation errors, in the field's resolve function I would like to add an error that that the argument item_no was out of bounds, and the argument commission cannot be set if the commission_type is not set.

ctx.add_error would return the query in the fields field of the error, whereas it would be much more self-explanatory (and easier for the frontend), if it were the erroneous argument, so it would not need a complex decision logic to show it to the user.

I'm thinking something like ctx.get_context_for(:item_no).add_error(...)

@axos88
Copy link
Author

axos88 commented Feb 15, 2018

Ok, I found a way, although it is a bit cumbersome:

e = GraphQL::ExecutionError.new('message')
e.path = ctx.path + ["item_no"]
ctx.add_error(e)

@rmosolgo
Copy link
Owner

Glad you found a solution! I think a new mutation API could provide better support for this, I'll keep it in mind at #1275

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants