@@ -53,6 +53,7 @@ func TestREADME(t *testing.T) {
53
53
// Run a query and check we got the result back
54
54
queryDQL := `{
55
55
alice(func: eq(name, "Alice")) {
56
+ uid
56
57
name
57
58
email
58
59
age
@@ -61,6 +62,7 @@ func TestREADME(t *testing.T) {
61
62
resp , err = client .RunDQL (ctx , dgo .RootNamespace , queryDQL )
62
63
require .NoError (t , err )
63
64
var m map [string ][]struct {
65
+ Uid string `json:"uid"`
64
66
Name string `json:"name"`
65
67
Email string `json:"email"`
66
68
Age int `json:"age"`
@@ -73,6 +75,7 @@ func TestREADME(t *testing.T) {
73
75
// Run the query with variables
74
76
queryDQLWithVar := `query Alice($name: string) {
75
77
alice(func: eq(name, $name)) {
78
+ uid
76
79
name
77
80
email
78
81
age
@@ -102,6 +105,17 @@ func TestREADME(t *testing.T) {
102
105
require .
Equal (
t ,
m [
"alice" ][
0 ].
Email ,
"[email protected] " )
103
106
require .Equal (t , m ["alice" ][0 ].Age , 29 )
104
107
108
+ // JSON Response, check that we can execute the JSON received from query response
109
+ // DQL with JSON Data format should be valid as per https://docs.hypermode.com/dgraph/dql/json
110
+ jsonBytes , marshallErr := json .Marshal (m ["alice" ][0 ])
111
+ require .NoError (t , marshallErr )
112
+ mutationDQL = fmt .Sprintf (`{
113
+ "set": [%s]
114
+ }` , jsonBytes )
115
+ resp , err = client .RunDQL (ctx , dgo .RootNamespace , mutationDQL , dgo .WithReadOnly ())
116
+ require .NoError (t , err )
117
+ require .Empty (t , resp .BlankUids )
118
+
105
119
// RDF Response, note that we can execute the RDFs received from query response
106
120
resp , err = client .RunDQL (ctx , dgo .RootNamespace , queryDQL , dgo .WithResponseFormat (apiv2 .RespFormat_RDF ))
107
121
require .NoError (t , err )
0 commit comments