[REQUEST] Add batch grouping
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 35/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- graphql, javascript
- Ambito
- backend-api-design
Direzione di ricerca
Inizia dal costruttore di DataLoader e rivedi l’opzione esistente cacheKeyFn e il comportamento di batchLoadFn. Definisci come batchGroupFn debba suddividere le chiavi, quante chiamate a batchLoadFn debbano essere effettuate e come i risultati rimangano allineati alle chiavi di input; il lavoro è completato quando il comportamento di raggruppamento proposto è specificato e coperto dai test.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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?
- Lingua principale
- JavaScript
- Stelle
- 13.4k
- Fork
- 522
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di graphql/dataloader
-
[BUG] `maxBatchSize: NaN` is accepted and silently disables batchingForse già presa @RaphaelFakhri l’ha presa 2 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
graphql/dataloader#405 ·
-
Failed batch evicts a replacement cache entry after clear/primeForse già presa @Claire-ovo l’ha presa 11 giorni fa. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 57/100
graphql/dataloader#403 ·
-
enhancement
Difficoltà 5/5 Più di una settimana Idoneità per principianti 38/100
graphql/dataloader#393 ·
-
enhancement
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
graphql/dataloader#382 ·
-
enhancement
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
graphql/dataloader#379 · 2 commenti · 5 reazioni ·
Tutte le issue di graphql/dataloader
Issue simili
-
binding:python bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
bug needs-triage potential-regression
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
aws/aws-sdk-js-v3#8408 ·
I maintainer di solito rispondono entro 1 giorno
-
[v3] KeyBindingManager calls (Add/Remove) are not converted into a case-insensitive accelerator.KeyApertaBug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 4 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100