Using Dgo and Slash GraphQL

Hello I’m starting to use graphql for a side project I have.

I’ve been using a local docker container to run my test and after the talk yesterday I decided to test slash graphql.
Right now I seem to have hit a roadblock.
I’m unable to get any Query to run, I keep getting messages like this:

rpc error: code = Unknown desc = : HTTP status code 464; transport: missing content-type field
Or
rpc error: code = Unimplemented desc = Not Found: HTTP status code 404; transport: received the unexpected content-type “text/plain; charset=utf-8”

I’m using this code to do the authentication to the slash dgraph

All of this is very confusing because I don’t know what part is bugging with what.

Thanks for your help :slight_smile:

Edit:
Just wanted to say that I’ve configured the backing in Flexible mode

From what I managed to debug, the code is able to connect to the database.
But when sending a request The server responds with a 404 and some text

INFO: 2020/09/11 23:45:45 [core] parsed scheme: ""
INFO: 2020/09/11 23:45:45 [core] scheme "" not registered, fallback to default scheme
INFO: 2020/09/11 23:45:45 [core] ccResolverWrapper: sending update to cc: {[{-------------.aws.cloud.dgraph.io:443  <nil> 0 <nil>}] <nil> <nil>}
INFO: 2020/09/11 23:45:45 [core] ClientConn switching balancer to "pick_first"
INFO: 2020/09/11 23:45:45 [core] Channel switches to new LB policy "pick_first"
INFO: 2020/09/11 23:45:45 [core] Subchannel Connectivity change to CONNECTING
INFO: 2020/09/11 23:45:45 [core] pickfirstBalancer: UpdateSubConnState: 0xc00030a1e0, {CONNECTING <nil>}
INFO: 2020/09/11 23:45:45 [core] Channel Connectivity change to CONNECTING
INFO: 2020/09/11 23:45:45 [core] Subchannel picks a new address "-------------:443" to connect
INFO: 2020/09/11 23:45:45 [core] Subchannel Connectivity change to READY
INFO: 2020/09/11 23:45:45 [core] pickfirstBalancer: UpdateSubConnState: 0xc00030a1e0, {READY <nil>}
INFO: 2020/09/11 23:45:45 [core] Channel Connectivity change to READY
2020/09/11 23:45:45 rpc error: code = Unimplemented desc = Not Found: HTTP status code 404; transport: received the unexpected content-type "text/plain; charset=utf-8"
exit status 1

Could something be miss configured?

@sbres I believe you are using wrong url to establish grpc connection. For example, if your GraphQL Endpoint is https://frozen-mango-42.eu-central-1.aws.cloud.dgraph.io/graphql , your gRPC endpoint will be frozen-mango-42.grpc.eu-central-1.aws.cloud.dgraph.io:443. Do check the grpc tag which is different. Please confirm this if this is the case.

Yes, what @aman-bansal mentioned. Also @Anurag will have a PR for dgo in the next few days, so that this is much easier to do.

Thanks for your messages, but I’m indeed using the right endpoint.
@aman-bansal
Could you please elaborate which tag is different? Right now the code is based on the example code I posted. I saw another post, where someone else managed to connect using it.

@gja Great news, maybe I should keep using my local instance and wait for the PR?

@sbres So in general if your backend endpoint is <name>.<region>.<Identity Provided>.dgraph.io, then grpc endpoint would be <name>.grpc.<region>.<Identity Provided>.dgraph.io difference is grpc tag between name and region. Here is the sample I have tested.

pool, err := x509.SystemCertPool()
   if err != nil {
      panic(err)
   }
   conn, err := grpc.Dial("grpc_url:443", grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{
      RootCAs:    pool,
      ServerName: strings.Split("grpc_url:443", ":")[0],
   })),
      grpc.WithPerRPCCredentials({authorization object}))
   if err != nil {
      panic(err)
   }
   dgraphClient := api.NewDgraphClient(conn)
   client := dgo.NewDgraphClient(dgraphClient)
   mut := "{\n   queryPerson(func: type(Person))  {\n     Person.name\n     Person.age\n     Person.country\n  }\n}"

   do, err := client.NewTxn().Do(context.Background(), &api.Request{
      Query: mut,
   })
   if err != nil {
      panic(err)
   }
   log.Print(do)

This is the schema I am using.

type Person {
 name: String! @search(by: [fulltext])
 age: Int
 country: String
}

One thing to note is that ACL is still not implemented in Slash. So login endpoint will not work for now.

@aman-bansal :partying_face: :partying_face: :partying_face:
Amazing, It’s working now. Such a small mistake on my side. I was starting to become crazy on my code.

I think adding something on this page would help people to avoid missing it.
Something like
“Don’t be like Stephane and remember to add .grpc to your hostname” hahaha

Thanks a lot for the help :slight_smile:

1 Like

It’s great to hear that you are unblocked now.

Seems interesting :joy: but I think it should be more clear on the slash dashboard itself. Considering the impact and difference, it’s quite easy to miss.

@gja can we mention two separate URLs (one for HTTP and one for GRPC) in the slash dashboard? I believe that might need some design consideration. This is an easy miss. We should think to improve clarity around this.

@sbres what we are thinking is that all clients will just accept the slash graphql endpoint as it is on the dashboard, and figure out everything internally. PR here: feat(Slash gRPC Client): Add gRPC support for Slash endpoints. by anurags92 · Pull Request #137 · dgraph-io/dgo · GitHub

2 Likes