Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP Client as an interface #240

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Loading