itopiz
In my GraphQL schema, I am using an authentication middleware similar to the one in the documentation. This middleware is set for all mutation fields.
In some mutation fields, I also want to use the Absinthe.Relay.Node.ParseIDs middleware.
In case a user is not authenticated and submits a mutation with an input that does not pass the ParseIDs middleware, the server returns the error message:
In argument \"input\": In field \"userId\": Could not decode ID value `foobar'
but I was expecting:
unauthenticated
After reading the Absinthe.Middleware documentation, I understand that both the authentication and ParseIDs middlewares are run anyway.
All middleware on a field are always run, make sure to pattern match on the state if you care.
When no user is authenticated, is there a way to receive the error message “unauthenticated” regardless of the input provided?
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 9- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
benwilson512
Are you not getting the unauthorized error at all? Or are you getting both unauthorized AND the parseids error?
What absinthe / absinthe_relay error are you getting?
itopiz
I only get the
ParseIDserror message if no user is authenticated and theuserIdis invalid. If no user is authenticated and theuserIdis valid, then I get the error message from the authentication middleware.benwilson512
How are you setting up the middleware?
itopiz
The authentication middleware is setup in the schema:
Here is my authentication middleware:
itopiz
And the
ParseIDsmiddleware is setup this way:itopiz
For information, there is no problem when I also use
Absinthe.Relay.Mutation.Notation.Modernand setup theParseIDsmiddleware this way:tspenov
@itopiz
changes the state of the
Resolutionstruct toresolved.So you can add a clause in
ParseIDsmiddleware to catch this case and pass like this:itopiz
Thank you for the suggestion. However, the ParseIDs middleware being part of the absinthe_relay project, I cannot change it.
benwilson512
The ParseIDs middleware should definitely be pattern matching on the unresolved state, I’ll look at fixing that today.