Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apollo-server-lambda: JSON.parse errors when lambda event.isBase64Encoded=true #2599

Closed
gobengo opened this issue Apr 21, 2019 · 7 comments
Closed

Comments

@gobengo
Copy link

gobengo commented Apr 21, 2019

Today I just started using apollo-server-lambda. It works pretty well, and my GET request resulted in the GraphiQL playground showing. However, the POST method requests were all failing due to an error in the backend. I could see in Cloudwatch that there was an error when apollo-server-lambda/src/lambdaApollo does JSON.parse(event.body).

For one reason or another, my event had event.isBase64Encoded === true, and the event.body was a long base64 encoded string (that decoded to JSON), not a JSON string.

I was able to work around this error by rewriting all base64-encoed events upstream using this 'middleware' before passing the event into the apollo-lambda-server ApolloServer handler.

PR: #2600

@gobengo
Copy link
Author

gobengo commented Apr 22, 2019

PR: #2600

@abernix
Copy link
Member

abernix commented May 13, 2019

Interesting!

For one reason or another, my event had event.isBase64Encoded === true, and the event.body was a long base64 encoded string (that decoded to JSON), not a JSON string.

Do you have any idea how or why this is the case? Not to say that we can't accept the PR, but the need seems be a bit unsubstantiated / not fully understood. I'd like just like to understand the reasoning so we can make sure we account for it property going forward.

@gobengo
Copy link
Author

gobengo commented May 13, 2019 via email

@jlarmstrongiv
Copy link

jlarmstrongiv commented Jun 4, 2019

@abernix Here’s one case I ran into: lambda@edge provides the Request Body as a base64 encoded string. I would love to have apollo-server-lambda automatically handle it.

@hsimah
Copy link

hsimah commented Mar 10, 2020

This issue stung me this weekend. I am building my first Apollo server app and want to stick it on a lambda. I followed the guide to the letter. When it deploys the IntrospectionQuery fires from the playground and the payload comes through as base64 encoded. I haven't looked into how or why, but applying this fix works, at least with the sample schema in the guide.

@2color
Copy link

2color commented Apr 9, 2020

I experienced the same problem and can confirm the associated PR #2600 resolves the problem.

@abernix
Copy link
Member

abernix commented Jul 17, 2020

Should hopefully be fixed in apollo-server-lambda@2.16.0 by #4311, which should be effectively the same as #2600.

@abernix abernix closed this as completed Jul 17, 2020
@abernix abernix added this to the Release 2.16.0 milestone Jul 17, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
5 participants