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
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
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.
Last Post!
zimt28
This would be great! Looking at this discussion, quite some people are building core, web and api applications, but using this it might be possible to have the api as the core and use it on the server in web ![]()
Popular in Discussions
Other popular topics
Latest Phoenix Threads
Chat & Discussions>Discussions
Latest on Elixir Forum
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex










