1
1
// Package graphql provides a low level GraphQL client.
2
2
//
3
- // // create a client (safe to share across requests)
4
- // client := graphql.NewClient("https://machinebox.io/graphql")
3
+ // // create a client (safe to share across requests)
4
+ // client := graphql.NewClient("https://machinebox.io/graphql")
5
5
//
6
- // // make a request
7
- // req := graphql.NewRequest(`
8
- // query ($key: String!) {
9
- // items (id:$key) {
10
- // field1
11
- // field2
12
- // field3
13
- // }
14
- // }
15
- // `)
6
+ // // make a request
7
+ // req := graphql.NewRequest(`
8
+ // query ($key: String!) {
9
+ // items (id:$key) {
10
+ // field1
11
+ // field2
12
+ // field3
13
+ // }
14
+ // }
15
+ // `)
16
16
//
17
- // // set any variables
18
- // req.Var("key", "value")
17
+ // // set any variables
18
+ // req.Var("key", "value")
19
19
//
20
- // // run it and capture the response
21
- // var respData ResponseStruct
22
- // if err := client.Run(ctx, req, &respData); err != nil {
23
- // log.Fatal(err)
24
- // }
20
+ // // run it and capture the response
21
+ // var respData ResponseStruct
22
+ // if err := client.Run(ctx, req, &respData); err != nil {
23
+ // log.Fatal(err)
24
+ // }
25
25
//
26
- // Specify client
26
+ // # Specify client
27
27
//
28
28
// To specify your own http.Client, use the WithHTTPClient option:
29
- // httpclient := &http.Client{}
30
- // client := graphql.NewClient("https://machinebox.io/graphql", graphql.WithHTTPClient(httpclient))
29
+ //
30
+ // httpclient := &http.Client{}
31
+ // client := graphql.NewClient("https://machinebox.io/graphql", graphql.WithHTTPClient(httpclient))
31
32
package graphql
32
33
33
34
import (
@@ -212,7 +213,8 @@ func (c *Client) runWithPostFields(ctx context.Context, req *Request, resp inter
212
213
213
214
// WithHTTPClient specifies the underlying http.Client to use when
214
215
// making requests.
215
- // NewClient(endpoint, WithHTTPClient(specificHTTPClient))
216
+ //
217
+ // NewClient(endpoint, WithHTTPClient(specificHTTPClient))
216
218
func WithHTTPClient (httpclient * http.Client ) ClientOption {
217
219
return func (client * Client ) {
218
220
client .httpClient = httpclient
@@ -231,17 +233,18 @@ func UseMultipartForm() ClientOption {
231
233
// modify the behaviour of the Client.
232
234
type ClientOption func (* Client )
233
235
234
- type graphErr struct {
235
- Message string
236
+ type GraphErr struct {
237
+ Message string `json:"message"`
238
+ Extensions map [string ]interface {} `json:"extensions"`
236
239
}
237
240
238
- func (e graphErr ) Error () string {
241
+ func (e GraphErr ) Error () string {
239
242
return "graphql: " + e .Message
240
243
}
241
244
242
245
type graphResponse struct {
243
246
Data interface {}
244
- Errors []graphErr
247
+ Errors []GraphErr
245
248
}
246
249
247
250
// Request is a GraphQL request.
0 commit comments