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!
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.
If you are using apollo server you can just enable it in production:
const server = new ApolloServer({
typeDefs,
resolvers,
introspection: true,
playground: true,
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With