@@ -179,7 +179,8 @@ err := client.SetSchema(context.TODO(), dgo.RootNamespace, sch)
179
179
180
180
### Running a Mutation
181
181
182
- To run a mutation, use the ` RunDQL ` function.
182
+ To run a mutation, use the ` RunDQL ` function. Note that the namespace is set via the ` WithNamespace `
183
+ option, if not set, the global namespace is used.
183
184
184
185
``` go
185
186
mutationDQL := ` {
@@ -189,10 +190,17 @@ mutationDQL := `{
189
190
_:alice <age> "29" .
190
191
}
191
192
}`
192
- resp , err := client.RunDQL (context.TODO (), dgo. RootNamespace , mutationDQL)
193
+ resp , err := client.RunDQL (context.TODO (), mutationDQL)
193
194
// Handle error
194
195
// Print map of blank UIDs
195
196
fmt.Printf (" %+v \n " , resp.BlankUids )
197
+
198
+ // Perform this mutation in a already created namespace named "finance-graph"
199
+ resp, err = client.RunDQL (context.TODO (), mutationDQL, dgo.WithNamespace (" finance-graph" ))
200
+ // Handle error
201
+ // Print map of blank UIDs
202
+ fmt.Printf (" %+v \n " , resp.BlankUids )
203
+
196
204
```
197
205
198
206
### Running a Query
@@ -207,7 +215,7 @@ queryDQL := `{
207
215
age
208
216
}
209
217
}`
210
- resp , err := client.RunDQL (context.TODO (), dgo. RootNamespace , queryDQL)
218
+ resp , err := client.RunDQL (context.TODO (), queryDQL)
211
219
// Handle error
212
220
fmt.Printf (" %s \n " , resp.QueryResult )
213
221
```
@@ -225,7 +233,7 @@ queryDQL = `query Alice($name: string) {
225
233
}
226
234
}`
227
235
vars := map [string ]string {" $name" : " Alice" }
228
- resp , err := client.RunDQLWithVars (context.TODO (), dgo. RootNamespace , queryDQL, vars)
236
+ resp , err := client.RunDQLWithVars (context.TODO (), queryDQL, vars)
229
237
// Handle error
230
238
fmt.Printf (" %s \n " , resp.QueryResult )
231
239
```
@@ -242,7 +250,7 @@ queryDQL := `{
242
250
age
243
251
}
244
252
}`
245
- resp , err := client.RunDQL (context.TODO (), dgo. RootNamespace , queryDQL, dgo.WithBestEffort ())
253
+ resp , err := client.RunDQL (context.TODO (), queryDQL, dgo.WithBestEffort ())
246
254
// Handle error
247
255
fmt.Printf (" %s \n " , resp.QueryResult )
248
256
```
@@ -259,7 +267,24 @@ queryDQL := `{
259
267
age
260
268
}
261
269
}`
262
- resp , err := client.RunDQL (context.TODO (), dgo.RootNamespace , queryDQL, dgo.WithReadOnly ())
270
+ resp , err := client.RunDQL (context.TODO (), queryDQL, dgo.WithReadOnly ())
271
+ // Handle error
272
+ fmt.Printf (" %s \n " , resp.QueryResult )
273
+ ```
274
+
275
+ ### Running a Query in a Namespace
276
+
277
+ To run a query in a namespace, use the same ` RunDQL ` function with ` TxnOption ` .
278
+
279
+ ``` go
280
+ queryDQL := ` {
281
+ alice(func: eq(name, "Alice")) {
282
+ name
283
+ email
284
+ age
285
+ }
286
+ }`
287
+ resp , err := client.RunDQL (context.TODO (), queryDQL, dgo.WithNamespace (" finance-graph" ), dgo.WithReadOnly ())
263
288
// Handle error
264
289
fmt.Printf (" %s \n " , resp.QueryResult )
265
290
```
0 commit comments