thezjy

thezjy

How to create a Relay edge?

Say my schema defines a todo object and a todos Relay connection. Right now there are methods like Absinthe.Relay.Connection.from_query to help create resolve that connection. And it works great.

My question is if I have a Relay mutation payload field :add_todo which returns a todo edge, is there any helper method for building that edge? Or we can do this by hand?

First Post!

kokolegorille

kokolegorille

It seems strange to answer a create mutation with a relay edge instead of a todo item.

Could You show your resolver?

Most Liked

thezjy

thezjy

Thanks for the reply. But I don’t see why it’s strange. :smile: The official relay example actually does this. That seems the only way to add to a connection?

I actually figured out a way, assuming the new todo is added to the end:

def some_resolver(_, args, _) do
  todo = SomeContext.create_todo(args)
  count = Repo.aggregate Todo, :count, :id 
  offset = count - 1
  cursor = Absinthe.Relay.Connection.offset_to_cursor(offset)

  {:ok, %{todoEdge: %{cursor: cursor, todo: todo}}
end

Where Next?

Popular in Questions Top

baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

Other popular topics Top

jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
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
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

We're in Beta

About us Mission Statement