Connecting to Slash GraphQL using Dgraph4j

Thanks, since @gja 's approach is the simplest I’ve used that and it works.

Next question:

How do I pass the API Key in Dgraph Client for Java?

private val client = {
	val channel = ManagedChannelBuilder.forAddress(DGRAPH_HOST, DGRAPH_PORT).usePlaintext.build // Where to put the KEY?
	val stub = DgraphGrpc.newStub(channel)

	new DgraphClient(stub)
}

Even in https://github.com/dgraph-io/dgraph4j there’s no mention of “Slash”.

@wiradikusuma Hi. We are still working on adding Slash GraphQL to dgraph4j. It should be in a week or so. In the meanwhile, it’s possible to connect to slash GraphQL similar to the other languages

  1. Create a GRPC connection with SSL (using system SSL certificates). useTransportSecurity() instead of usePlainText
  2. Passing the API Key as call credentials on the stub (withCallCredentials, passing in a CallCredentials that passes the api key in the ‘authorization’ field)

I moved this to a new topic.

@gja could you be more specific? I tried this:

private val client = {
	val channel = ManagedChannelBuilder.forAddress("myapp-01.us-west-2.aws.cloud.dgraph.io", 9080).useTransportSecurity().build
	val stub = DgraphGrpc.newStub(channel).withCallCredentials(
		MoreCallCredentials.from(OAuth2Credentials.create(new AccessToken("sOmEwEiRdCoDe3kSOV32NO8Af90yca952MnUcUs=", null))))

	new DgraphClient(stub)
}

But then after a minute I got this:

Caused by: io.grpc.netty.shaded.io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection timed out: no further information: myapp-01.us-west-2.aws.cloud.dgraph.io/12.34.56.78:9080
Caused by: java.net.ConnectException: Connection timed out: no further information
	at java.base/sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)

Here is a working snippet:

    ManagedChannel channel =
        ManagedChannelBuilder.forAddress("<your-name>.grpc.us-east-1.aws.thegaas.com", 443).useTransportSecurity().build();
    DgraphStub stub = DgraphGrpc.newStub(channel);

    Metadata metadata = new Metadata();
    metadata.put(
        Metadata.Key.of("authorization", Metadata.ASCII_STRING_MARSHALLER), "<api-key-here>");
    stub = MetadataUtils.attachHeaders(stub, metadata);

    return new DgraphClient(stub);