1

我在本地运行 Postgres。我可以使用本地访问数据库,psql postgres:///reviewapp并且\dt可以看到一些表。

如果我运行,npx postgraphile -c "postgres:///reviewapp"我不会在终端中收到任何错误:

PostGraphile v4.12.4 server listening on port 5000 

  ‣ GraphQL API:         http://localhost:5000/graphql
  ‣ GraphiQL GUI/IDE:    http://localhost:5000/graphiql (RECOMMENDATION: add '--enhance-graphiql')
  ‣ Postgres connection: postgres:///reviewapp
  ‣ Postgres schema(s):  public
  ‣ Documentation:       https://graphile.org/postgraphile/introduction/
  ‣ Node.js version:     v14.15.5 on darwin x64
  ‣ Join Mark in supporting PostGraphile development: https://graphile.org/sponsor/

* * *

但是,当我转到http://localhost:5000/graphql屏幕上时出现错误: {"errors":[{"message":"Only POST requests are allowed."}]}

4

2 回答 2

0

您正在访问使用/graphqlGraphQL(通过 POST 请求)的端点,但您正在向其发送 Web 请求(通过 GET)。相反,请使用/graphiql端点查看 GraphiQL GraphQL IDE - 此端点使用 Web,并为您提供与/graphql端点通信的良好界面。查看 PostGraphile 命令的输出:

  ‣ GraphQL API:         http://localhost:5000/graphql
  ‣ GraphiQL GUI/IDE:    http://localhost:5000/graphiql (RECOMMENDATION: add '--enhance-graphiql')

我建议您将--enhance-graphiql选项添加到 PostGraphile CLI 以在浏览器中获得更强大的 IDE。

于 2021-09-24T16:05:44.787 回答
0

这是因为当您在浏览器的地址栏中输入您的地址时,正在发送一个 GET 请求,而您的 Postgraphile 实例只接受 POST 请求。所以这就是问题所在。您要么避免发送 GET 请求,要么尝试确保 Postraphile 也接受 GET 请求。

一个非常简单的解决方案是创建一个非常简单且小型的网站,该网站将充当代理,并在加载时向 http://localhost:5000/graphql 发送 POST 请求

有一个 GitHub 票,其中建议使用中间件,请阅读此以获取更多信息:https ://github.com/graphile/postgraphile/issues/442

于 2021-09-24T15:20:25.010 回答