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.7.1
Marked As Solved
Popular in Questions
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
Hello all!
I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
Hi there,
I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
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
Student & New to elixir. Nice language.
I want to convert a english character, e.g. “a”, which is stored in a variable, to it’s asci...
New
Hey guys.
I'm new to elixir and im really stocked about it. But I ran into a bit of problem - I need to convert a date sting, for examp...
New
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
The Elixir Typespec docs show the following syntax for keyword lists in typespecs:
# ...
| [key: type] # keyword lis...
New
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum.
...
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
Other popular topics
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
I have followed this StackOverflow post to install the specific version of Erlang.
And When I am running mix ecto.setup then getting fol...
New
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode.
The solution seems to be, in a hyphena...
New
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
Hi,
I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
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
Hello everybody,
usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New







