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

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
griffinbyatt
Sobelow Sobelow is a security-focused static analysis tool for the Phoenix framework. For security researchers, it is a useful tool for g...
New
AlexMcConnell
The reason that Rails is as popular as it is is because it’s very easy for relatively inexperienced developers to get a lot of work done....
588 19568 166
New
und0ck3d
Hello everyone! A few days ago I’ve created a topic here about how people were creating CMSs with Elixir and Phoenix. I’ve been studying...
New
acrolink
How does the two languages compare when it comes to server side application development? Any experiences or ideas? Thank you.
New
WildYorkies
It seems that the more I read, the more I find Elixir users speaking about all the ways that Elixir is not good for x, y, and z use cases...
New
vans163
So useless benchmarks aside, Its possible to write a webserver that can serve 300k requests per second (perhaps more with optimizations)....
New
chuck
Let me start by stating an assumption: Phoenix is a great approach to building REST APIs. There are many reasons for this, but I will ass...
New
arpan
Hello everyone :wave: Today I am very excited to announce a project that I have been working on for almost 3 months now. The project is...
New
Rustixir
Hi everyone, im working on find best language/framework/system for high concurrency, high performance and stable performance after wor...
New

Other popular topics Top

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
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
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
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
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
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
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

We're in Beta

About us Mission Statement