diff --git a/clientgenv2/template.gotpl b/clientgenv2/template.gotpl index bb917f8..a38a6e6 100644 --- a/clientgenv2/template.gotpl +++ b/clientgenv2/template.gotpl @@ -26,7 +26,7 @@ Client *clientv2.Client } - func NewClient(cli *http.Client, baseURL string, options *clientv2.Options, interceptors ...clientv2.RequestInterceptor) {{- if .ClientInterfaceName }} {{ .ClientInterfaceName }} {{- else }} *Client {{- end }} { + func NewClient(cli clientv2.HttpClient, baseURL string, options *clientv2.Options, interceptors ...clientv2.RequestInterceptor) {{- if .ClientInterfaceName }} {{ .ClientInterfaceName }} {{- else }} *Client {{- end }} { return &Client{Client: clientv2.NewClient(cli, baseURL, options, interceptors...)} } diff --git a/clientv2/client.go b/clientv2/client.go index 74425d2..26e8ead 100644 --- a/clientv2/client.go +++ b/clientv2/client.go @@ -20,6 +20,11 @@ import ( "github.com/vektah/gqlparser/v2/gqlerror" ) +type HttpClient interface { + Do(req *http.Request) (*http.Response, error) + Post(url, contentType string, body io.Reader) (*http.Response, error) +} + type GQLRequestInfo struct { Request *Request } @@ -55,7 +60,7 @@ func ChainInterceptor(interceptors ...RequestInterceptor) RequestInterceptor { // Client is the http client wrapper type Client struct { - Client *http.Client + Client HttpClient BaseURL string RequestInterceptor RequestInterceptor CustomDo RequestInterceptorFunc @@ -70,7 +75,7 @@ type Request struct { } // NewClient creates a new http client wrapper -func NewClient(client *http.Client, baseURL string, options *Options, interceptors ...RequestInterceptor) *Client { +func NewClient(client HttpClient, baseURL string, options *Options, interceptors ...RequestInterceptor) *Client { c := &Client{ Client: client, BaseURL: baseURL, diff --git a/gqlgenc b/gqlgenc new file mode 100755 index 0000000..ae9f2e0 Binary files /dev/null and b/gqlgenc differ