v0.14.0
Highlights
Subscription enhancements
- The main runner will be a singleton. Get rid of the recursive loop to avoid goroutine leaks
- Enhance the error handling. Add 2 new timeout settings,
WithConnectionInitialisationTimeout
andWithWebsocketConnectionIdleTimeout
, to handle errors when the server is unresponsive. Check out the docs for more details. - Behavior changes: The state of subscription requests is retained until the
Close
method is called. Resubscribing to the subscription will initiate duplicate requests.
Support Retry for Query and Mutation
Introduced retry options for the GraphQL client, allowing customization for retries, backoff intervals, and error handling during GraphQL operations.
client := graphql.NewClient("/graphql", http.DefaultClient,
// number of retries
graphql.WithRetry(3),
// base backoff interval. Optional, default 1 second.
// Prioritize the Retry-After header if it exists in the response.
graphql.WithRetryBaseDelay(time.Second),
// exponential rate. Optional, default 2.0
graphql.WithRetryExponentialRate(2),
// retry on http statuses. Optional, default: 429, 502, 503, 504
graphql.WithRetryHTTPStatus([]int{http.StatusServiceUnavailable}),
// if the http status is 200 but the graphql response is error,
// use this option to check if the error is retryable.
graphql.WithRetryOnGraphQLError(func(errs graphql.Errors) bool {
return len(errs) == 1 && errs[0].Message == "Field 'user' is missing required arguments: login"
}),
)
Get headers from response
Use the BindResponseHeaders
option to bind headers from the response.
headers := http.Header{}
err := client.Query(context.TODO(), &q, map[string]any{}, graphql.BindResponseHeaders(&headers))
if err != nil {
panic(err)
}
fmt.Println(headers.Get("content-type"))
// application/json
What's Changed
- feat: introduce BindResponseHeaders option by @hgiasac in #163
- fix: subscription goroutine leaks by @hgiasac in #162
- misc: Indicate user agent should be descriptive by @toini in #167
- feat: add retry option to graphql client by @japananh in #168
- feat: add more retry options by @hgiasac in #169
New Contributors
Full Changelog: v0.13.1...v0.14.0