Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martijnwalraven/28ff235bb00411971d165b28f7b065c7 to your computer and use it in GitHub Desktop.
Save martijnwalraven/28ff235bb00411971d165b28f7b065c7 to your computer and use it in GitHub Desktop.
export class PersonalizationAPI extends RESTDataSource {
baseURL = 'https://personalization-api.example.com';
willSendRequest(request: Request) {
request.headers.set('Authorization', this.context.token);
}
private progressLoader = new DataLoader(async (ids: string[]) => {
const progressList = await this.get('progress', {
ids: ids.join(','),
});
return ids.map(id =>
progressList.find((progress: any) => progress.id === id),
);
});
async getProgressFor(id: string) {
return this.progressLoader.load(id);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment