raphexion

raphexion

When using Absinthe Controller, what is the correct way to massage data before it goes into the mutation

Hey,

I’ve created a Absinthe schema that is working. Just for fun I want to try to integrate and learn Absinthe.Phoenix.Controller. So that I can reuse the same schema in a “classic” controller solution.

I’ve started from the auto-generate code that I get from this

mix phx.gen.html Todos TodoList todo_lists name:string

index as easy to implement by just following the documentation.
However, from create I got a little stuck.
Here is my stripped controller.

defmodule BackendWeb.TodoListController do
  use BackendWeb, :controller
  use Absinthe.Phoenix.Controller, schema: BackendWeb.Schema, action: [mode: :internal]

  @graphql """
  mutation CreateTodoList($name: String!) {
    create_todo_list(name: $name)
  }
  """
  def create(conn, result) do
    # ...
  end
end

When I press the button from http://localhost:4000/todo_lists/new I get

Parameters: %{"_csrf_token" => "..", "todo_list" => %{"name" => "Have fun"}}

I think the mutation needs a %{name: "Have fun"}. Which means that I need to unpack the incoming request body.

Which is the correct way to massage the incoming data from the form so it fits with the GraphQL query. I want to ask before I try to hack my own solution.

Any help is greatly appreciated.

Most Liked

raphexion

raphexion

Thank you @krasenyp for the help. I agree that it might not be the best idea. However, I notice that there is a mutation example in the book (page 207).

Great suggestion about the query parameters example. I didn’t make the connection when I read the documentation. I was so focused on keeping the GraphQL statement the same (as if I called it externally over the API).

Once again, thank you for your reply, I will try it out.

krasenyp

krasenyp

I think the original idea is to use the Absinthe controller with GraphQL queries. I don’t see why you’d want to use it the way you tried. Nevertheless, the docs show an example usage and the data for the query comes from the request’s query parameters - Absinthe.Phoenix.Controller — absinthe_phoenix v2.0.5.

Where Next?

Popular in Questions Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lists...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call t...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New

Other popular topics Top

baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
Nvim
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help. Where are they similar? Where do they differ the m...
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 43757 214
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement