[REQUEST] Update types to support an array of promises as the resolved value for batchLoadFn
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bastante claro
- Estado de actividad
- Estancado
- Stack tecnológico
- javascript
- Área
- backend-api-design
Línea de trabajo
Comienza por la definición del tipo BatchLoadFn y las declaraciones de tipo de DataLoader. Compara el tipo de retorno declarado con el ejemplo de un array de promesas y, después, verifica que el ejemplo de comprobación de tipos acepta elementos Promise al tiempo que conserva los casos V y Error.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
What problem are you trying to solve?
The DataLoader class already functionally handles the case where you resolve with an array of promises rather than an array of values. This is nice because it allows individual items in the batch to resolve separately and prevents the case where one long-running item in the batch holds up the rest of the items which were resolved quickly.
The problem is that the type definition for the batchLoadFn does not allow for individual items in the resolved array to be promises containing V. They must either be V or Error.
Here's an example.
const dataloader = new DataLoader<TheKey, TheValue>(
// This will cause a flow error because TheValue does not equal Promise<TheValue>.
async (keys: $ReadOnlyArray<TheKey>): Promise<Array<Promise<TheValue>>> => {
return keys.map(key =>
doSomethingTimeConsuming(key)
.then(doMoreTimeConsumingThings)
// Ensure errors are cached.
.catch(e => e)
);
}
);
Describe the solution you'd like
The type BatchLoadFn could be updated to return Promise<$ReadOnlyArray<V | Promise<V> | Error>>.
Describe alternatives you've considered
I could just specify Promise<TheValue> as the return value for the dataloader, but then I have to do silly things like this to keep flow happy:
const theValue = await await dataloader.load(theKey);
Additional context
I'm working on a pull request now to address this if the maintainers decide this is a good change.
- 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
-
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
-
fix(docs): align git__gh troubleshooting with its actual failure pathsPosiblemente ocupada @akhil9tiet la tomó hoy. Abiertobug docs p2
Dificultad 1/5 1-3 horas Aptitud para principiantes 78/100
vercel/eve#6130 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100