ryanswapp

ryanswapp

Phoenix GraphQL Tutorial with Absinthe: Add CRUD Using Mutations

I wrote up the second post in a series I’m doing on using Phoenix and Absinthe to build GraphQL API’s. In this post I cover adding CRUD functionality with mutations. Please let me know if you have any questions. Happy to help in any way that I can!

https://ryanswapp.com/2016/12/03/phoenix-graphql-tutorial-with-phoenix-add-crud-using-mutations/

Most Liked

bruce

bruce

Author of Craft GraphQL APIs in Elixir with Absinthe

We’ll get this out soon. We actually have it driving the Phoenix CRUD scaffolding with very minimal edits (including queries and mutations). Just some work around serialization (eg, views probably don’t want serialized time structs they then have to deserialize) and some utilities for error feedback before we push this out there.

Here’s a sneak peek of working code. Note the 3-arity actions; Absinthe processes input using the associated document, hands off result to action for response. It is pretty cool to have your Absinthe schema handle the complexities of input validation and database operations and just focus on what to show them!

  @graphql """
  mutation ($id: ID!, $user: InputUser!) {
    user: update_user(id: $id, input: $user) { ... UserFields }
  }
  """
  # Note: The "UserFields" fragment used above is defined by the View, as
  #       it's a view concern.
  def update(conn, %{user: user}, []) do
    conn
    |> put_flash(:info, "User updated successfully.")
    |> redirect(to: user_path(conn, :show, user))
  end
  def update(conn, %{user: user}, _errors) do
    conn
    |> put_flash(:error, "An error occurred.")
    |> redirect(to: user_path(conn, :edit, user))
  end
benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

You’re my hero for making these!

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

We have an experimental library that does exactly this. Let me see if we can carve out some time this week and get a beta released.

Where Next?

Popular in Discussions Top

jeramyRR
This is an interesting article to read. Elixir’s performance, like usual, is excellent. However, it seems like the high CPU usage is co...
New
New
axelson
Decided against including more info in the title, but the gist is that Plataformatec sponsored projects will continue with the assets bei...
New
arcanemachine
https://nitter.net/josevalim/status/1744395345872683471 https://twitter.com/josevalim/status/1744395345872683471
New
Ankhers
Just a little information upfront. Generally speaking, if I feel like I need to either break a pipe chain or use an anonymous function in...
New
fireproofsocks
I’ve been working on an Elixir project that has required a lot of scripting. I usually reach for Elixir because I like it more (and in th...
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
acrolink
How does the two languages compare when it comes to server side application development? Any experiences or ideas? Thank you.
New
scouten
I’m looking for a host for the server part of a small (personal) side project that I’m working on. It’s currently written in Node.js and ...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

Other popular topics Top

mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 53690 245
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52341 488
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
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

We're in Beta

About us Mission Statement