Creating GraphQL APIs Using Elixir Phoenix and Absinthe

The mutation is defined in lib/graphql_web/schema/schema.ex while the input parameter values are defined in lib/graphql_web/schema/types.ex —input_object :update_post_params do field(:title, :string) field(:body, :string) field(:accounts_user_id, :id)endThe difference with previous type definitions is that it’s defined as input_object instead of object.The corresponding resolver function is defined as follows:def update(%{id: id, post: post_params}, _info) do case find(%{id: id}, _info) do {:ok, post} -> post |> Blog.update_post(post_params) {:error, _} -> {:error, "Post id #{id} not found"} endendHere we have defined a query parameter to specify the id of the blog post to be updated.ConclusionThis is all you need, to write a basic GraphQL server for any Phoenix application using Absinthe.References******************************************************************Velotio Technologies is a software engineering firm, with core expertise in Data Science, Machine Learning and DevOps..Our modus operandi is working with the latest transformative tech to turbocharge customer success.Interested in learning more about us?.We would love to connect with you on our Website, LinkedIn or Twitter.*******************************************************************. More details

Leave a Reply