@@ -2,20 +2,25 @@ const fs = require('fs');
22const path = require ( 'path' ) ;
33
44const dgraph = require ( "dgraph-js" ) ;
5- const grpc = require ( "grpc" ) ;
65
76// Create a client stub.
87function 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+ } ) ;
0 commit comments