From 71309a8256bd54e748fdeaf056d20ea1bec9d480 Mon Sep 17 00:00:00 2001 From: Steven Date: Thu, 25 Jun 2020 11:07:33 -0400 Subject: [PATCH 1/2] [apollo-server-lambda] Add support for `isBase64Encoded` --- packages/apollo-server-lambda/src/lambdaApollo.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/apollo-server-lambda/src/lambdaApollo.ts b/packages/apollo-server-lambda/src/lambdaApollo.ts index 934c2959593..fad594122e9 100644 --- a/packages/apollo-server-lambda/src/lambdaApollo.ts +++ b/packages/apollo-server-lambda/src/lambdaApollo.ts @@ -32,8 +32,13 @@ export function graphqlLambda( callback, ): void => { context.callbackWaitsForEmptyEventLoop = false; + let { body, isBase64Encoded } = event; - if (event.httpMethod === 'POST' && !event.body) { + if (body && isBase64Encoded) { + body = Buffer.from(body, 'base64').toString(); + } + + if (event.httpMethod === 'POST' && !body) { return callback(null, { body: 'POST body missing.', statusCode: 500, @@ -43,12 +48,12 @@ export function graphqlLambda( const contentType = event.headers["content-type"] || event.headers["Content-Type"]; let query: Record | Record[]; - if (event.body && event.httpMethod === 'POST' && + if (body && event.httpMethod === 'POST' && contentType && contentType.startsWith("multipart/form-data") ) { - query = event.body as any; - } else if (event.body && event.httpMethod === 'POST') { - query = JSON.parse(event.body); + query = body as any; + } else if (body && event.httpMethod === 'POST') { + query = JSON.parse(body); } else { query = event.queryStringParameters || {}; } From e621ccb415df45fcee880725207b5d642c6a2568 Mon Sep 17 00:00:00 2001 From: Jesse Rosenberger Date: Tue, 7 Jul 2020 13:51:58 +0300 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4955ade8a0f..a875e81e369 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ The version headers in this history reflect the versions of Apollo Server itself > The changes noted within this `vNEXT` section have not been released yet. New PRs and commits which introduce changes should include an entry in this `vNEXT` section as part of their development. With few exceptions, the format of the entry should follow convention (i.e., prefix with package name, use markdown `backtick formatting` for package names and code, suffix with a link to the change-set à la `[PR #YYY](https://link/pull/YYY)`, etc.). When a release is being prepared, a new header will be (manually) created below and the appropriate changes within that release will be moved into the new section. +- `apollo-server-lamdbda`: Automatically decode payloads which are Base64-encoded when the `isBase64Encoded` boolean is present on Lambda `event` payloads. [PR #4311](https://github.com/apollographql/apollo-server/pull/4311) - The default branch of the repository has been changed to `main`. As this changed a number of references in the repository's `package.json` and `README.md` files (e.g., for badges, links, etc.), this necessitates a release to publish those changes to npm. [PR #4302](https://github.com/apollographql/apollo-server/pull/4302) ### v2.15.0