Skip to content

apollo-server-lambda: TypeError: Cannot read property 'endsWith' of undefined #5016

Closed
@st-pimentel

Description

@st-pimentel

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'
}

Activity

changed the title [-]TypeError: Cannot read property 'endsWith' of undefined[/-] [+]apollo-server-lambda: TypeError: Cannot read property 'endsWith' of undefined[/+] on Mar 9, 2021
glasser

glasser commented on Mar 9, 2021

@glasser
Member

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

glasser

glasser commented on Mar 9, 2021

@glasser
Member

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

glasser commented on Mar 9, 2021

@glasser
Member

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

st-pimentel commented on Mar 10, 2021

@st-pimentel
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

glasser commented on Mar 10, 2021

@glasser
Member

Good to know! Thanks for double-checking.

atalebagha

atalebagha commented on Apr 9, 2021

@atalebagha

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

st-pimentel

st-pimentel commented on Apr 9, 2021

@st-pimentel
Author

@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

glasser commented on Apr 9, 2021

@glasser
Member

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

glasser

glasser commented on Apr 9, 2021

@glasser
Member

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

glasser commented on Apr 14, 2021

@glasser
Member

This is released in Apollo Server 2.23.0.

locked as resolved and limited conversation to collaborators on Apr 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @glasser@atalebagha@st-pimentel

        Issue actions

          apollo-server-lambda: TypeError: Cannot read property 'endsWith' of undefined · Issue #5016 · apollographql/apollo-server