A serialized GraphQL error when having a type mismatch when sending an argument from a custom scalar
I've got this custom Scalar (UUID)
defmodule Bigseat.Schema.Scalars.Uuid do
use Absinthe.Schema.Notation
alias Ecto.UUID
scalar :uuid, name: "UUID4" do
description("""
The `UUID4` scalar type represents UUID4 compliant string data, represented as UTF-8
character sequences. The UUID4 type is most often used to represent unique
human-readable ID strings.
""")
serialize(&encode/1)
parse(&decode/1)
end
@spec decode(Absinthe.Blueprint.Input.String.t()) :: {:ok, term()} | :error
@spec decode(Absinthe.Blueprint.Input.Null.t()) :: {:ok, nil}
defp decode(%Absinthe.Blueprint.Input.String{value: value}) do
UUID.cast(value)
end
defp decode(%Absinthe.Blueprint.Input.Null{}) do
{:ok, nil}
end
defp decode(_) do
{:error}
end
defp encode(value), do: value
end
I use it on a query space and when I send a valid UUID such as abe0b120-9d23-44f1-8046-ce485940a42d it passes, but when I send something like 1 on purpose it completely crashes instead of validating in a clean and readable way what's happened.

It goes through {:error} as intended, but why isn't it showing an error with the GraphQL format?
# CaseClauseError at POST /graphql\n\nException:\n\n ** (CaseClauseError) no case clause matching: {:error}\n (absinthe 1.6.1) lib/absinthe/phase/document/arguments/parse.ex:44: Absinthe.Phase.Document.Arguments.Parse.build_value/3\n (absinthe 1.6.1) lib/absinthe/phase/document/arguments/parse.ex:24: Absinthe.Phase.Document.Arguments.Parse.handle_node/2\n (absinthe 1.6.1) lib/absinthe/blueprint/transform.ex:16: anonymous fn/3 in
Hi @Loschcode, the correct value to return from a scalar is :error, not {:error}. I would also make sure that UUID.cast(value) returns :error in the event of a failed cast and not something like {:error, reason}.
Ah stupid mistake! Hope it helps people making it too, thanks for the quick response 馃憤
Most helpful comment
Hi @Loschcode, the correct value to return from a scalar is
:error, not{:error}. I would also make sure thatUUID.cast(value)returns:errorin the event of a failed cast and not something like{:error, reason}.