Skip to content

Commit

Permalink
feat: add possibility to configure client target (#3349)
Browse files Browse the repository at this point in the history
  • Loading branch information
taraktikos authored Oct 31, 2024
1 parent b336eae commit 0b86cf7
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ import (
type (
// Client used for testing GraphQL servers. Not for production use.
Client struct {
h http.Handler
dc *mapstructure.DecoderConfig
opts []Option
h http.Handler
dc *mapstructure.DecoderConfig
opts []Option
target string
}

// Option implements a visitor that mutates an outgoing GraphQL request
Expand Down Expand Up @@ -48,8 +49,9 @@ type (
// Options can be set that should be applied to all requests made with this client
func New(h http.Handler, opts ...Option) *Client {
p := &Client{
h: h,
opts: opts,
h: h,
opts: opts,
target: "/",
}

return p
Expand Down Expand Up @@ -111,7 +113,7 @@ var boundaryRegex = regexp.MustCompile(`multipart/form-data; ?boundary=.*`)
func (p *Client) newRequest(query string, options ...Option) (*http.Request, error) {
bd := &Request{
Query: query,
HTTP: httptest.NewRequest(http.MethodPost, "/", http.NoBody),
HTTP: httptest.NewRequest(http.MethodPost, p.target, http.NoBody),
}
bd.HTTP.Header.Set("Content-Type", "application/json")

Expand Down Expand Up @@ -146,6 +148,11 @@ func (p *Client) SetCustomDecodeConfig(dc *mapstructure.DecoderConfig) {
p.dc = dc
}

// SetCustomTarget sets a custom target path for the client
func (p *Client) SetCustomTarget(target string) {
p.target = target
}

func unpack(data, into any, customDc *mapstructure.DecoderConfig) error {
dc := &mapstructure.DecoderConfig{
TagName: "json",
Expand Down

0 comments on commit 0b86cf7

Please sign in to comment.