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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

josipsumeckispread
Copy link

@josipsumeckispread josipsumeckispread commented Oct 30, 2024

Having HTTP Client as an interface allows us to use more complex http client implementations. The one I am personally interested at is github.com/sethgrid/pester which allows us to use resilient requests to remote GraphQL server by implementing a retry strategy on underlying HTTP requests.
The rest of the repository requires no change. All the existing generated code will be compatible with the proposed change.

Example:

package ein

import (
	"context"
	"net/http"
	"time"

	"github.com/sethgrid/pester"

        "github.com/Yamashou/gqlgenc/clientv2"
)

func NewEinHttpClientWithRetry(roundTripper http.RoundTripper) clientv2.HttpClient {
	client := pester.New()
	client.Transport = roundTripper
	client.Timeout = 120 * time.Second
	client.Concurrency = 1
	client.MaxRetries = 5
	client.Backoff = pester.ExponentialJitterBackoff
	client.RetryOnHTTP429 = true
	return client
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant