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) // Where to put the KEY?
	val stub = DgraphGrpc.newStub(channel)

	new DgraphClient(stub)

Even in 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("", 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:$AnnotatedConnectException: Connection timed out: no further information:
Caused by: Connection timed out: no further information
	at java.base/ Method)

Here is a working snippet:

    ManagedChannel channel =
        ManagedChannelBuilder.forAddress("<your-name>", 443).useTransportSecurity().build();
    DgraphStub stub = DgraphGrpc.newStub(channel);

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

    return new DgraphClient(stub);