0

Absinthe graphql スキーマに次のようなオブジェクトがあります。

object :match do
    field(:id, non_null(:id))
    field(:opponent, non_null(:string))
    @desc "The number of votes that have been cast so far."
    field(:vote_count, non_null(:integer), resolve: &MatchResolver.get_vote_count/2)
    # etc...
end

vote_count親を使用してectoクエリを実行するためのリゾルバーを使用していますmatch。ただし、一致のリストがクエリされる場合、これは n+1 クエリの問題に遭遇します。現在、次のようになっています。

  def get_vote_count(_root, %{source: %Match{} = match}) do
    count = match |> Ecto.assoc(:votes) |> Repo.aggregate(:count, :id)

    {:ok, count}
  end

私はすでにデータローダーを使用してエンティティをバッチロードしていますが、Absinthe が提供する関数を使用するときにカスタムrun_batch関数を動作させることができないようです。Absinthe.Resolution.Helpers.dataloader

dataloader/ecto を使用してカスタム バッチ クエリを実装するための推奨されるアプローチは何ですか? スキーマ定義部分を含め、誰かが例を挙げてもらえますか?

4

1 に答える 1