From 29693b6cde6f0e189284d57d4955f8046807dd2f Mon Sep 17 00:00:00 2001 From: Owen Calvin Date: Sun, 1 Mar 2020 21:12:15 +0100 Subject: [PATCH] Fix file upload bug with apollo-server-koa (#2843) --- packages/apollo-server-koa/src/ApolloServer.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/apollo-server-koa/src/ApolloServer.ts b/packages/apollo-server-koa/src/ApolloServer.ts index 2043e299f60..0967444ef75 100644 --- a/packages/apollo-server-koa/src/ApolloServer.ts +++ b/packages/apollo-server-koa/src/ApolloServer.ts @@ -37,6 +37,7 @@ const fileUploadMiddleware = ( server: ApolloServerBase, ) => async (ctx: Koa.Context, next: Function) => { if (typeis(ctx.req, ['multipart/form-data'])) { + const finished = new Promise(resolve => ctx.req.on('end', resolve)); try { ctx.request.body = await processFileUploads( ctx.req, @@ -51,6 +52,8 @@ const fileUploadMiddleware = ( formatter: server.requestOptions.formatError, debug: server.requestOptions.debug, }); + } finally { + await finished; } } else { return next();