Using dataloader at leaf level of multi layer schema failed to batch

Abierto
#276 0 comentarios 6 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
25/100
Tipo de issue
Error
Claridad
Necesita aclaración
Estado de actividad
Estancado
Stack tecnológico
graphql, javascript, postgres

Línea de trabajo

Comienza reproduciendo la consulta D→S→SW→W→C con un DataLoader únicamente en el nivel hoja C, usando la configuración descrita de Apollo Server, Postgres y Knex. Compara el batching con y sin batchScheduleFn y, después, añade loaders ancestro para W, SW y S; se considera terminado cuando se haya determinado si el comportamiento es el esperado o se trata de un error de DataLoader, y se haya documentado la conclusión si corresponde.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Hi there,

I have a graphql schema like this:
D has many S has many SW has one W has many C.
D is available via a root level query.
(The underlying SQL has the same set of entities and relationships between them).

Using apollo server (not sure if relevant), postgres and knex.

I started by adding a dataloader for C. I then made a root level query for D, asking for all the properties of each element in the above schema. Testing revealed that the caching worked - each distinct C was only queried for once. But batching didn't work - for each distinct C, there was a separate SELECT.

When debugging this, added batchScheduleFn: (callback) => setTimeout(callback, 100) to the dataloader for C. At that point, batching started to work.

This made me think that somehow the C resolution was taking place on different event loop tics. On a hunch, I added a dataloader for W, SW and S. (none for D, as there is just one root level query for D).

After doing this, batching worked for all of S, SW, W and C - even with the batchSchedule function removed.

So I wanted to ask - is this possibly a bug (either in dataloader or, for a separate matter, Apollo Server), or is it expected that batching at the leaf node C would not work unless all ancestor nodes are also resolved with dataloaders?

If this isn't a bug, I wonder if adding this information to the documentation would be possible, to help other people who find themselves in this situation - implementing dataloader only at the leaf of a deep schema, and having batching not work they way they expected it would?

Anyhow, thanks for the library and its ongoing maintenance :)

Lenguaje dominante
JavaScript
Estrellas
13.4k
Forks
522
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de graphql/dataloader

Todos los issues de graphql/dataloader

Issues similares

Más issues de JavaScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.