Closed
Description
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.
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'
}
Activity
[-]TypeError: Cannot read property 'endsWith' of undefined[/-][+]apollo-server-lambda: TypeError: Cannot read property 'endsWith' of undefined[/+]glasser commentedon 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 commentedon 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 commentedon Mar 9, 2021
Glancing at all of
@types/aws-lambda
, I don't see any type they define that includesmultiValueHeaders
but doesn't includepath: 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 commentedon Mar 10, 2021
@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 commentedon Mar 10, 2021
Good to know! Thanks for double-checking.
atalebagha commentedon Apr 9, 2021
@st-pimentel how did you solve this issue? I'm dealing with the same thing. Thanks!
st-pimentel commentedon 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/serverglasser commentedon Apr 9, 2021
Seems like duplicate of #5084; this is about the two different API Gateway payload format versions.
glasser commentedon 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 commentedon Apr 14, 2021
This is released in Apollo Server 2.23.0.