Skip to content

Commit ee5c9c7

Browse files
fix trunk check
1 parent 37d1f47 commit ee5c9c7

File tree

5 files changed

+109
-106
lines changed

5 files changed

+109
-106
lines changed

examples/simple/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const dgraph = require("dgraph-js")
1+
import * as dgraph from "dgraph-js"
22

33
// Drop All - discard all data, schema and start from a clean slate.
44
async function dropAll(dgraphClient) {
@@ -115,7 +115,7 @@ async function queryData(dgraphClient) {
115115
}
116116

117117
async function main() {
118-
const dgraphClient = await dgraph.open("dgraph://groot:password@localhost:8090")
118+
const dgraphClient = await dgraph.open("dgraph://groot:password@localhost:9080")
119119
await dropAll(dgraphClient)
120120
await setSchema(dgraphClient)
121121
await createData(dgraphClient)

examples/simple/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"name": "simple",
3+
"type": "module",
34
"dependencies": {
45
"dgraph-js": "^24.1.0",
56
"@grpc/grpc-js": "1.8.22"

examples/tls/index.js

Lines changed: 103 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,121 +1,121 @@
11
const fs = require('fs');
22
const path = require('path');
33

4-
const dgraph = require("dgraph-js");
4+
import * as dgraph from "dgraph-js";
55

66
// Create a client stub.
77
function newClientStub() {
8-
// First create the appropriate TLS certs with dgraph cert:
9-
// $ dgraph cert
10-
// $ dgraph cert -n localhost
11-
// $ dgraph cert -c user
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-
);
20-
return new dgraph.DgraphClientStub(
21-
"localhost:9080",
22-
dgraph.grpc.credentials.createSsl(rootCaCert, clientCertKey, clientCert)
23-
);
8+
// First create the appropriate TLS certs with dgraph cert:
9+
// $ dgraph cert
10+
// $ dgraph cert -n localhost
11+
// $ dgraph cert -c user
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+
);
20+
return new dgraph.DgraphClientStub(
21+
"localhost:9080",
22+
dgraph.grpc.credentials.createSsl(rootCaCert, clientCertKey, clientCert)
23+
);
2424
}
2525

2626
// Create a client.
2727
function newClient(clientStub) {
28-
return new dgraph.DgraphClient(clientStub);
28+
return new dgraph.DgraphClient(clientStub);
2929
}
3030

3131
// Drop All - discard all data and start from a clean slate.
3232
async function dropAll(dgraphClient) {
33-
const op = new dgraph.Operation();
34-
op.setDropAll(true);
35-
await dgraphClient.alter(op);
33+
const op = new dgraph.Operation();
34+
op.setDropAll(true);
35+
await dgraphClient.alter(op);
3636
}
3737

3838
// Set schema.
3939
async function setSchema(dgraphClient) {
40-
const schema = `
40+
const schema = `
4141
name: string @index(exact) .
4242
age: int .
4343
married: bool .
4444
loc: geo .
4545
dob: datetime .
4646
friend: [uid] @reverse .
4747
`;
48-
const op = new dgraph.Operation();
49-
op.setSchema(schema);
50-
await dgraphClient.alter(op);
48+
const op = new dgraph.Operation();
49+
op.setSchema(schema);
50+
await dgraphClient.alter(op);
5151
}
5252

5353
// Create data using JSON.
5454
async function createData(dgraphClient) {
55-
// Create a new transaction.
56-
const txn = dgraphClient.newTxn();
57-
try {
58-
// Create data.
59-
const p = {
60-
uid: "_:alice",
61-
name: "Alice",
62-
age: 26,
63-
married: true,
64-
loc: {
65-
type: "Point",
66-
coordinates: [1.1, 2],
67-
},
68-
dob: new Date(1980, 1, 1, 23, 0, 0, 0),
69-
friend: [
70-
{
71-
name: "Bob",
72-
age: 24,
73-
},
74-
{
75-
name: "Charlie",
76-
age: 29,
77-
},
78-
],
79-
school: [
80-
{
81-
name: "Crown Public School",
82-
},
83-
],
84-
};
55+
// Create a new transaction.
56+
const txn = dgraphClient.newTxn();
57+
try {
58+
// Create data.
59+
const p = {
60+
uid: "_:alice",
61+
name: "Alice",
62+
age: 26,
63+
married: true,
64+
loc: {
65+
type: "Point",
66+
coordinates: [1.1, 2],
67+
},
68+
dob: new Date(1980, 1, 1, 23, 0, 0, 0),
69+
friend: [
70+
{
71+
name: "Bob",
72+
age: 24,
73+
},
74+
{
75+
name: "Charlie",
76+
age: 29,
77+
},
78+
],
79+
school: [
80+
{
81+
name: "Crown Public School",
82+
},
83+
],
84+
};
8585

86-
// Run mutation.
87-
const mu = new dgraph.Mutation();
88-
mu.setSetJson(p);
89-
const response = await txn.mutate(mu);
86+
// Run mutation.
87+
const mu = new dgraph.Mutation();
88+
mu.setSetJson(p);
89+
const response = await txn.mutate(mu);
9090

91-
// Commit transaction.
92-
await txn.commit();
91+
// Commit transaction.
92+
await txn.commit();
9393

94-
// Get uid of the outermost object (person named "Alice").
95-
// Response#getUidsMap() returns a map from blank node names to uids.
96-
// For a json mutation, blank node label is used for the name of the created nodes.
97-
console.log(
98-
`Created person named "Alice" with uid = ${response
99-
.getUidsMap()
100-
.get("alice")}\n`
101-
);
94+
// Get uid of the outermost object (person named "Alice").
95+
// Response#getUidsMap() returns a map from blank node names to uids.
96+
// For a json mutation, blank node label is used for the name of the created nodes.
97+
console.log(
98+
`Created person named "Alice" with uid = ${response
99+
.getUidsMap()
100+
.get("alice")}\n`
101+
);
102102

103-
console.log("All created nodes (map from blank node names to uids):");
104-
response
105-
.getUidsMap()
106-
.forEach((uid, key) => console.log(`${key} => ${uid}`));
107-
console.log();
108-
} finally {
109-
// Clean up. Calling this after txn.commit() is a no-op
110-
// and hence safe.
111-
await txn.discard();
112-
}
103+
console.log("All created nodes (map from blank node names to uids):");
104+
response
105+
.getUidsMap()
106+
.forEach((uid, key) => console.log(`${key} => ${uid}`));
107+
console.log();
108+
} finally {
109+
// Clean up. Calling this after txn.commit() is a no-op
110+
// and hence safe.
111+
await txn.discard();
112+
}
113113
}
114114

115115
// Query for data.
116116
async function queryData(dgraphClient) {
117-
// Run query.
118-
const query = `query all($a: string) {
117+
// Run query.
118+
const query = `query all($a: string) {
119119
all(func: eq(name, $a)) {
120120
uid
121121
name
@@ -132,33 +132,33 @@ async function queryData(dgraphClient) {
132132
}
133133
}
134134
}`;
135-
const vars = { $a: "Alice" };
136-
const res = await dgraphClient
137-
.newTxn({ readOnly: true })
138-
.queryWithVars(query, vars);
139-
const ppl = res.getJson();
135+
const vars = { $a: "Alice" };
136+
const res = await dgraphClient
137+
.newTxn({ readOnly: true })
138+
.queryWithVars(query, vars);
139+
const ppl = res.getJson();
140140

141-
// Print results.
142-
console.log(`Number of people named "Alice": ${ppl.all.length}`);
143-
ppl.all.forEach((person) => console.log(person));
141+
// Print results.
142+
console.log(`Number of people named "Alice": ${ppl.all.length}`);
143+
ppl.all.forEach((person) => console.log(person));
144144
}
145145

146146
async function main() {
147-
const dgraphClientStub = newClientStub();
148-
const dgraphClient = newClient(dgraphClientStub);
149-
await dropAll(dgraphClient);
150-
await setSchema(dgraphClient);
151-
await createData(dgraphClient);
152-
await queryData(dgraphClient);
147+
const dgraphClientStub = newClientStub();
148+
const dgraphClient = newClient(dgraphClientStub);
149+
await dropAll(dgraphClient);
150+
await setSchema(dgraphClient);
151+
await createData(dgraphClient);
152+
await queryData(dgraphClient);
153153

154-
// Close the client stub.
155-
dgraphClientStub.close();
154+
// Close the client stub.
155+
dgraphClientStub.close();
156156
}
157157

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

examples/tls/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
22
"name": "tls",
3+
"type": "module",
34
"dependencies": {
45
"dgraph-js": "^24.0.0"
56
},
67
"scripts": {
78
"example": "node index.js",
8-
"clean": "rm -rf node_modules"
9+
"clean": "rm -fr node_modules"
910
}
1011
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "24.1.0",
44
"description": "Official javascript client for Dgraph",
55
"license": "Apache-2.0",
6+
"type": "module",
67
"repository": {
78
"type": "git",
89
"url": "https://github.com/hypermodeinc/dgraph-js.git"

0 commit comments

Comments
 (0)