I’m raising an error inside a resolver with. I would like Absinthe Middleware to handle it, so I can display it to the frontend team. However when the error raises, the resolution
variable doesn’t have any errors inside it.
What would I be doing wrong?
def check(questions) do
case questions do
nil -> raise ArgumentError, message: "Invalid number of questions."
_ -> some_extra_stuff
end
end
raise ArgumentError, message: "Invalid number of questions."
defmodule MyApp.Schema.Middleware.ArgumentErrors do
@behaviour Absinthe.Middleware
@impl true
def call(resolution, _) do
IO.inspect resolution
resolution
end
end
defmodule AdmissionWeb.Schema do
use Absinthe.Schema
alias AdmissionWeb.Schema.Middleware
alias Admission.{Accounts, Exams}
def dataloader() do
Dataloader.new
|> Dataloader.add_source(Accounts, Accounts.data())
|> Dataloader.add_source(Exams, Exams.data())
end
def context(ctx) do
Map.put(ctx, :loader, dataloader())
end
def plugins do
[Absinthe.Middleware.Dataloader | Absinthe.Plugin.defaults]
end
def middleware(middleware, _field, %{identifier: :mutation}) do
middleware ++ [Middleware.ArgumentErrors]
end
def middleware(middleware, _field, _object) do
middleware
end
end