memery
Absinthe KV Dataloader Problems
I’ve got a KV Dataloader configured as:
defmodule FoobarWeb.Graphql.CircleMock do
require Logger
@circles {
%{id: "foo", name: "Foo"},
%{id: "bar", name: "Bar"}
}
def data() do
Dataloader.KV.new(&fetch/2)
end
def fetch(batch_key, ids) do
Logger.debug("fetch batch_key=#{inspect(batch_key)} ids=#{inspect(ids)}")
for id <- ids do
Logger.debug("id=#{inspect(id)}")
end
%{%{} => nil}
end
defp find_circle(id) do
Logger.debug("find circle #{id}")
@circles
|> Enum.find(fn(t) -> t |> Map.get(:id) == id end)
end
end
and a schema defined as:
defmodule FoobarWeb.Graphql.Schema do
alias FoobarWeb.Graphql.CircleMock
use Absinthe.Schema
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
require Logger
object :circle do
field :id, :id
field :name, :string
end
object :circle_queries do
field :circle_list, list_of(:circle), resolve: dataloader(CircleMock)
end
query do
import_fields(:circle_queries)
end
def context(ctx) do
loader =
Dataloader.new
|> Dataloader.add_source(CircleMock, CircleMock.data())
Map.put(ctx, :loader, loader)
end
def middleware(middleware, _field, %Absinthe.Type.Object{identifier: identifier})
when identifier in [:query, :subscription, :mutation] do
[FoobarWeb.Graphql.Auth | middleware]
end
def middleware(middleware, _field, _object) do
middleware
end
def plugins do
[Absinthe.Middleware.Dataloader] ++ Absinthe.Plugin.defaults()
end
end
When I issue a query I see this printed:
23:23:43.682 [debug] fetch batch_key={:circle_list, %{}} ids=MapSet.new([%{}]) { }
Basic on the docs shouldn’t the batch_key be just :circle_list? Have I done something stupid somewhere?
I based this on the docs available here: Dataloader — absinthe v1.11.0
Marked As Solved
Popular in Questions
Hi,
I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
I have a super simple question about elixir - how would I take a file like this
foo
bar
baz
and output a new file that enumerates th...
New
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum.
...
New
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
Hi everyone!
I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
Hi, I’m just starting to build a side-project with Elixir and Phoenix and doing some basic test with Elixir alone.
What strikes me is th...
New
Hello, I have map which I want to convert it to string like this:
the map:
%{last_name: "tavakkoli", name: "shahryar"}
the string I ne...
New
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
Other popular topics
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
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
Hello!
Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
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
If I have a post route which an argument:
post /my_post_route/:my_param1, MyController.my_post_handler
How would get the post params ...
New
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something…
Haskell reminds me of Java, and e...
New
Phoenix 1.4.0 released
Phoenix 1.4 is out! This release ships with exciting new features, most notably
with HTTP2 support, improved deve...
New
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
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
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this:
...
New
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
- #javascript
- #code-sync
- #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
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








