@@ -53,6 +53,7 @@ func TestREADME(t *testing.T) {
5353 // Run a query and check we got the result back
5454 queryDQL := `{
5555 alice(func: eq(name, "Alice")) {
56+ uid
5657 name
5758 email
5859 age
@@ -61,6 +62,7 @@ func TestREADME(t *testing.T) {
6162 resp , err = client .RunDQL (ctx , dgo .RootNamespace , queryDQL )
6263 require .NoError (t , err )
6364 var m map [string ][]struct {
65+ Uid string `json:"uid"`
6466 Name string `json:"name"`
6567 Email string `json:"email"`
6668 Age int `json:"age"`
@@ -73,6 +75,7 @@ func TestREADME(t *testing.T) {
7375 // Run the query with variables
7476 queryDQLWithVar := `query Alice($name: string) {
7577 alice(func: eq(name, $name)) {
78+ uid
7679 name
7780 email
7881 age
@@ -102,6 +105,17 @@ func TestREADME(t *testing.T) {
102105 require .
Equal (
t ,
m [
"alice" ][
0 ].
Email ,
"[email protected] " )
103106 require .Equal (t , m ["alice" ][0 ].Age , 29 )
104107
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+
105119 // RDF Response, note that we can execute the RDFs received from query response
106120 resp , err = client .RunDQL (ctx , dgo .RootNamespace , queryDQL , dgo .WithResponseFormat (apiv2 .RespFormat_RDF ))
107121 require .NoError (t , err )
0 commit comments