[REQUEST] Add batch grouping
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bastante claro
- Estado de actividad
- Estancado
- Stack tecnológico
- graphql, javascript
- Área
- backend-api-design
Línea de trabajo
Comienza en el constructor de DataLoader y revisa la opción existente cacheKeyFn y el comportamiento de batchLoadFn. Define cómo debe particionar batchGroupFn las claves, cuántas llamadas a batchLoadFn deben realizarse y cómo los resultados permanecen alineados con las claves de entrada; se considera terminado cuando el comportamiento de agrupación propuesto está especificado y cubierto por pruebas.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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?
- Lenguaje dominante
- JavaScript
- Estrellas
- 13.4k
- Forks
- 522
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de graphql/dataloader
-
[BUG] `maxBatchSize: NaN` is accepted and silently disables batchingPosiblemente ocupada @RaphaelFakhri la tomó hace 2 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
graphql/dataloader#405 ·
-
Failed batch evicts a replacement cache entry after clear/primePosiblemente ocupada @Claire-ovo la tomó hace 11 días. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 57/100
graphql/dataloader#403 ·
-
enhancement
Dificultad 5/5 Más de una semana Aptitud para principiantes 38/100
graphql/dataloader#393 ·
-
enhancement
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
graphql/dataloader#382 ·
-
enhancement
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
graphql/dataloader#379 · 2 comentarios · 5 reacciones ·
Todos los issues de graphql/dataloader
Issues similares
-
binding:python bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 1 día
-
bug needs-triage potential-regression
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
aws/aws-sdk-js-v3#8408 ·
Los mantenedores suelen responder en 1 día
-
[v3] KeyBindingManager calls (Add/Remove) are not converted into a case-insensitive accelerator.KeyAbiertoBug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 4 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100