@@ -3,21 +3,28 @@ const grpc = require("grpc");
33
44// Create a client stub.
55function newClientStub ( ) {
6- return new dgraph . DgraphClientStub ( "localhost:9080" , grpc . credentials . createInsecure ( ) ) ;
6+ return new dgraph . DgraphClientStub ( "localhost:9080" ) ;
77}
88
99// Create a client.
1010function newClient ( clientStub ) {
1111 return new dgraph . DgraphClient ( clientStub ) ;
1212}
1313
14- // Drop All - discard all data and start from a clean slate.
14+ // Drop All - discard all data, schema and start from a clean slate.
1515async function dropAll ( dgraphClient ) {
1616 const op = new dgraph . Operation ( ) ;
1717 op . setDropAll ( true ) ;
1818 await dgraphClient . alter ( op ) ;
1919}
2020
21+ // Drop All Data, but keep the schema.
22+ async function dropData ( dgraphClient ) {
23+ const op = new dgraph . Operation ( ) ;
24+ op . setDropOp ( dgraph . Operation . DropOp . DATA ) ;
25+ await dgraphClient . alter ( op ) ;
26+ }
27+
2128// Set schema.
2229async function setSchema ( dgraphClient ) {
2330 const schema = `
@@ -125,6 +132,10 @@ async function main() {
125132 await setSchema ( dgraphClient ) ;
126133 await createData ( dgraphClient ) ;
127134 await queryData ( dgraphClient ) ;
135+ await dropData ( dgraphClient ) ;
136+ await queryData ( dgraphClient ) ;
137+ await createData ( dgraphClient ) ;
138+ await queryData ( dgraphClient ) ;
128139
129140 // Close the client stub.
130141 dgraphClientStub . close ( ) ;
0 commit comments