# Connecting to Slash GraphQL using Dgraph4j

**URL:** <https://discuss.dgraph.io/t/connecting-to-slash-graphql-using-dgraph4j/10813>\
**Category:** Dgraph Clients\
**Tags:** dgraph4j, kind:feature\
**Created:** [October 7, 2020, 3:54am UTC](https://discuss.dgraph.io/t/connecting-to-slash-graphql-using-dgraph4j/10813 "2020-10-07T03:54:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![wiradikusuma](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/wiradikusuma/32/1847_2.png) [@wiradikusuma](https://discuss.dgraph.io/u/wiradikusuma)\
**Post date:** [October 7, 2020, 3:54am UTC](https://discuss.dgraph.io/t/connecting-to-slash-graphql-using-dgraph4j/10813/1 "2020-10-07T03:54:07Z")

</div>

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 [GitHub - dgraph-io/dgraph4j: Official Dgraph Java client](https://github.com/dgraph-io/dgraph4j) there’s no mention of “Slash”.

---

<div class="post-metadata">

**Author:** ![gja](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/gja/32/2654_2.png) [@gja](https://discuss.dgraph.io/u/gja)\
**Post date:** [October 7, 2020, 5:43am UTC](https://discuss.dgraph.io/t/connecting-to-slash-graphql-using-dgraph4j/10813/2 "2020-10-07T05:43:07Z")

</div>

@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)

---

<div class="post-metadata">

**Author:** ![chewxy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/chewxy/32/4339_2.png) [@chewxy](https://discuss.dgraph.io/u/chewxy)\
**Post date:** [October 7, 2020, 5:55am UTC](https://discuss.dgraph.io/t/connecting-to-slash-graphql-using-dgraph4j/10813/3 "2020-10-07T05:55:26Z")

</div>

I moved this to a new topic.

---

<div class="post-metadata">

**Author:** ![wiradikusuma](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/wiradikusuma/32/1847_2.png) [@wiradikusuma](https://discuss.dgraph.io/u/wiradikusuma)\
**Post date:** [October 7, 2020, 2:34pm UTC](https://discuss.dgraph.io/t/connecting-to-slash-graphql-using-dgraph4j/10813/4 "2020-10-07T14:34:07Z")

</div>

@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)
```

---

<div class="post-metadata">

**Author:** ![gja](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/gja/32/2654_2.png) [@gja](https://discuss.dgraph.io/u/gja)\
**Post date:** [October 7, 2020, 4:58pm UTC](https://discuss.dgraph.io/t/connecting-to-slash-graphql-using-dgraph4j/10813/5 "2020-10-07T16:58:24Z")

</div>

Here is a working snippet:

```java
    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);

```
