How to use Enum and Custom Scalars together in Absinthe?

Hello, welcome to the forum.

I use simple atoms, without as when I don’t need to use db, like so

  enum :sort_order do
    value :asc
    value :asc_nulls_last
    value :asc_nulls_first
    value :desc
    value :desc_nulls_last
    value :desc_nulls_first
  end

But if You want to persists Int in the DB and keep nice looking status, I would use a scalar. Nothing really complicate, You just need a parse and a serialize functions.

I use this for json.

  scalar :json do
    parse fn input ->
      case Jason.decode(input.value) do
        {:ok, result} -> result
        _ -> :error
      end
    end
    serialize &Jason.encode!/1
  end

And with your Enum requirement, it would be simple to write those 2 functions. For example…

scalar :status do
  parse fn 1 -> :green; 2 -> :yellow; 3 -> :amber; 4 -> :red; _ -> :error end
  serialize fn :green -> 1; :yellow -> 2; :amber -> 3; :red -> 4; _ -> :error end
end