raphexion

raphexion

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.

Showing Posts 1 to 2

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.

raphexion

raphexion OP

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.

— All posts loaded —

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
ChrisAmelia
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication): toke...
New
dillonoconnor
Is there any way to avoid the Hologram compiler running when using iex? It seems like the front-end code could potentially be disregarded...
New
thiagogsr
** (ArgumentError) expected :max_attempts to be a positive integer, got: {:@, [line: 10, column: 19], [{:max_attempts, [line: 10, column:...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews