/
dgql_test.go
43 lines (39 loc) · 933 Bytes
/
dgql_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package dgql_test
import (
"context"
"testing"
"github.com/Sczlog/dgql"
"github.com/stretchr/testify/assert"
)
func TestQuery(t *testing.T) {
client, err := dgql.NewClient("http://localhost:8080/graphql")
pass := assert.Equal(t, nil, err, "Error creating client")
if !pass {
return
}
resp, _, err := client.Query(context.Background(), "product", map[string]interface{}{
"id": 1,
}, nil)
pass = assert.Equal(t, nil, err, "Error querying")
if !pass {
return
}
println(resp.Raw)
}
func TestMutation(t *testing.T) {
client, err := dgql.NewClient("http://localhost:8080/graphql")
pass := assert.Equal(t, nil, err, "Error creating client")
if !pass {
return
}
resp, _, err := client.Mutation(context.Background(), "create", map[string]interface{}{
"name": "test",
"info": "test",
"price": 100,
}, nil)
pass = assert.Equal(t, nil, err, "Error mutating")
if !pass {
return
}
println(resp.Raw)
}