Skip to content

Commit 40b08be

Browse files
Update README
1 parent 56c3f0d commit 40b08be

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

README.md

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ err := client.SetSchema(context.TODO(), dgo.RootNamespace, sch)
179179

180180
### Running a Mutation
181181

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.
183184

184185
```go
185186
mutationDQL := `{
@@ -189,10 +190,17 @@ mutationDQL := `{
189190
_:alice <age> "29" .
190191
}
191192
}`
192-
resp, err := client.RunDQL(context.TODO(), dgo.RootNamespace, mutationDQL)
193+
resp, err := client.RunDQL(context.TODO(), mutationDQL)
193194
// Handle error
194195
// Print map of blank UIDs
195196
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+
196204
```
197205

198206
### Running a Query
@@ -207,7 +215,7 @@ queryDQL := `{
207215
age
208216
}
209217
}`
210-
resp, err := client.RunDQL(context.TODO(), dgo.RootNamespace, queryDQL)
218+
resp, err := client.RunDQL(context.TODO(), queryDQL)
211219
// Handle error
212220
fmt.Printf("%s\n", resp.QueryResult)
213221
```
@@ -225,7 +233,7 @@ queryDQL = `query Alice($name: string) {
225233
}
226234
}`
227235
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)
229237
// Handle error
230238
fmt.Printf("%s\n", resp.QueryResult)
231239
```
@@ -242,7 +250,7 @@ queryDQL := `{
242250
age
243251
}
244252
}`
245-
resp, err := client.RunDQL(context.TODO(), dgo.RootNamespace, queryDQL, dgo.WithBestEffort())
253+
resp, err := client.RunDQL(context.TODO(), queryDQL, dgo.WithBestEffort())
246254
// Handle error
247255
fmt.Printf("%s\n", resp.QueryResult)
248256
```
@@ -259,7 +267,24 @@ queryDQL := `{
259267
age
260268
}
261269
}`
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())
263288
// Handle error
264289
fmt.Printf("%s\n", resp.QueryResult)
265290
```

0 commit comments

Comments
 (0)