Skip to content

Commit 60b803c

Browse files
Update gRPC library in dgraph-js to use gRPC-js
2 parents 3f83745 + 11790e8 commit 60b803c

27 files changed

+555
-270
lines changed

examples/simple/index.js

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const dgraph = require("dgraph-js");
2-
const grpc = require("grpc");
32

43
// Create a client stub.
54
function newClientStub() {
@@ -64,13 +63,13 @@ async function createData(dgraphClient) {
6463
{
6564
name: "Charlie",
6665
age: 29,
67-
}
66+
},
6867
],
6968
school: [
7069
{
7170
name: "Crown Public School",
72-
}
73-
]
71+
},
72+
],
7473
};
7574

7675
// Run mutation.
@@ -84,10 +83,16 @@ async function createData(dgraphClient) {
8483
// Get uid of the outermost object (person named "Alice").
8584
// Response#getUidsMap() returns a map from blank node names to uids.
8685
// For a json mutation, blank node label is used for the name of the created nodes.
87-
console.log(`Created person named "Alice" with uid = ${response.getUidsMap().get("alice")}\n`);
86+
console.log(
87+
`Created person named "Alice" with uid = ${response
88+
.getUidsMap()
89+
.get("alice")}\n`,
90+
);
8891

8992
console.log("All created nodes (map from blank node names to uids):");
90-
response.getUidsMap().forEach((uid, key) => console.log(`${key} => ${uid}`));
93+
response
94+
.getUidsMap()
95+
.forEach((uid, key) => console.log(`${key} => ${uid}`));
9196
console.log();
9297
} finally {
9398
// Clean up. Calling this after txn.commit() is a no-op
@@ -117,7 +122,9 @@ async function queryData(dgraphClient) {
117122
}
118123
}`;
119124
const vars = { $a: "Alice" };
120-
const res = await dgraphClient.newTxn({ readOnly: true }).queryWithVars(query, vars);
125+
const res = await dgraphClient
126+
.newTxn({ readOnly: true })
127+
.queryWithVars(query, vars);
121128
const ppl = res.getJson();
122129

123130
// Print results.
@@ -141,8 +148,10 @@ async function main() {
141148
dgraphClientStub.close();
142149
}
143150

144-
main().then(() => {
145-
console.log("\nDONE!");
146-
}).catch((e) => {
147-
console.log("ERROR: ", e);
148-
});
151+
main()
152+
.then(() => {
153+
console.log("\nDONE!");
154+
})
155+
.catch((e) => {
156+
console.log("ERROR: ", e);
157+
});

examples/tls/index.js

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,25 @@ const fs = require('fs');
22
const path = require('path');
33

44
const dgraph = require("dgraph-js");
5-
const grpc = require("grpc");
65

76
// Create a client stub.
87
function newClientStub() {
98
// First create the appropriate TLS certs with dgraph cert:
109
// $ dgraph cert
1110
// $ dgraph cert -n localhost
1211
// $ dgraph cert -c user
13-
const rootCaCert = fs.readFileSync(path.join(__dirname, 'tls', 'ca.crt'));
14-
const clientCertKey = fs.readFileSync(path.join(__dirname, 'tls', 'client.user.key'));
15-
const clientCert = fs.readFileSync(path.join(__dirname, 'tls', 'client.user.crt'));
12+
console.log(path.join(__dirname, "tls", "ca.crt"));
13+
const rootCaCert = fs.readFileSync(path.join(__dirname, "tls", "ca.crt"));
14+
const clientCertKey = fs.readFileSync(
15+
path.join(__dirname, "tls", "client.user.key")
16+
);
17+
const clientCert = fs.readFileSync(
18+
path.join(__dirname, "tls", "client.user.crt")
19+
);
1620
return new dgraph.DgraphClientStub(
1721
"localhost:9080",
18-
grpc.credentials.createSsl(rootCaCert, clientCertKey, clientCert));
22+
dgraph.grpc.credentials.createSsl(rootCaCert, clientCertKey, clientCert)
23+
);
1924
}
2025

2126
// Create a client.
@@ -69,13 +74,13 @@ async function createData(dgraphClient) {
6974
{
7075
name: "Charlie",
7176
age: 29,
72-
}
77+
},
7378
],
7479
school: [
7580
{
7681
name: "Crown Public School",
77-
}
78-
]
82+
},
83+
],
7984
};
8085

8186
// Run mutation.
@@ -89,10 +94,16 @@ async function createData(dgraphClient) {
8994
// Get uid of the outermost object (person named "Alice").
9095
// Response#getUidsMap() returns a map from blank node names to uids.
9196
// For a json mutation, blank node label is used for the name of the created nodes.
92-
console.log(`Created person named "Alice" with uid = ${response.getUidsMap().get("alice")}\n`);
97+
console.log(
98+
`Created person named "Alice" with uid = ${response
99+
.getUidsMap()
100+
.get("alice")}\n`
101+
);
93102

94103
console.log("All created nodes (map from blank node names to uids):");
95-
response.getUidsMap().forEach((uid, key) => console.log(`${key} => ${uid}`));
104+
response
105+
.getUidsMap()
106+
.forEach((uid, key) => console.log(`${key} => ${uid}`));
96107
console.log();
97108
} finally {
98109
// Clean up. Calling this after txn.commit() is a no-op
@@ -122,7 +133,9 @@ async function queryData(dgraphClient) {
122133
}
123134
}`;
124135
const vars = { $a: "Alice" };
125-
const res = await dgraphClient.newTxn({ readOnly: true }).queryWithVars(query, vars);
136+
const res = await dgraphClient
137+
.newTxn({ readOnly: true })
138+
.queryWithVars(query, vars);
126139
const ppl = res.getJson();
127140

128141
// Print results.
@@ -142,8 +155,10 @@ async function main() {
142155
dgraphClientStub.close();
143156
}
144157

145-
main().then(() => {
146-
console.log("\nDONE!");
147-
}).catch((e) => {
148-
console.log("ERROR: ", e);
149-
});
158+
main()
159+
.then(() => {
160+
console.log("\nDONE!");
161+
})
162+
.catch((e) => {
163+
console.log("ERROR: ", e);
164+
});

examples/tls/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"name": "tls",
33
"dependencies": {
4-
"dgraph-js": "^20.3.0",
5-
"grpc": "^1.24.2"
4+
"dgraph-js": "^20.3.0"
65
}
76
}

generated/api_grpc_pb.d.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,49 @@
11
// package: api
22
// file: api.proto
33

4-
import * as grpc from "grpc";
4+
import * as grpc from "@grpc/grpc-js";
55
import * as api_pb from "./api_pb";
66

77
export class DgraphClient extends grpc.Client {
88
public login(
99
request: api_pb.LoginRequest,
1010
metadata: grpc.Metadata | null,
1111
options: grpc.CallOptions | null,
12-
callback: (err?: Error | null, res?: api_pb.Response) => void,
12+
callback: (err?: Error | null, res?: api_pb.Response) => void
1313
): void;
1414

1515
public alter(
1616
operation: api_pb.Operation,
1717
metadata: grpc.Metadata | null,
1818
options: grpc.CallOptions | null,
19-
callback: (err?: Error | null, res?: api_pb.Payload) => void,
19+
callback: (err?: Error | null, res?: api_pb.Payload) => void
2020
): void;
2121

2222
public query(
2323
request: api_pb.Request,
2424
metadata: grpc.Metadata | null,
2525
options: grpc.CallOptions | null,
26-
callback: (err?: Error | null, res?: api_pb.Response) => void,
26+
callback: (err?: Error | null, res?: api_pb.Response) => void
2727
): void;
2828

2929
public mutate(
3030
request: api_pb.Mutation,
3131
metadata: grpc.Metadata | null,
3232
options: grpc.CallOptions | null,
33-
callback: (err?: Error | null, res?: api_pb.Response) => void,
33+
callback: (err?: Error | null, res?: api_pb.Response) => void
3434
): void;
3535

3636
public commitOrAbort(
3737
request: api_pb.TxnContext,
3838
metadata: grpc.Metadata | null,
3939
options: grpc.CallOptions | null,
40-
callback: (err?: Error | null, res?: api_pb.TxnContext) => void,
40+
callback: (err?: Error | null, res?: api_pb.TxnContext) => void
4141
): void;
4242

4343
public checkVersion(
4444
request: api_pb.Check,
4545
metadata: grpc.Metadata | null,
4646
options: grpc.CallOptions | null,
47-
callback: (err?: Error | null, res?: api_pb.Version) => void,
47+
callback: (err?: Error | null, res?: api_pb.Version) => void
4848
): void;
4949
}

0 commit comments

Comments
 (0)