graphqlUploadKoa.mjs 517 B

12345678910111213141516171819
  1. import { processRequest as defaultProcessRequest } from './processRequest'
  2. export const graphqlUploadKoa = ({
  3. processRequest = defaultProcessRequest,
  4. ...processRequestOptions
  5. } = {}) => async (ctx, next) => {
  6. if (!ctx.request.is('multipart/form-data')) return next()
  7. const finished = new Promise(resolve => ctx.req.on('end', resolve))
  8. try {
  9. ctx.request.body = await processRequest(
  10. ctx.req,
  11. ctx.res,
  12. processRequestOptions
  13. )
  14. await next()
  15. } finally {
  16. await finished
  17. }
  18. }