Skip to content

Commit

Permalink
docs(clients): Add multi-tenancy to Dgraph client docs (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
bucanero authored Mar 19, 2021
1 parent 4aef10c commit be4c8b0
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 6 deletions.
23 changes: 23 additions & 0 deletions content/clients/go.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,29 @@ func newClient() *dgo.Dgraph {

```

### Multi-tenancy

In [multi-tenancy]({{< relref "multitenancy.md" >}}) environments, Dgraph provides a new method `LoginIntoNamespace()`,
which will allow the users to login to a specific namespace.

In order to create a dgo client, and make the client login into namespace `123`:

```go
conn, err := grpc.Dial("127.0.0.1:9080", grpc.WithInsecure())
if err != nil {
glog.Error("While trying to dial gRPC, got error", err)
}
dc := dgo.NewDgraphClient(api.NewDgraphClient(conn))
ctx := context.Background()
// Login to namespace 123
if err := dc.LoginIntoNamespace(ctx, "groot", "password", 123); err != nil {
glog.Error("Failed to login: ",err)
}
```

In the example above, the client logs into namespace `123` using username `groot` and password `password`.
Once logged in, the client can perform all the operations allowed to the `groot` user of namespace `123`.

### Creating a Client for Slash GraphQL Endpoint

If you want to connect to Dgraph running on your [Slash GraphQL](https://slash.dgraph.io) instance, then all you need is the URL of your Slash GraphQL endpoint and the API key. You can get a client using them as follows:
Expand Down
24 changes: 18 additions & 6 deletions content/clients/java.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,24 @@ DgraphStub stub3 = DgraphGrpc.newStub(channel3);

DgraphClient dgraphClient = new DgraphClient(stub1, stub2, stub3);
```
### Login using ACL

If [ACL]({{< relref "access-control-lists.md" >}}) is enabled then you can log-in to the default namespace (`0`) with the following method:

```java
dgraphClient.login(USER_ID, USER_PASSWORD);
```

### Multi-tenancy

If [multi-tenancy]({{< relref "multitenancy.md" >}}) is enabled, by default the login method on client will login into the namespace `0`.
In order to login into some other namespace, use the `loginIntoNamespace` method on the client:

```java
dgraphClient.loginIntoNamespace(USER_ID, USER_PASSWORD, NAMESPACE);
```

Once logged-in, the `dgraphClient` object can be used to do any further operations.

### Creating a Client for Slash GraphQL Endpoint

Expand Down Expand Up @@ -118,12 +136,6 @@ is able to communicate with the Dgraph server. This will also help reduce the la
query/mutation which results from some dynamic library loading and linking that happens in JVM
(see [this issue](https://github.com/dgraph-io/dgraph4j/issues/108) for more details).

### Login Using ACL

```java
dgraphClient.login(USER_ID, USER_PASSWORD);
```

### Altering the Database

To set the schema, create an `Operation` object, set the schema and pass it to
Expand Down
15 changes: 15 additions & 0 deletions content/clients/javascript/grpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,21 @@ const dgraphClient = new dgraph.DgraphClient(clientStub);

To facilitate debugging, [debug mode](#debug-mode) can be enabled for a client.

### Multi-tenancy

In [multi-tenancy]({{< relref "multitenancy.md" >}}) environments, `dgraph-js` provides a new method `loginIntoNamespace()`,
which will allow the users to login to a specific namespace.

In order to create a JavaScript client, and make the client login into namespace `123`:

```js
const dgraphClientStub = new dgraph.DgraphClientStub("localhost:9080");
await dgraphClientStub.loginIntoNamespace("groot", "password", 123); // where 123 is the namespaceId
```

In the example above, the client logs into namespace `123` using username `groot` and password `password`.
Once logged in, the client can perform all the operations allowed to the `groot` user of namespace `123`.

### Creating a Client for Slash GraphQL Endpoint

If you want to connect to Dgraph running on your [Slash GraphQL](https://slash.dgraph.io) instance, then all you need is the URL of your Slash GraphQL endpoint and the API key. You can get a client using them as follows:
Expand Down
17 changes: 17 additions & 0 deletions content/clients/python.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,23 @@ client_stub = pydgraph.DgraphClientStub('localhost:9080')
client = pydgraph.DgraphClient(client_stub)
```

### Multi-tenancy

In [multi-tenancy]({{< relref "multitenancy.md" >}}) environments, PyDgraph provides a new method `login_in_namespace()`,
which will allow the users to login to a specific namespace.

In order to create a python client, and make the client login into namespace `123`:

```python
client_stub = pydgraph.DgraphClientStub('localhost:9080')
client = pydgraph.DgraphClient(client_stub)
// Login to namespace groot user of namespace 123
client.login_in_namespace("groot", "password", "123")
```

In the example above, the client logs into namespace `123` using username `groot` and password `password`.
Once logged in, the client can perform all the operations allowed to the `groot` user of namespace `123`.

### Creating a Client for Slash GraphQL Endpoint

If you want to connect to Dgraph running on your [Slash GraphQL](https://slash.dgraph.io) instance, then all you need is the URL of your Slash GraphQL endpoint and the API key. You can get a client using them as follows:
Expand Down

0 comments on commit be4c8b0

Please sign in to comment.