Created
June 19, 2018 17:46
-
-
Save martijnwalraven/28ff235bb00411971d165b28f7b065c7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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