3

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."}]}

Evanss
  • 23,390
  • 94
  • 282
  • 505
  • What is your operating system? If it's Windows, you can use PowerShell to: Invoke-RestMethod localhost:5000 -Method post If you are on a Linux variant use curl to send a post request to your URI – Boluc Papuccuoglu Sep 24 '21 at 15:01

2 Answers2

0

It is because when you type in your address into the address bar of your browser, a GET request is being sent, while your Postgraphile instance only accepts POST requests. So this is the problem. You either avoid sending GET requests, or try and ensure that Postraphile accepts GET requests as well.

A very simple solution would be to create a very simple and small website that will act as a proxy and upon load, it would send a POST request to http://localhost:5000/graphql

There is a GitHub ticket where a middleware is suggested, read this for further information: https://github.com/graphile/postgraphile/issues/442

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175
0

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.

Benjie
  • 7,701
  • 5
  • 29
  • 44