graphqlUploadKoa.js 615 B

123456789101112131415161718192021222324252627
  1. 'use strict'
  2. exports.__esModule = true
  3. exports.graphqlUploadKoa = void 0
  4. var _processRequest = require('./processRequest')
  5. const graphqlUploadKoa = ({
  6. processRequest = _processRequest.processRequest,
  7. ...processRequestOptions
  8. } = {}) => async (ctx, next) => {
  9. if (!ctx.request.is('multipart/form-data')) return next()
  10. const finished = new Promise(resolve => ctx.req.on('end', resolve))
  11. try {
  12. ctx.request.body = await processRequest(
  13. ctx.req,
  14. ctx.res,
  15. processRequestOptions
  16. )
  17. await next()
  18. } finally {
  19. await finished
  20. }
  21. }
  22. exports.graphqlUploadKoa = graphqlUploadKoa