-
Notifications
You must be signed in to change notification settings - Fork 25
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
Clarification Question. Errors #23
Comments
Hi, Do you have a fork of this librarry that fixes this issue. We are experiencing the same issue and would not like to break the graphql standards. |
Not the OP, but we use the following helper currently: defp build_better_payload(%{errors: errors} = resolution, config) do
case errors do
# No errors -> build payload (successful=true with result)
[] -> build_payload(resolution, config)
# Changeset errors -> build payload (successful=false with error messages)
[%Ecto.Changeset{}] -> build_payload(resolution, config)
# Other errors -> keep as is, ie. render as top level "errors" in response
_ -> resolution
end
end (Used as |
I had a similar problem. I'm authenticating users with this middleware: defmodule MyApp.Schema.Middleware.Authenticate do
@behaviour Absinthe.Middleware
alias MyApp.Accounts.User
def call(resolution, _) do
case resolution.context do
%{current_user: %User{}} ->
resolution
_ ->
Absinthe.Resolution.put_result(resolution, {:error, :unauthorized})
end
end
end But if authorization fails, I want this to be an However, this is the only homegrown So my solution is to do something similar to @bforchhammer, except simpler because I don't need to handle the generic case: defp build_payload(%{errors: errors} = resolution, config) do
if :unauthorized in errors do
resolution
else
AbsintheErrorPayload.Payload.build_payload(resolution, config)
end
end That's in my |
Thanks for the great library, I've got a point of confusion I'd like help understanding.
This line confused me. Typically, my GraphQL responses have "data" and "errors" at the root. If, before passing into the build_payload function my resolution already has errors, I'm surprised they are being manipulated into the payload object and not being left as errors. That's what I though it meant by ERRORS should be returned as errors.
On the client side this gives me a bit of a problem. For example:
My ideal would be a change like this to the library, but please feel free to tell me why it'd a bad idea!
The text was updated successfully, but these errors were encountered: