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

Incorrect playground endpoint in apollo-server-lambda #4687

Closed
danielpatrickdotdev opened this issue Oct 28, 2020 · 6 comments
Closed

Incorrect playground endpoint in apollo-server-lambda #4687

danielpatrickdotdev opened this issue Oct 28, 2020 · 6 comments

Comments

@danielpatrickdotdev
Copy link

danielpatrickdotdev commented Oct 28, 2020

When deploying apollo-server-lambda as per the readme, the url used by the playground is wrong when using the API gateway execute-api domain.

I believe this is caused by the change made in #1527.

This example payload for this type of event includes a url of https://70ixmpl4fl.execute-api.ca-central-1.amazonaws.com/Prod/, with event.requestContext.path of /Prod/ (the stage name). The event.path is /. Clearly in this case using event.path would be incorrect.

When using an API gateway with a custom domain, the values for event.requestContext.path and event.path are identical.

I'd be happy to submit a PR to fix this, but it would be good to understand why this was changed in the first place first as I don't want to break anything.

@arabold
Copy link

arabold commented Feb 24, 2021

I'm having the same issue. apollo-server-lambda only works with custom domains but not in a simple default setup as it is described in the readme. The original "fix" you're referring to is nearly two years old. That makes me wonder why hasn't this been noted earlier?! We can't be the only ones running into this, can we?

@glasser
Copy link
Member

glasser commented Feb 24, 2021

Is this related to #4891/#4892? That's another issue about path handling in Lambda. Oddly that one suggests that it only works without custom domains, whereas it sounds like you're saying playground only works with custom domains?

I'm happy to merge a fix and have #4892 already lined up for my next PRs-outside-my-current-knowledge-learning-and-merging day); maybe #4892 needs to be expanded to fix this too?

@arabold
Copy link

arabold commented Mar 1, 2021

I did some digging and more testing... The root cause might lie in serverless-offline: The default setting appends the stage name to the URL path, e.g. http://localhost:3000/dev/ for the dev stage. It seems that the fix in #1527 trips over this behavior/bug in serverless-offline: dherault/serverless-offline#1029

For now I have set up my local serverless-offline with the noPrependStageInUrl: true option to avoid the stage name in my path. This matches my actual AWS Lambda setup in which the stage name is defined in the domain mapping (dev.example.com). This works as expected now.

tl;dr. I think this issue can be closed with a reference to the previously mentioned bug report for serverless-offline: dherault/serverless-offline#1029. As a workaround set noPrependStageInUrl: true in your serverless.yml.

@danielpatrickdotdev
Copy link
Author

I didn't use the Serverless framework (I used SAM/CloudFormation) so unsure how this could be related?

@glasser without looking into it in too much detail, I don't think these issues are related but unsure as I've not played around with non-default base path mapping.

@glasser
Copy link
Member

glasser commented Mar 5, 2021

While it's possible that the original author of #1527 (@stubailo) or its reviewer (@jbaxleyiii) might choose to chime in, neither of them work at Apollo any more, and it's quite likely that the world of Lambda has changed a lot in the past 3 years anyway.

I've merged the other semi-related PR (#4892) but I'm not sure I understand Lambda well enough to get what's going on here.

That said:

  • If you send a PR that fixes this, I'll definitely review it, and will do my best to gather info during a release process from Lambda folks to make sure this doesn't break others
  • We are likely to change the graphql-playground integration in AS3 as part of the goal of that release is reducing the number of direct dependencies that AS has on other packages which could be separately integrated.

@glasser
Copy link
Member

glasser commented Oct 11, 2022

Apollo Server 4 replaces a hard-coded set of web framework integrations with a simple stable API for building integrations. As part of this, the core project no longer directly supports a Lambda integration. Check out the @as-integrations/aws-lambda package; this new package is maintained by Lambda users and implements support for the API Gateway v1 and v2 protocols. If you need to work with different AWS projects, you may be able to add that support to that package, or take another approach such as combining the @vendia/serverless-express package with Apollo Server 4's built-in expressMiddleware (this is the same approach that apollo-server-lambda takes in AS3). Sorry for the delay!

(In addition, we changed the support for Playground only to supporting multiple landing pages in AS3 without parsing paths, and AS4 doesn't parse paths at all.)

@glasser glasser closed this as completed Oct 11, 2022
@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
Development

No branches or pull requests

4 participants