question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

apollo-server-lambda: Root ("/") path breaks server

See original GitHub issue

Package/Version

This bug relates to apollo-server-lambda 3.0 (this issue did not appear in any 2.x releases)

Expected Behavior

apollo-server-lambda runs regardless of the specific http path used for it within the serverless.yml configuration.

Actual Behavior

I built an example based exactly on the steps found on the tutorial page with the only change being that I used an http path of / instead of graphql within serverless.yml. This is so that the GraphQL server runs at the root of the domain instead of at /graphql. When run, this results in the server responding to all requests with the following message:

<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="utf-8">
	<title>Error</title>
</head>

<body>
	<pre>Cannot POST /</pre>
</body>

</html>

This does not happen if I revert back to a path of graphql.

In our use case, we simply had defaulted to using the root url for GraphQL and had done so with all previous releases, so we were hoping to keep the paradigm to avoid unnecessary changes to our client applications. It’s my understanding that a path of / is the correct way to reference the root url within serverless configurations as it’s worked before.

Reproduction Steps

An example for reproduction can be found at pearljobs/apollo-serverless-bug

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
glassercommented, Oct 7, 2022

@apatelvero This seems like a question about the serverless tool or AWS Lambda rather than anything Apollo Server specific. As of v3.0.1 apollo-server-lambda shouldn’t care much about URL paths, and in the almost-released v4 nothing in Apollo Server will care about URL paths.

0reactions
apatelverocommented, Oct 6, 2022

Hi, I just can’t seem to get this to work! In my case I’m creating a federated graph and the / path is for the gateway …

My setup looks like :

functions:
  gateway:
    handler: src/services/gateway/handler.graphql
    events:
      - http:
          path: / 
          method: post
          cors: true
      - http:
          path: / 
          method: get
          cors: true
const gateway = new ApolloGateway({
  supergraphSdl: new IntrospectAndCompose({
    subgraphs: urls,
  }),
});

export const server = new ApolloServer({
  gateway,
  csrfPrevention: true,
  cache: "bounded",
  plugins: [ApolloServerPluginLandingPageLocalDefault({ embed: true })],
});
export const apolloServerHandler = server.createHandler({
  expressGetMiddlewareOptions: { path: "/" },
});

in the server less offline logging I can see that an endpoint has been setup:

 POST | http://localhost:4001/dev                                         │
   │   POST | http://localhost:4001/2015-03-31/functions/gateway/invocations    │
   │   GET  | http://localhost:4001/dev            

when I try calling the endpoint from the browser I get Cannot GET null

Works fine if I give the path a route …

deps :

    "@apollo/gateway": "^2.0.5",
    "@apollo/subgraph": "^2.0.5",
    "apollo-server-lambda": "^3.10.1",
    "dataloader": "^2.1.0",
    "graphql": "^16.5.0",

any ideas? /Stephen.

Do you know if there is anyway to remove the environment from end of the url http://localhost:4001/dev. I would just prefer to have localhost:4001/graphql instead of localhost:4001/dev/graphql

Read more comments on GitHub >

github_iconTop Results From Across the Web

Deploying with AWS Lambda - Apollo GraphQL Docs
In this guide, we'll walk through how to deploy Apollo Server's AWS Lambda integration to AWS Lambda using the Serverless framework.
Read more >
Deploying with AWS Lambda - Apollo GraphQL Docs
How to deploy Apollo Server with AWS Lambda. AWS Lambda is a service that allows users to run code without provisioning or managing...
Read more >
Migrating to Apollo Server 3 - Apollo GraphQL Docs
We can pass this schema object to both the SubscriptionServer and ApolloServer . This way, it's clear that the same schema is being...
Read more >
GraphQL schema basics - Apollo GraphQL Docs
This article describes the fundamental building blocks of a schema and how to create one for your GraphQL server. The schema definition language....
Read more >
Apollo-server-lambda with additional endpoints - Help
export const handler = apolloServer.createHandler({ expressAppFromMiddleware: (middleware) => { const app = express(); app.get('/my-path', (req, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found