File tree Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -5,11 +5,12 @@ Low-level GraphQL client for Go.
5
5
* Simple, familiar API
6
6
* Respects context.Context cancallation
7
7
* Build and execute any kind of GraphQL request
8
+ * Use variables and upload files
8
9
9
10
``` go
10
11
ctx := context.Background ()
11
12
ctx := graphql.NewContext (ctx, " https://machinebox.io/graphql" )
12
- r := graphql.NewRequest (`
13
+ req := graphql.NewRequest (`
13
14
query ($key: String!) {
14
15
items (id:$key) {
15
16
field1
@@ -18,9 +19,9 @@ r := graphql.NewRequest(`
18
19
}
19
20
}
20
21
` )
21
- r .Var (" key" , " value" )
22
+ req .Var (" key" , " value" )
22
23
var res ResponseStruct
23
- if err := r .Run (ctx, &resp); err != nil {
24
+ if err := req .Run (ctx, &resp); err != nil {
24
25
log.Fatalln (err)
25
26
}
26
27
```
Original file line number Diff line number Diff line change @@ -127,7 +127,11 @@ func NewRequest(q string) *Request {
127
127
return req
128
128
}
129
129
130
- // Run executes the query and unmarshals the response into response.
130
+ // Run executes the query and unmarshals the response from the data field
131
+ // into the response object.
132
+ // Pass in a nil response object to skip response parsing.
133
+ // If the request fails or the server returns an error, the first error
134
+ // will be returned. Use IsGraphQLErr to determine which it was.
131
135
func (req * Request ) Run (ctx context.Context , response interface {}) error {
132
136
client , err := fromContext (ctx )
133
137
if err != nil {
@@ -152,6 +156,13 @@ func (req *Request) File(filename string, r io.Reader) {
152
156
})
153
157
}
154
158
159
+ // IsGraphQLErr gets whether the error is a remote GraphQL
160
+ // server error or not.
161
+ func IsGraphQLErr (err error ) bool {
162
+ _ , ok := err .(graphErr )
163
+ return ok
164
+ }
165
+
155
166
// file represents a file to upload.
156
167
type file struct {
157
168
Name string
You can’t perform that action at this time.
0 commit comments