将Apollo Express服务器部署到Heroku时出现问题:“缺少查询”。

Cer*_*ean 1 heroku node.js apollo graphql apollo-server

我使用Apollo Express编写了一个简单的GraphQL服务器,并将其部署到Heroku。在弄乱了Procfiles之类的东西之后,它构建成功。

当我点击主URL https://limitless-atoll-59109.herokuapp.com时,我得到了错误

不能获取 /

好的,那我以为Express服务器必须只是在graphql端点上查找get。但是当我点击https://limitless-atoll-59109.herokuapp.com/graphql时,我得到了

缺少GET查询。

我需要在网址中包含端口吗?我在代码中正确设置了端口

const PORT = process.env.PORT || 4000

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

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

但是访问Heroku上的服务器时,我不需要添加它,对吗?

值得的是,这是错误日志中的错误

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服务= 900ms状态= 400字节= 196协议= https

谢谢你的帮助!

小智 12

如果您使用的是 apollo 服务器,您可以在生产中启用它:

const server = new ApolloServer({
  typeDefs,
  resolvers,
  introspection: true,
  playground: true,
});
Run Code Online (Sandbox Code Playgroud)


Cer*_*ean 5

答案是,它在两端的网址/graphql是一个希望。但是,当您从浏览器中访问该URL时,它将尝试加载Playground并失败,因为在生产中默认情况下Playground是禁用的。

但是,您可以从客户端应用程序对该URL进行graphql调用,并且效果很好。