graphql/dataloader

[QUESTION] Any recommendations for using DataLoader with pivot tables?

Open

#289 geöffnet am 29. Dez. 2021

Auf GitHub ansehen
 (0 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)JavaScript (556 Forks)batch import
help wanted

Repository-Metriken

Stars
 (12.520 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 5T 2h) (1 gemergte PR in 30 T)

Beschreibung

Pivot tables are often used in relational databases to define one-to-many relationships.

In my case I'm using Adonis.js's Lucid ORM in my GraphQL resolvers, but things get a little tricky when loading relationships that use a pivot table. For example:

const user = await context.loaders.userById.load(input.id);
const posts = await user.posts().fetch();

// Since I didn't use a loader to fetch posts, I now have to prime the cache manually:
for (let post of posts.rows) {
  context.loaders.postById.prime(post.id, post);
}

The downside to this is I lose the simplicity of only using my loaders to grab data, and I have to remember to manually priming my cache even when I might not need the data again.

Contributor Guide