-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
style(Prettier): Add Prettier to eslint rules. Some other cleanups.
- Loading branch information
Showing
16 changed files
with
422 additions
and
257 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,66 @@ | ||
export default function (graphqlHTTPMiddleware) { | ||
export default function(graphqlHTTPMiddleware) { | ||
return (req, res) => { | ||
const subResponses = []; | ||
return Promise.all( | ||
req.body.map(data => | ||
new Promise((resolve) => { | ||
const subRequest = { | ||
__proto__: req.__proto__, // eslint-disable-line | ||
...req, | ||
body: data, | ||
}; | ||
const subResponse = { | ||
status(st) { this.statusCode = st; return this; }, | ||
set() { return this; }, | ||
send(payload) { | ||
resolve({ status: this.statusCode, id: data.id, payload }); | ||
}, | ||
req.body.map( | ||
data => | ||
new Promise(resolve => { | ||
const subRequest = { | ||
__proto__: req.__proto__, // eslint-disable-line | ||
...req, | ||
body: data, | ||
}; | ||
const subResponse = { | ||
status(st) { | ||
this.statusCode = st; | ||
return this; | ||
}, | ||
set() { | ||
return this; | ||
}, | ||
send(payload) { | ||
resolve({ status: this.statusCode, id: data.id, payload }); | ||
}, | ||
|
||
// support [email protected] | ||
setHeader() { return this; }, | ||
header() {}, | ||
write(payload) { this.payload = payload; }, | ||
end(payload) { | ||
// support [email protected] | ||
if (payload) { | ||
// support [email protected] | ||
setHeader() { | ||
return this; | ||
}, | ||
header() {}, | ||
write(payload) { | ||
this.payload = payload; | ||
} | ||
resolve({ status: this.statusCode, id: data.id, payload: this.payload }); | ||
}, | ||
}; | ||
subResponses.push(subResponse); | ||
graphqlHTTPMiddleware(subRequest, subResponse); | ||
}) | ||
}, | ||
end(payload) { | ||
// support [email protected] | ||
if (payload) { | ||
this.payload = payload; | ||
} | ||
resolve({ | ||
status: this.statusCode, | ||
id: data.id, | ||
payload: this.payload, | ||
}); | ||
}, | ||
}; | ||
subResponses.push(subResponse); | ||
graphqlHTTPMiddleware(subRequest, subResponse); | ||
}) | ||
) | ||
).then(responses => { | ||
let response = ''; | ||
responses.forEach(({ status, id, payload }, idx) => { | ||
if (status) { | ||
res.status(status); | ||
} | ||
const comma = responses.length - 1 > idx ? ',' : ''; | ||
response += `{ "id":"${id}", "payload":${payload} }${comma}`; | ||
) | ||
.then(responses => { | ||
let response = ''; | ||
responses.forEach(({ status, id, payload }, idx) => { | ||
if (status) { | ||
res.status(status); | ||
} | ||
const comma = responses.length - 1 > idx ? ',' : ''; | ||
response += `{ "id":"${id}", "payload":${payload} }${comma}`; | ||
}); | ||
res.set('Content-Type', 'application/json'); | ||
res.send(`[${response}]`); | ||
}) | ||
.catch(err => { | ||
res.status(500).send({ error: err.message }); | ||
}); | ||
res.set('Content-Type', 'application/json'); | ||
res.send(`[${response}]`); | ||
}).catch(err => { | ||
res.status(500).send({ error: err.message }); | ||
}); | ||
}; | ||
} |
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
Oops, something went wrong.