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: TypeError: Cannot read property 'endsWith' of undefined #5016

Closed
st-pimentel opened this issue Mar 9, 2021 · 10 comments

Comments

@st-pimentel
Copy link

Using the playground, when try to load the page, this error is outputed:

TypeError: Cannot read property 'endsWith' of undefined

Seems to be the case of not every time or at least not at the first request that the event have the path attribute.

if (event.path.endsWith('/.well-known/apollo/server-health')) {

I printed the event object and could not find the path attribute.

{
  headers: {
    host: 'localhost:4000',
    connection: 'keep-alive',
    'content-length': '1468',
    accept: '*/*',
    'apollo-query-plan-experimental': '1',
    'x-apollo-tracing': '1',
    'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.192 Safari/537.36',
    'content-type': 'application/json',
    origin: 'http://localhost:4000',
    'sec-fetch-site': 'same-origin',
    'sec-fetch-mode': 'cors',
    'sec-fetch-dest': 'empty',
    referer: 'http://localhost:4000/',
    'accept-encoding': 'gzip, deflate, br',
    'accept-language': 'en-GB,en-US;q=0.9,en;q=0.8,pt;q=0.7,de;q=0.6'
  },
  multiValueHeaders: {},
  body: '{...}',
  httpMethod: 'POST'
}
@glasser glasser changed the title TypeError: Cannot read property 'endsWith' of undefined apollo-server-lambda: TypeError: Cannot read property 'endsWith' of undefined Mar 9, 2021
@glasser
Copy link
Member

glasser commented Mar 9, 2021

Uh-oh, this looks like a regression in v2.21.1 from #4892. I bet a little question mark should fix that up.

@glasser
Copy link
Member

glasser commented Mar 9, 2021

That said I'm a little concerned that our TS types don't catch this. And it's not a matter of us being behind on @types/aws-lambda: the latest version looks the same.

In what context are you running your Lambda? Perhaps it's not behind "api gateway" and our choice of APIGatewayProxyEvent as the typing to use is not general enough?

@glasser
Copy link
Member

glasser commented Mar 9, 2021

Glancing at all of @types/aws-lambda, I don't see any type they define that includes multiValueHeaders but doesn't include path: string (except some result types that have other required fields that aren't visible above).

I know I can just add the single question mark, but I'd like to understand a tad better what context you're seeing this pathless event in. Is this behind an ALB?

@st-pimentel
Copy link
Author

@glasser thank you for your response.
Today I discovered that this project use some kind of a custom proxy and the path isn't filled for the event.
We made this change here and now is working.
Sorry for the trouble.

@glasser
Copy link
Member

glasser commented Mar 10, 2021

Good to know! Thanks for double-checking.

@glasser glasser closed this as completed Mar 10, 2021
@atalebagha
Copy link

@st-pimentel how did you solve this issue? I'm dealing with the same thing. Thanks!

@st-pimentel
Copy link
Author

st-pimentel commented Apr 9, 2021

@atalebagha in my case not is a problem with the apollo-server-lambda
in my environment the attribute path is missing, so we need to add this attribute on our proxy/server

@st-pimentel how did you solve this issue? I'm dealing with the same thing. Thanks!

@glasser
Copy link
Member

glasser commented Apr 9, 2021

Seems like duplicate of #5084; this is about the two different API Gateway payload format versions.

@glasser
Copy link
Member

glasser commented Apr 9, 2021

I've released a prerelease with this fix, version 2.23.0-alpha.1. Try out the alpha and see if it works for you! Please provide any feedback in #5094.

@glasser
Copy link
Member

glasser commented Apr 14, 2021

This is released in Apollo Server 2.23.0.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants