Skip to content

Commit bce3cdb

Browse files
committed
Add broken example from JSON Data Format docs to tests
Note this currently fails intentionally, to demonstrate mismatch with documentation
1 parent 1ce3fe0 commit bce3cdb

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

client_test.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"time"
1414

1515
"github.com/dgraph-io/dgo/v250"
16-
api "github.com/dgraph-io/dgo/v250/protos/api"
16+
"github.com/dgraph-io/dgo/v250/protos/api"
1717

1818
"github.com/stretchr/testify/require"
1919
)
@@ -185,6 +185,23 @@ func TestREADME(t *testing.T) {
185185
require.Equal(t, m["alice"][0].Email, "[email protected]")
186186
require.Equal(t, m["alice"][0].Age, 29)
187187

188+
// JSON Response, check that we can execute the JSON received from query response
189+
// DQL with JSON Data format should be valid as per https://docs.hypermode.com/dgraph/dql/json
190+
jsonBytes, marshallErr := json.Marshal(m["alice"])
191+
require.NoError(t, marshallErr)
192+
mutationDQL = fmt.Sprintf(`{
193+
"set": %s
194+
}`, jsonBytes)
195+
resp, err = client.RunDQL(ctx, mutationDQL)
196+
require.NoError(t, err)
197+
require.NotEmpty(t, resp.Uids["alice"])
198+
resp, err = client.RunDQL(ctx, queryDQL, dgo.WithReadOnly())
199+
require.NoError(t, err)
200+
require.NoError(t, json.Unmarshal(resp.Json, &m))
201+
require.Equal(t, m["alice"][0].Name, "Alice")
202+
require.Equal(t, m["alice"][0].Email, "[email protected]")
203+
require.Equal(t, m["alice"][0].Age, 29)
204+
188205
// Running an upsert
189206
upsertQuery := `upsert {
190207
query {

0 commit comments

Comments
 (0)