This repository has been archived by the owner on Dec 17, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(express-middleware): Add DataLoader middleware
Added an express middleware to provide per-request DataLoaders for fetching data from the HealthGraph API to prevent multiple calls to the same URI in the same request.
- Loading branch information
Simon Wears
committed
Mar 19, 2017
1 parent
08defbe
commit a817695
Showing
11 changed files
with
81 additions
and
55 deletions.
There are no files selected for viewing
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
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
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
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
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
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
This file was deleted.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const request = require('superagent-promise')(require('superagent'), Promise); | ||
const DataLoader = require('dataloader'); | ||
const log = require('./../helpers/logging'); | ||
|
||
module.exports = function createLoader (req, res, next) { | ||
|
||
const HealthGraphLoader = new DataLoader( | ||
urls => Promise.all(urls.map(uri => { | ||
|
||
log.info('HEALTHGRAPH_REQUEST', {uri}); | ||
|
||
return request | ||
.get(`https://api.runkeeper.com${uri}`) | ||
.query({ | ||
access_token: req.cookies.auth | ||
}) | ||
.end() | ||
.then(data => data.body); | ||
|
||
})) | ||
); | ||
|
||
req.healthGraphLoader = HealthGraphLoader; // eslint-disable-line no-param-reassign | ||
|
||
next(); | ||
|
||
}; |
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
Oops, something went wrong.