这是indexloc提供的服务,不要输入任何密码
Skip to content

feat: add retry option to graphql client #168

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

Merged
merged 1 commit into from
Apr 26, 2025

Conversation

japananh
Copy link

@japananh japananh commented Apr 21, 2025

Add WithRetry option for configurable request retries

Features

  • New ClientOption type for configuring client behavior.
  • WithRetry(retries int) option to set maximum retry attempts for failed GraphQL requests.
  • No retry on HTTP URL error.
  • Added comprehensive tests:
    • Retry behavior on temporary errors
    • Max retries exceeded scenarios
    • No retry on permanent errors

Usage

// Create client with 3 retry attempts
client := graphql.NewClient(
    "/graphql",
    httpClient,
    graphql.WithRetry(3),
)

var q struct {
    User struct {
        Name string
    }
}

// Query will automatically retry up to 3 times on temporary failures
err := client.Query(context.Background(), &q, nil)

@japananh japananh marked this pull request as draft April 21, 2025 10:49
@japananh japananh force-pushed the feat/client-with-retry-option branch 2 times, most recently from bf3d957 to 9132873 Compare April 22, 2025 09:33
@japananh japananh marked this pull request as ready for review April 22, 2025 09:34
Copy link

@hgiasac hgiasac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @japananh,

Thank you for contributing. I added some comments.
Actually, you can use any HTTP client that supports retry and satisfies the Doer interface. However, it's also cool if the GraphQL client supports retry natively.

@japananh japananh force-pushed the feat/client-with-retry-option branch 6 times, most recently from 694997c to 6d9aa72 Compare April 23, 2025 09:00
@japananh japananh requested a review from hgiasac April 23, 2025 09:13
@japananh japananh force-pushed the feat/client-with-retry-option branch from 6d9aa72 to 5eaf96e Compare April 23, 2025 09:17
@hgiasac hgiasac merged commit f20a101 into hasura:master Apr 26, 2025
1 check failed
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.

2 participants