LoginSignup
0
0

More than 3 years have passed since last update.

graphql/dataloaderを使うときに足りないデータにnullを入れたり、順番を調整するのに使える

Posted at

https://github.com/graphql/dataloader#batch-function
を応用すればいいだけ。
自分のjavascriptのレベルが低いときはスルーしてた

const users = [{
  id:3,
  name: "jone"
},{
  id:6,
  name: "paul"
},{
  id:8,
  name: "anna"
}];

const userIds =[6, 3, 8];

const mapped = userIds.map(
  userid => users.find(e => e.id === userid) || null
);

console.log(mapped);
/*
[
  { id: 6, name: 'paul' },
  { id: 3, name: 'jone' },
  { id: 8, name: 'anna' }
]
*/
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0