Handling multiple errors coming from separate Absinthe middlewares


I have two Absinthe middlewares which are each doing validation. When the validation fails, an error is added to the resolution by calling Absinthe.Resolution.put_result/2. When both middlewares fail, only the error from the last middleware is preserved in the resolution (this behaviour is expected by looking at how put_result is written).

But graphql allows multiple errors to be returned in the response. The first validation error is also useful to know about. What is the best practice for returning multiple errors coming from separate middlewares like this?

Thanks in advance

Hey @chad-adams, in this case your middleware should just add errors to the resolution.errors key directly.


Thank you for the quick response!

Yes I thought about doing something like that. Looking at the implementation of put_result, I should probably also set the state to :resolved at the same time. I guess I’m a bit surprised Absinthe doesn’t provide a function for this out of the box and instead requires us to essentially roll our own put_result (that’s what led me to wonder whether I was going down the correct path here or if there was a different best practice…) Thank you for confirming.