Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"time"

"github.com/dgraph-io/dgo/v250"
api "github.com/dgraph-io/dgo/v250/protos/api"
"github.com/dgraph-io/dgo/v250/protos/api"

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

// JSON Response, check that we can execute the JSON received from query response
// DQL with JSON Data format should be valid as per https://docs.hypermode.com/dgraph/dql/json
jsonBytes, marshallErr := json.Marshal(m["alice"])
require.NoError(t, marshallErr)
mutationDQL = fmt.Sprintf(`{
"set": %s
}`, jsonBytes)
resp, err = client.RunDQL(ctx, mutationDQL)
require.NoError(t, err)
require.NotEmpty(t, resp.Uids["alice"])
resp, err = client.RunDQL(ctx, queryDQL, dgo.WithReadOnly())
require.NoError(t, err)
require.NoError(t, json.Unmarshal(resp.Json, &m))
require.Equal(t, m["alice"][0].Name, "Alice")
require.Equal(t, m["alice"][0].Email, "[email protected]")
require.Equal(t, m["alice"][0].Age, 29)

// Running an upsert
upsertQuery := `upsert {
query {
Expand Down