GraphQL node setup - documentation says, in a distributed setup, us --alpha


(J Czz) #1

How do you attach the GraphQL node to “–alpha” node in existing cluster?

I used the docker compose setup: https://docs.dgraph.io/deploy/#multi-host-setup.

Almost working:
docker run -v $(pwd):/dgraph -p 9000:9000 -it dgraph/standalone:graphql dgraph graphql --alpha=local_server_1:9080

It hangs with: 1 admin.go:276] Trying to connect to Dgraph at local_server_1:9080


(Michel Conrado) #2

This is certainly a Docker issue. Maybe expose the 9080 port?


(J Czz) #3

Port 9080 on alpha / local_server_1 is already exposed and I can use it via dgo - if that was what you meant?


(Michel Conrado) #4

Humm, have you followed the procedures in the https://graphql.dgraph.io/ site?

Like “create a graphql schema” and so on.


(J Czz) #5

I was going to, but I should be able to connect
graphql node to alpha
and then I create schema etc. - right?


(J Czz) #6

In step 2, the doc creates the schema: https://graphql.dgraph.io/docs/quick-start/

But first, I think, you need the graphql node to be up running. I would like to connect the graphql to an existing cluster(docker compose example)

The doc: https://graphql.dgraph.io/docs/admin/
Says in: Advanced Options it looks like I should pass in the --alpha option.


(Michel Conrado) #7

Okay, I never did it in a running context. @michaelcompton what you can tell about it?


(J Czz) #8

As you know I can get the node to start:
docker run -v $(pwd):/dgraph -p 9000:9000 -it dgraph/standalone:graphql dgraph graphql --alpha=local_server_1:9080

But then is logs:

I1126 14:07:13.981923       1 run.go:137] Starting GraphQL with Dgraph at: local_server_1:9080
I1126 14:07:13.982904       1 run.go:169] Bringing up GraphQL HTTP API at 0.0.0.0:9000/graphql
I1126 14:07:13.982983       1 run.go:170] Bringing up GraphiQL web interface for HTTP API at 0.0.0.0:9000/graphiql
I1126 14:07:13.983025       1 run.go:171] Bringing up GraphQL HTTP admin API at 0.0.0.0:9000/admin
I1126 14:07:13.983047       1 run.go:172] Bringing up GraphiQL web interface for HTTP admin API at 0.0.0.0:9000/admin/graphiql
I1126 14:07:13.984334       1 admin.go:276] Trying to connect to Dgraph at local_server_1:9080
I1126 14:07:33.988844       1 admin.go:276] Trying to connect to Dgraph at local_server_1:9080

And then it just keeps trying. And Just to recap, I am able to connect via dgo(the docker client to ipaddress)… hmm, I will just try with the ip address.

Same thing with:
If I docker run with “–network=“host”” and use “–alpha=127.0.0.1:9080” I get a connection:

I1126 15:42:54.555586       1 run.go:137] Starting GraphQL with Dgraph at: 127.0.0.1:9080
I1126 15:42:54.556323       1 admin.go:276] Trying to connect to Dgraph at 127.0.0.1:9080
I1126 15:42:54.566899       1 run.go:169] Bringing up GraphQL HTTP API at 0.0.0.0:9000/graphql
I1126 15:42:54.567009       1 run.go:170] Bringing up GraphiQL web interface for HTTP API at 0.0.0.0:9000/graphiql
I1126 15:42:54.567038       1 run.go:171] Bringing up GraphQL HTTP admin API at 0.0.0.0:9000/admin
I1126 15:42:54.567085       1 run.go:172] Bringing up GraphiQL web interface for HTTP admin API at 0.0.0.0:9000/admin/graphiql
I1126 15:42:54.602796       1 admin.go:285] Established Dgraph connection
I1126 15:43:04.590033       1 admin.go:276] Trying to connect to Dgraph at 127.0.0.1:9080
I1126 15:43:04.599727       1 admin.go:285] Established Dgraph connection
I1126 15:43:14.605770       1 admin.go:276] Trying to connect to Dgraph at 127.0.0.1:9080
I1126 15:43:14.613432       1 admin.go:285] Established Dgraph connection
I1126 15:43:24.620181       1 admin.go:276] Trying to connect to Dgraph at 127.0.0.1:9080
I1126 15:43:24.628213       1 admin.go:285] Established Dgraph connection
I1126 15:43:34.600236       1 admin.go:276] Trying to connect to Dgraph at 127.0.0.1:9080

It keeps doing “Trying to connect” and “Established Dgraph connection” maybe it is just checking for health?

I will try with graphql_playground and get back…

But I would still expect it to be able to use local_default network?


(J Czz) #9

Just tried to apply the schema from the “Quick Start”- got Connection refused:

jq -n --arg schema "$(cat schema.graphql)" '{ query: "mutation addSchema($sch: String!) { addSchema(input: { schema: $sch }) { schema { schema } } }", variables: { sch: $schema }}' | curl -X POST -H "Content-Type: application/json" http://localhost:9000/admin -d @- | jq -r

% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
curl: (7) Failed to connect to localhost port 9000: Connection refused

(J Czz) #10

Connection is refused do to a warning when running docker with --network="host":

docker run --network="host" -v $(pwd):/dgraph -p 9000:9000 -it dgraph/standalone:graphql dgraph graphql --alpha=127.0.0.1:9080

WARNING: Published ports are discarded when using host network mode

I will keep trying to see if I can connect via local_default network…


(J Czz) #11

Just for information:
docker run -v $(pwd):/dgraph -p 9000:9000 -it dgraph/standalone:graphql

It works no problem, but The “Advanced Options” is still an issue - described here: https://graphql.dgraph.io/docs/admin/


(Daniel Mai) #12

Can you share how you’re running Dgraph itself? The key here is to get both Dgraph and the GraphQL API on Dgraph networked together. If you want everything to run on your host network namespace, then you can use the --network host option for docker run, don’t use -p to publish any ports, and point everything to the proper ports on localhost.


(J Czz) #13

Easy to reproduce in three steps :wink:

Step 1. Standard dgraph setup from: https://docs.dgraph.io/get-started/#docker-compose
I am running:
docker-compose up -d
This works as expected, and is exposing / mapped from the compose file incl. port 9080.

Step 2.
Now I tried:
docker run --network="host" -v $(pwd):/dgraph -it dgraph/standalone:graphql dgraph graphql --alpha=127.0.0.1:9080

And it looks like it is running:

I1126 19:08:03.829936       1 run.go:137] Starting GraphQL with Dgraph at: 127.0.0.1:9080
I1126 19:08:03.832279       1 run.go:169] Bringing up GraphQL HTTP API at 0.0.0.0:9000/graphql
I1126 19:08:03.832356       1 run.go:170] Bringing up GraphiQL web interface for HTTP API at 0.0.0.0:9000/graphiql
I1126 19:08:03.832383       1 run.go:171] Bringing up GraphQL HTTP admin API at 0.0.0.0:9000/admin
I1126 19:08:03.832406       1 run.go:172] Bringing up GraphiQL web interface for HTTP admin API at 0.0.0.0:9000/admin/graphiql
I1126 19:08:03.832868       1 admin.go:276] Trying to connect to Dgraph at 127.0.0.1:9080
I1126 19:08:03.838535       1 admin.go:285] Established Dgraph connection
I1126 19:08:13.852418       1 admin.go:276] Trying to connect to Dgraph at 127.0.0.1:9080
I1126 19:08:13.856081       1 admin.go:285] Established Dgraph connection

Step 3. The adding the schema:

jq -n --arg schema "$(cat schema.graphql)" '{ query: "mutation addSchema($sch: String!) { addSchema(input: { schema: $sch }) { schema { schema } } }", variables: { sch: $schema }}' | curl -X POST -H "Content-Type: application/json" http://localhost:9000/admin -d @- | jq -r
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
curl: (7) Failed to connect to localhost port 9000: Connection refused

You mention “Dgraph networked” - I have standard “local_default”?

This will eventually run on Kubernetes cluster, I just need to see it work on my local machine.


(Daniel Mai) #14

This error message means wherever you’re running the jq / curl command cannot reach localhost:9000. Can you confirm that localhost:9000 is accessible? The --network="host" Docker option only works on Linux, not Docker for Mac or Docker for Windows.

If you curl the /admin endpoint you should get a response back.

$ curl localhost:9000/admin

{"errors":[{"message":"no query string supplied in request"}],"extensions":{"requestID":"6f732a5e-e201-4e49-bf22-a16521fe1a68"}}%                                                                                                                         

Another thing: GraphQL API for Dgraph currently requires Dgraph version from master, not v1.1.0. The Docker Compose config you find on docs is configured to run v1.1.0, so you’ll need to change the image to the master version in your test.


(J Czz) #15

Ok thanks

Well I am running Docker for Mac :slight_smile: I will try to see if I can get it up and running on Kubernetes - any suggestion, apart from running Dgraph version from master - git master branch right, and is there a docker container containing this?

And for local testing, maybe a docker-compose.yaml file could help trying out this scenario?


(Daniel Mai) #16

Actually, the current master Dgraph binary does not currently have the dgraph graphql subcommand. The main way to use the GraphQL API for Dgraph is with the dgraph/standalone:graphql image. Here’s a Docker Compose config for the “clustered” mode using that image. This should work on Mac too:

version: "3.2"
services:
  zero:
    image: dgraph/standalone:graphql
    volumes:
      - type: volume
        source: dgraph
        target: /dgraph
        volume:
          nocopy: true
    ports:
      - 5080:5080
      - 6080:6080
    command: dgraph zero --my=zero:5080
  alpha:
    image: dgraph/standalone:graphql
    volumes:
      - type: volume
        source: dgraph
        target: /dgraph
        volume:
          nocopy: true
    ports:
      - 8080:8080
      - 9080:9080
    command: dgraph alpha --my=alpha:7080 --lru_mb=2048 --zero=zero:5080
  graphql:
    image: dgraph/standalone:graphql
    volumes:
      - type: volume
        source: dgraph
        target: /dgraph
        volume:
          nocopy: true
    ports:
      - 9000:9000
    command: dgraph graphql --alpha alpha:9080
  ratel:
    image: dgraph/standalone:graphql
    volumes:
      - type: volume
        source: dgraph
        target: /dgraph
        volume:
          nocopy: true
    ports:
      - 8000:8000
    command: dgraph-ratel

volumes:
  dgraph:

Here are some points to notice:

  • Dgraph Zero, Dgraph Alpha, and Dgraph’s GraphQL API are run seperately for a distributed setup.
  • --my flags are set accordingly.
  • The GraphQL API command is set to dgraph graphql --alpha alpha:9080, where alpha:9080 is the hostname and port for the alpha container.

Once we officially release the GraphQL API for Dgraph, then you can use a versioned dgraph/dgraph image instead of the dgraph/standalone image.


(J Czz) #17

Thanks Daniel

Ahh sorry, I did not realise it had not been released. It is really cool, any idea on a wishfull release date?

I will enjoy playing around with it until released - thanks for the yaml file


(Daniel Mai) #18

The GraphQL API for Dgraph should be out alongside Dgraph v1.1.1, which should be out soon.


(J Czz) #19

Fantastic, and indeed the docker-compose you send me is working.

Update: No worries, I will just try to convert you docker-compose yaml file to K8s yaml file.
Thanks again Daniel - and I can’t wait to get my hands on the release :slight_smile:

Do you think I can get this up on Kubernetes, that will be really nice to show of?


(Daniel Mai) #20

A K8s config for Dgraph and the GraphQL API is definitely possible. Looking forward to hearing you getting it working.