From 7db726614ddaf9ebc14d43a53d6e3c92266fc57e Mon Sep 17 00:00:00 2001 From: Andy Wagner Date: Wed, 20 May 2020 13:26:57 -0400 Subject: [PATCH] Use Pester as default client This is a quick hack to replace http.Client with pester.Client, in lieu of a better solution like a transport raised in #33. --- graphql.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/graphql.go b/graphql.go index 05c29b7..c1b2868 100644 --- a/graphql.go +++ b/graphql.go @@ -25,8 +25,8 @@ // // Specify client // -// To specify your own http.Client, use the WithHTTPClient option: -// httpclient := &http.Client{} +// To specify your own pester.Client, use the WithHTTPClient option: +// httpclient := &pester.Client{} // client := graphql.NewClient("https://machinebox.io/graphql", graphql.WithHTTPClient(httpclient)) package graphql @@ -40,12 +40,13 @@ import ( "net/http" "github.com/pkg/errors" + "github.com/sethgrid/pester" ) // Client is a client for interacting with a GraphQL API. type Client struct { endpoint string - httpClient *http.Client + httpClient *pester.Client useMultipartForm bool // closeReq will close the request body immediately allowing for reuse of client @@ -67,7 +68,7 @@ func NewClient(endpoint string, opts ...ClientOption) *Client { optionFunc(c) } if c.httpClient == nil { - c.httpClient = http.DefaultClient + c.httpClient = pester.New() } return c } @@ -221,10 +222,10 @@ func (c *Client) runWithPostFields(ctx context.Context, req *Request, resp inter return nil } -// WithHTTPClient specifies the underlying http.Client to use when +// WithHTTPClient specifies the underlying pester.Client to use when // making requests. // NewClient(endpoint, WithHTTPClient(specificHTTPClient)) -func WithHTTPClient(httpclient *http.Client) ClientOption { +func WithHTTPClient(httpclient *pester.Client) ClientOption { return func(client *Client) { client.httpClient = httpclient }