Skip to content

Commit

Permalink
Merge pull request #240 from josipsumeckispread/feature/http-client-i…
Browse files Browse the repository at this point in the history
…nterface

HTTP Client as an interface
  • Loading branch information
Yamashou authored Nov 7, 2024
2 parents ae430e8 + ac8584f commit e320159
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion clientgenv2/template.gotpl
Original file line number Diff line number Diff line change
Expand Up @@ -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...)}
}

Expand Down
9 changes: 7 additions & 2 deletions clientv2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down
Binary file added gqlgenc
Binary file not shown.

0 comments on commit e320159

Please sign in to comment.