Search code examples
postgraphile

Postgraphile "Only `POST` requests are allowed." error


I have Postgres running locally. I can access the database locally with psql postgres:///reviewapp and with \dt I can see a few tables.

If I run npx postgraphile -c "postgres:///reviewapp" I dont get any errors in the terminal:

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/

* * *

However when I go to http://localhost:5000/graphql I have an error on the screen: {"errors":[{"message":"Only POST requests are allowed."}]}


Solution

  • You're visiting the /graphql endpoint which speaks GraphQL (over POST requests), but you're sending it a web request (over GET). Instead, use the /graphiql end point to view the GraphiQL GraphQL IDE - this endpoint speaks web, and will give you a nice interface for communicating with the /graphql endpoint. See this output from the PostGraphile command:

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

    I recommend you add the --enhance-graphiql option to the PostGraphile CLI to get an even more powerful IDE in the browser.