Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Solve N+1 Problem in GraphQl API

Solve N+1 Problem in GraphQl API

Ngalam Backend Community

April 28, 2019
Tweet

More Decks by Ngalam Backend Community

Other Decks in Programming

Transcript

  1. dataloader input = [2, 1, 5, 3, 4]; output =

    [ { id: 2, name: "two" }, { id: 1, name: "one" }, { id: 5, name: "five" } { id: 3, name: "three" } { id: 4, name: "four" } ];
  2. batching • The Array of values must be the same

    length as the Array of keys • Each index in the Array of values must correspond to the same index in the Array of keys
  3. caching const userLoader = new DataLoader(...) const result1 = await

    userLoader.load(1) const result2 = await userLoader.load(1) assert(result1 === result2)