Skip to content

Commit

Permalink
[apollo-server-lambda] Add support for isBase64Encoded
Browse files Browse the repository at this point in the history
  • Loading branch information
styfle committed Jun 25, 2020
1 parent 753e60c commit 71309a8
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions packages/apollo-server-lambda/src/lambdaApollo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -43,12 +48,12 @@ export function graphqlLambda(
const contentType = event.headers["content-type"] || event.headers["Content-Type"];
let query: Record<string, any> | Record<string, any>[];

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 || {};
}
Expand Down

0 comments on commit 71309a8

Please sign in to comment.