idi527
How to get the error message from absinthe
Right now i get an unnecessary (to me) In field "signUp": in front of the actual message:
{
"errors": [
{
"message": "In field \"signUp\": should be at least 3 character(s)",
...
"key": "username"
},
{
"message": "In field \"signUp\": should be at least 6 character(s)",
...
"key": "password"
}
]
...
}
But i would like to just get "should be at least 6 character(s)" in the "message" fields. Is this possible? Or is there some other way to access this message?
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
Using Phoenix.LiveView.TagEngine as an EEx.Engine is deprecated!
To compile HEEx, use Phoenix.LiveView.TagEngine.compile/2 instead.
Sta...
New
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app?
Looking for hints regarding:
Addi...
New
Hi all, I wanted to ask how the community is dealing with post-release steps.
Today we have Ecto migrations, which make sure that the db...
New
I am using Oban and occasionally, shortly after a deployment, a handful of jobs can fail because of dependency on other parts of the syst...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #performance










First 9 of 9 Posts
idi527
I’ve decided to add an additional
"error"field to put the error message in.benwilson512
Hey there! Your solution is definitely one approach.
By way of analogy, you can kind of think of GraphQL errors like exceptions in a regular programming language. They aren’t return values from the field, but rather field execution errors that bubble up to the top.
For errors like you’re trying to expose there’s another pattern that uses a union type to represent that a field may return validation errors. Here’s an example:
And here’s how you’d use this in a document:
This is a lot like the difference between Elixir functions that return
{:ok, result} | {:error, reason}and functions that simply return the result or raise.idi527
Thanks! It seems like i need to learn more about both Absinthe and GraphQL.
idi527
I’ve tried the union operator but whenever I supply an invalid username/password pair so that to get
ValidationErrorI keep getting this error insteadHere’s my
schema.exschema/types.exand
resolver/session.exand the document I send
idi527
I’ve replaced
list_of(:validation_error)with:validation_errorsadded
validation_errorstypeand updated
session.exto return%{errors: ...}mapand now it works. The document I send now is
I wonder if there is a shorter solution which doesn’t require defining a new type.
benwilson512
Unfortunately no not at the moment. The reason returning
list_of(:valication_error)didn’t work is thatlist_ofis really a type modifier as far as GraphQL is concerned, rather than a proper generic type of the formList<T>. Practically speaking I think the reason is that any given key that is requested should always be a list of a type or a regular type, but never sometimes one and sometimes the other.We are looking to perhaps support some schema tools that would make this pattern less verbose and more first class, but at the moment I believe what you have here is the best for now.
rafbgarcia
I’m trying to implement this solution, and it’s kind of working but something unexpected is going on, I’m getting this error:
This is my code:
I import this in my schema:
And this is my resolver:
Any ideas on what’s going on?
FWIW this is what I see in the console: see gist
It returns a function with my return value and Absinthe.Resolution as a second param.
benwilson512
Hey! You may be confused about what gets passed to the
resolve_typefunction.You should just be doing:
rafbgarcia
That worked \o/ Thanks (for the fast answer too)!