Skip to content

Commit 6949037

Browse files
committed
Add extensions and export error
1 parent 05b17f3 commit 6949037

File tree

1 file changed

+30
-27
lines changed

1 file changed

+30
-27
lines changed

graphql.go

+30-27
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,34 @@
11
// Package graphql provides a low level GraphQL client.
22
//
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")
55
//
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+
// `)
1616
//
17-
// // set any variables
18-
// req.Var("key", "value")
17+
// // set any variables
18+
// req.Var("key", "value")
1919
//
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+
// }
2525
//
26-
// Specify client
26+
// # Specify client
2727
//
2828
// 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))
3132
package graphql
3233

3334
import (
@@ -212,7 +213,8 @@ func (c *Client) runWithPostFields(ctx context.Context, req *Request, resp inter
212213

213214
// WithHTTPClient specifies the underlying http.Client to use when
214215
// making requests.
215-
// NewClient(endpoint, WithHTTPClient(specificHTTPClient))
216+
//
217+
// NewClient(endpoint, WithHTTPClient(specificHTTPClient))
216218
func WithHTTPClient(httpclient *http.Client) ClientOption {
217219
return func(client *Client) {
218220
client.httpClient = httpclient
@@ -231,17 +233,18 @@ func UseMultipartForm() ClientOption {
231233
// modify the behaviour of the Client.
232234
type ClientOption func(*Client)
233235

234-
type graphErr struct {
235-
Message string
236+
type GraphErr struct {
237+
Message string `json:"message"`
238+
Extensions map[string]interface{} `json:"extensions"`
236239
}
237240

238-
func (e graphErr) Error() string {
241+
func (e GraphErr) Error() string {
239242
return "graphql: " + e.Message
240243
}
241244

242245
type graphResponse struct {
243246
Data interface{}
244-
Errors []graphErr
247+
Errors []GraphErr
245248
}
246249

247250
// Request is a GraphQL request.

0 commit comments

Comments
 (0)