[REQUEST] Add batch grouping
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 35/100
- issue の種類
- 機能追加
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- graphql, javascript
調査の方向性
DataLoader コンストラクターから始めて、既存の cacheKeyFn オプションと batchLoadFn の動作を確認します。batchGroupFn がキーをどのように分割するべきか、batchLoadFn の呼び出しが何回発生するべきか、結果を入力キーとどのように対応付けたままにするかを定義します。提案されたグループ化の動作が仕様化され、テストでカバーされれば完了です。
索引モデルが issue の本文から書いたものです。
説明
What problem are you trying to solve?
Handling different parameters in field resolvers with dataloader is tricky.
Let’s have this GraphQL schema:
type Order {
orderId: Int
status: String
}
type User {
userId: Int
name: String
orders(status: String): [Order!]
}
type Query {
GetUsers(search: String): [User!]
}
schema {
query: Query
}
Then we have query:
query {
GetUsers(search: "john") {
userId
name
ordersNew: orders(status: "New") {
orderId
status
}
ordersCompleted: orders(status: "Completed") {
orderId
status
}
}
}
Here orders resolver with dataloader:
User: {
orders: async ({ userId }, { status }) => {
return await ordersLoader.load({userId: userId, status: status});
}
},
Here ordersLoader with batchLoadFn:
const ordersLoader = new DataLoader(
async (params: { userId: number, status?: string }[]): Promise<Order[][]> => {
...
}
);
In this batch loader function we need to get orders from a database. If we have all orders stored in one table we can have single query, like:
SELECT * from Orders WHERE userId IN (:userIds) and status IN (:statuses)
Then loop through params and return the result. No real issues, so far.
Now let’s think orders in different statuses can’t be queried with a single query. For example, “New” orders are in “Online” db and “Competed” are moved in some “Archive” db. So, we need to have 2 queries. Then we need to build results properly based on input params. It is doable but even with this simple example not so easy. In real life we may have multiple parameters and we need to handle all permutations of them.
Describe the solution you'd like
I suggest adding a new option to DataLoader constructor. Very similar to existing cacheKeyFn – batchGroupFn?: (key: K) => C;. Based on result of this function batchLoadFn function needs to be called as many times as many different results gives batchGroupFn. I.e. I want to group batches by input keys.
For my example it would be:
batchGroupFn: (key: { userId: number, status?: string }) => (key.status??"")
So for each status it will be separate call of batchLoadFn. It will simplify this function a lot.
Please let me know if this solution is feasible. Or maybe there is alternative/better solution?
- 主要言語
- JavaScript
- スター
- 13.4k
- フォーク
- 522
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
graphql/dataloader のほかの issue
-
[BUG] `maxBatchSize: NaN` is accepted and silently disables batching対応中かも @RaphaelFakhri が 2 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
graphql/dataloader#405 ·
-
Failed batch evicts a replacement cache entry after clear/prime対応中かも @Claire-ovo が 11 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 57/100
graphql/dataloader#403 ·
-
enhancement
難易度 5/5 1週間以上 初心者へのやさしさ 38/100
graphql/dataloader#393 ·
-
enhancement
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
graphql/dataloader#382 ·
-
enhancement
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
graphql/dataloader#379 · コメント 2 件 · リアクション 5 件 ·
graphql/dataloader の issue をすべて見る
似ている issue
-
binding:python bug
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
bug needs-triage potential-regression
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
aws/aws-sdk-js-v3#8408 ·
メンテナーはふだん 1 日以内に返信
-
[v3] KeyBindingManager calls (Add/Remove) are not converted into a case-insensitive accelerator.KeyオープンBug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 4 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100