hasura / graphql-engine

Blazing fast, instant realtime GraphQL APIs on your DB with fine grained access control, also trigger webhooks on database events.
https://hasura.io
Apache License 2.0
31.18k stars 2.76k forks source link

"error: :"resource does not exist" with docker/ubuntu #174

Closed krishkumar closed 6 years ago

krishkumar commented 6 years ago

I setup Hasura, PostgreSQL on my Linux box running Ubuntu 16.04 using the following instructions - https://docs.hasura.io/1.0/graphql/manual/getting-started/docker-simple.html

Two issues -

  1. On accessing the endpoint at http://ip:8080 I get this - {"path":"$","error":"resource does not exist","code":"not-found"}

  2. Hasura console says its running at http://ip:9695 but it does not seem to be running.

Any ideas on what is wrong with my setup?

shahidhk commented 6 years ago

@krishkumar,

  1. How are you accessing the endpoint? On a browser, using curl etc.? A GET on / should redirect to /console. The graphql endpoint is /v1alpha1/graphql.
  2. Is it a VM/remote box? In that case you should run the console with hasura console --address 0.0.0.0 since the default address is localhost.
krishkumar commented 6 years ago

Thanks @shahidhk.

  1. Tried curl and browser.

$ curl http://172.104.125.25:8080/v1alpha1/graphql {"path":"$","error":"resource does not exist","code":"not-found"}

  1. hasura console --address 0.0.0.0 helped. But getting a different error now on the browser.

"Not able to reach the graphql server. Check if hasura console server is running or if graphql server is running and try again"

shahidhk commented 6 years ago
  1. /v1alpha1/graphql/ only accepts POST requests. curl -d'{"query":""}' http://172.104.125.25:8080/v1alpha1/graphql throws a correct parsing error. Also, http://172.104.125.25:8080/console should serve the API console if --enable-console flag is present in docker-compose.yaml. Can you verify that?

  2. Since you're accessing the console through a non-localhost interface, you need to pass the graphql endpoint also to console. The command will now look like this: hasura console --address 0.0.0.0 --endpoint http://172.104.125.25:8080.

Ideally you should be running the cli on a client machine, where you've configured the endpoint to a remote graphql-engine instance in config.yaml. The cli can be initialised on a client by executing hasura init --endpoint <remote-graphql-engine-url>. Then open the console by doing hasura console

krishkumar commented 6 years ago
  1. docker-compose.yaml looks to have the correct flag.

  2. Makes sense. I am now passing the endpoint the the console command - hasura console --address 0.0.0.0 --endpoint http://172.104.125.25:8080

Curious why this is failing at all. Is there a Hasura logs file I can tail to see what is going on?

docker-compose.yaml.txt

shahidhk commented 6 years ago

As I understand the situation, you're using docker-compose to run postgres and graphl-engine, as mentioned in the docs. But this is running on a virtual machine with a public ip. Correct?

You can run docker logs <container-id> to see the logs. Use docker ps to get the container id for graphql enigne.

shahidhk commented 6 years ago

Is the console accessible by running hasura console command with the correct flags?

krishkumar commented 6 years ago

This is a fresh Linode instance with a public ip. Installed postgresql and docker with apt.

Console is still not accessible via browser. Throws this alert - "Not able to reach the graphql server. Check if hasura console server is running or if graphql server is running and try again"

docker-logs-3c8a78daa394.txt

shahidhk commented 6 years ago

Okay. Here is how you can access the console using hasura cli:

On your local machine (not on the linode machine), install hasura cli.

Then execute the following:

hasura init --endpoint http://172.104.125.25:8080 --directory my-project
cd my-project
hasura console

This will open up the console on your default browser.

shahidhk commented 6 years ago

Now, to debug console not being served on http://172.104.125.25:8080/console, can you paste me the output of docker ps?

krishkumar commented 6 years ago

CONTAINER ID        IMAGE                          COMMAND                  CREATED             STATUS              PORTS                    NAMES
c6e541efe4cd        hasura/graphql-engine:latest   "graphql-engine --da…"   11 minutes ago      Up 11 minutes       0.0.0.0:8080->8080/tcp   angry_kalam
shahidhk commented 6 years ago

Ah, okay. So I assume you have not used docker-compose as mentioned in https://docs.hasura.io/1.0/graphql/manual/getting-started/docker-simple.html, but went with the standalone docker run mentioned in https://docs.hasura.io/1.0/graphql/manual/deployment/docker/index.html. Is that correct?

In that case, the console is not available on the server because --enable-console was not passed to the docker run command. You can confirm this by checking docker inspect <container id>.

If you want console to be available on the server, please restart the container with the following command:

docker run -d -p 8080:8080 \
  hasura/graphql-engine:latest \
  graphql-engine \
  --database-url postgres://username:password@hostname:port/dbname \
  serve --enable-console

Otherwise, your setup is alright and you can continue using console from CLI, by following the steps above.

I recommend adding an access key, since the IP is in a public forum now.

krishkumar commented 6 years ago

Turns out I did use the standalone docker setup instructions instead of docker compose.

Hasura on my Linode box works fine now. Thanks @shahidhk for all the support and debugging!

shahidhk commented 6 years ago

No problem @krishkumar. When using the CLI, initialise with hasura init --endpoint http://172.104.125.25:8080 --access-key <access-key> --directory my-project or add access_key: <access-key> to an existing config.yaml

krishkumar commented 6 years ago

Makes sense. I have secured my endpoint by adding a access_key to config.yaml.