-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_test.go
74 lines (59 loc) · 1.11 KB
/
example_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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package gqlclient_test
import (
"context"
"log"
"strings"
"git.sr.ht/~emersion/gqlclient"
)
func ExampleClient_Execute() {
var ctx context.Context
var c *gqlclient.Client
op := gqlclient.NewOperation(`query {
me {
name
}
}`)
var data struct {
Me struct {
Name string
}
}
if err := c.Execute(ctx, op, &data); err != nil {
log.Fatal(err)
}
log.Print(data)
}
func ExampleClient_Execute_vars() {
var ctx context.Context
var c *gqlclient.Client
op := gqlclient.NewOperation(`query ($name: String!) {
user(username: $name) {
age
}
}`)
op.Var("name", "emersion")
var data struct {
User struct {
Age int
}
}
if err := c.Execute(ctx, op, &data); err != nil {
log.Fatal(err)
}
log.Print(data)
}
func ExampleClient_Execute_upload() {
var ctx context.Context
var c *gqlclient.Client
op := gqlclient.NewOperation(`mutation ($file: Upload!) {
send(file: $file)
}`)
op.Var("file", gqlclient.Upload{
Filename: "gopher.txt",
MIMEType: "text/plain",
Body: strings.NewReader("Hello, 世界"),
})
if err := c.Execute(ctx, op, nil); err != nil {
log.Fatal(err)
}
}