Skip to content

Commit

Permalink
Use Pester as default client
Browse files Browse the repository at this point in the history
This is a quick hack to replace http.Client with pester.Client, in lieu
of a better solution like a transport raised in machinebox#33.
  • Loading branch information
Rarian committed May 20, 2020
1 parent 3a92531 commit 7db7266
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 7db7266

Please sign in to comment.