Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem deploying Apollo Express server to Heroku: "GET query missing."

I wrote a simple GraphQL server using Apollo Express and deployed it to Heroku. After some messing around with Procfiles and the like, it built OK.

When I hit the main URL https://limitless-atoll-59109.herokuapp.com I get the error

Cannot GET /

OK, then I thought the Express server must just be looking for a get on the graphql endpoint. But when I hit https://limitless-atoll-59109.herokuapp.com/graphql I get

GET query missing.

Do I need to include a port in the url? I've got the port set correctly in the code

const PORT = process.env.PORT || 4000

  app.listen({port: PORT}, () =>

  console.log(`Server ready at http://localhost:${PORT}${server.graphqlPath}`)
  );

but I don't think I need to include it when accessing the server on Heroku, do I?

For what it's worth, this is the error in the error logs

019-05-08T17:07:41.492327+00:00 heroku[router]: at=info method=GET path="/graphql" host=limitless-atoll-59109.herokuapp.com request_id=b6171835-aac4-4b45-8a7b-daebbb3167ed fwd="139.47.21.74" dyno=web.1 connect=0ms service=900ms status=400 bytes=196 protocol=https

Thanks for any help!

like image 338
Cerulean Avatar asked Nov 27 '22 02:11

Cerulean


2 Answers

The answer is that it is the url that ends in /graphql that one wants. However, when you hit that url from the browser, it attempts to load the playground, and fails, as the playground is disabled by default in production.

However, you can make graphql calls against that url from your client app and it works fine.

like image 191
Cerulean Avatar answered Dec 10 '22 02:12

Cerulean


If you are using apollo server you can just enable it in production:

const server = new ApolloServer({
  typeDefs,
  resolvers,
  introspection: true,
  playground: true,
});
like image 22
Website Is Fun Avatar answered Dec 10 '22 03:12

Website Is Fun