graphqlUploadExpress.js 861 B

12345678910111213141516171819202122232425262728293031323334
  1. 'use strict'
  2. exports.__esModule = true
  3. exports.graphqlUploadExpress = void 0
  4. var _processRequest = require('./processRequest')
  5. const graphqlUploadExpress = ({
  6. processRequest = _processRequest.processRequest,
  7. ...processRequestOptions
  8. } = {}) => (request, response, next) => {
  9. if (!request.is('multipart/form-data')) return next()
  10. const finished = new Promise(resolve => request.on('end', resolve))
  11. const { send } = response
  12. response.send = (...args) => {
  13. finished.then(() => {
  14. response.send = send
  15. response.send(...args)
  16. })
  17. }
  18. processRequest(request, response, processRequestOptions)
  19. .then(body => {
  20. request.body = body
  21. next()
  22. })
  23. .catch(error => {
  24. if (error.status && error.expose) response.status(error.status)
  25. next(error)
  26. })
  27. }
  28. exports.graphqlUploadExpress = graphqlUploadExpress