graphql-crystal icon indicating copy to clipboard operation
graphql-crystal copied to clipboard

Allow for customized/templated error hash creation

Open jney opened this issue 7 years ago • 4 comments

Hello. Maybe i missed it in the documentation, is there a way to customise error adding fields?

jney avatar Aug 18 '17 21:08 jney

I don't understand what you mean. Whenever a resolve method raises an error the resolved field is set to nil and an error is added to the response with the message of the raise.

ziprandom avatar Aug 19 '17 13:08 ziprandom

i will try to be more explicit. some people are customizing error fields, for example: https://medium.com/@tarkus/validation-and-user-errors-in-graphql-mutations-39ca79cd00bf so i was wondering if this kind of thing could be accomplished

jney avatar Aug 19 '17 17:08 jney

This is an interesting feature which is unavailable in the current implementation as it only tracks Errors with a path and a message in the form of a Tuple alias Error = { message: String, path: Array(String|Int32) }. This architecture could be changed to track a path and an Exception (which really could be any user defined subclass of Exception) and then provide functionality for a user defined callback to render the array of errors into the a hash of the desired the form. I don't know what priority to give to such a feature..

ziprandom avatar Aug 21 '17 19:08 ziprandom

For earlier I apologize I do not know English exceptions slower it is better to use a class or format: GraphQL::Error/GraphQL::ResponseError or {:error, data} aka Elixir

Stanislav-Lapata avatar Dec 24 '17 17:12 Stanislav-Lapata