hongbo-miao/hongbomiao.com

View on GitHub
api-node/src/graphQL/dataLoaders/starshipDataLoader.ts

Summary

Maintainability
A
0 mins
Test Coverage
import DataLoader from 'dataloader';
import fetchStarshipByID from '../../dataSources/swapi/utils/fetchStarshipByID';
import GraphQLStarship from '../types/GraphQLStarship';

const starshipDataLoader = (): DataLoader<string, GraphQLStarship | null> =>
  new DataLoader(async (ids: ReadonlyArray<string>) => {
    return Promise.all(ids.map((id) => fetchStarshipByID(id)));
  });

export default starshipDataLoader;