memery

memery OP

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

First Post! Switch mode

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Hi @memery the dataloader/1 helper, by default, sets a key of {field_identifier, field_args}.

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
michallepicki
I am using Oban and occasionally, shortly after a deployment, a handful of jobs can fail because of dependency on other parts of the syst...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New

We're in Beta

About us Mission Statement