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

feat: Retry and Timeout configuration for upstream requests #322

Merged
merged 33 commits into from
Dec 13, 2024

Conversation

ardatan
Copy link
Member

@ardatan ardatan commented Dec 12, 2024

New Retry and Timeout plugins;

  • Retry plugin: Retry a request if it fails

It respects the Retry-After HTTP header, See more about this HTTP

export const gatewayConfig = defineConfig({
    upstreamRetry: {
        // The maximum number of retries to attempt.
        maxRetries: 3, // required
        // The maximum delay between retries in milliseconds.
        maxDelay: 1000, // default
        /**
         * A function that determines whether a response should be retried.
         * If the upstream returns `Retry-After` header, the response will be retried.
         */
        shouldRetry: response => response.status >= 500 || response.status === 429 // default
    }
    // or you can configure it by subgraph name
    upstreamRetry({ subgraphName }) {
        if (subgraphName === 'my-rate-limited-subgraph') {
            return {
                maxRetries: 3,
            }
        }
    }
})
  • Timeout plugin: Timeout a request if it takes too long
export const gatewayConfig = defineConfig({
    // The maximum time in milliseconds to wait for a response from the upstream.
    upstreamTimeout: 1000, // required
    // or you can configure it by subgraph name
    upstreamTimeout({ subgraphName }) {
        if (subgraphName === 'my-slow-subgraph') {
            return 1000;
        }
    }
})

@ardatan ardatan requested a review from EmrysMyrddin December 12, 2024 12:29
@theguild-bot
Copy link
Collaborator

theguild-bot commented Dec 12, 2024

🚀 Snapshot Release (alpha)

The latest changes of this PR are available as alpha on npm (based on the declared changesets):

Package Version Info
@graphql-hive/gateway-abort-signal-any 0.0.1-alpha-467e0da460eac9a047b4b5c9f45862a245729820 npm ↗︎ unpkg ↗︎
@graphql-tools/batch-delegate 9.0.24-alpha-467e0da460eac9a047b4b5c9f45862a245729820 npm ↗︎ unpkg ↗︎
@graphql-tools/delegate 10.2.8-alpha-467e0da460eac9a047b4b5c9f45862a245729820 npm ↗︎ unpkg ↗︎
@graphql-tools/executor-http 1.2.1-alpha-467e0da460eac9a047b4b5c9f45862a245729820 npm ↗︎ unpkg ↗︎
@graphql-tools/federation 3.0.2-alpha-467e0da460eac9a047b4b5c9f45862a245729820 npm ↗︎ unpkg ↗︎
@graphql-mesh/fusion-runtime 0.10.21-alpha-467e0da460eac9a047b4b5c9f45862a245729820 npm ↗︎ unpkg ↗︎
@graphql-hive/gateway 1.7.0-alpha-467e0da460eac9a047b4b5c9f45862a245729820 npm ↗︎ unpkg ↗︎
@graphql-mesh/hmac-upstream-signature 1.2.17-alpha-467e0da460eac9a047b4b5c9f45862a245729820 npm ↗︎ unpkg ↗︎
@graphql-mesh/plugin-opentelemetry 1.3.28-alpha-467e0da460eac9a047b4b5c9f45862a245729820 npm ↗︎ unpkg ↗︎
@graphql-mesh/plugin-prometheus 1.3.16-alpha-467e0da460eac9a047b4b5c9f45862a245729820 npm ↗︎ unpkg ↗︎
@graphql-hive/gateway-runtime 1.4.0-alpha-467e0da460eac9a047b4b5c9f45862a245729820 npm ↗︎ unpkg ↗︎
@graphql-tools/stitch 9.4.10-alpha-467e0da460eac9a047b4b5c9f45862a245729820 npm ↗︎ unpkg ↗︎
@graphql-tools/stitching-directives 3.1.23-alpha-467e0da460eac9a047b4b5c9f45862a245729820 npm ↗︎ unpkg ↗︎
@graphql-mesh/transport-common 0.7.23-alpha-467e0da460eac9a047b4b5c9f45862a245729820 npm ↗︎ unpkg ↗︎
@graphql-mesh/transport-http 0.6.27-alpha-467e0da460eac9a047b4b5c9f45862a245729820 npm ↗︎ unpkg ↗︎
@graphql-mesh/transport-http-callback 0.5.14-alpha-467e0da460eac9a047b4b5c9f45862a245729820 npm ↗︎ unpkg ↗︎
@graphql-mesh/transport-ws 0.4.12-alpha-467e0da460eac9a047b4b5c9f45862a245729820 npm ↗︎ unpkg ↗︎
@graphql-tools/wrap 10.0.26-alpha-467e0da460eac9a047b4b5c9f45862a245729820 npm ↗︎ unpkg ↗︎

@theguild-bot
Copy link
Collaborator

theguild-bot commented Dec 12, 2024

🚀 Snapshot Release (Binary for macOS-ARM64)

The latest changes of this PR are available for download (based on the declared changesets).

Download

@theguild-bot
Copy link
Collaborator

theguild-bot commented Dec 12, 2024

🚀 Snapshot Release (Binary for Linux-X64)

The latest changes of this PR are available for download (based on the declared changesets).

Download

@theguild-bot
Copy link
Collaborator

theguild-bot commented Dec 12, 2024

🚀 Snapshot Release (Node Docker Image)

The latest changes of this PR are available as image on GitHub Container Registry (based on the declared changesets):

ghcr.io/graphql-hive/gateway:1.7.0-alpha-467e0da460eac9a047b4b5c9f45862a245729820

@theguild-bot
Copy link
Collaborator

theguild-bot commented Dec 12, 2024

🚀 Snapshot Release (Bun Docker Image)

The latest changes of this PR are available as image on GitHub Container Registry (based on the declared changesets):

ghcr.io/graphql-hive/gateway:1.7.0-alpha-467e0da460eac9a047b4b5c9f45862a245729820-bun

@theguild-bot
Copy link
Collaborator

theguild-bot commented Dec 12, 2024

🚀 Snapshot Release (Binary for macOS-X64)

The latest changes of this PR are available for download (based on the declared changesets).

Download

@theguild-bot
Copy link
Collaborator

theguild-bot commented Dec 12, 2024

🚀 Snapshot Release (Binary for Windows-X64)

The latest changes of this PR are available for download (based on the declared changesets).

Download

@ardatan ardatan marked this pull request as draft December 12, 2024 15:09
@ardatan ardatan marked this pull request as ready for review December 12, 2024 16:46
@ardatan ardatan requested a review from EmrysMyrddin December 12, 2024 16:48
@ardatan ardatan requested a review from EmrysMyrddin December 13, 2024 10:04
@ardatan ardatan requested a review from EmrysMyrddin December 13, 2024 13:48
@ardatan ardatan merged commit 23b8987 into main Dec 13, 2024
27 checks passed
@ardatan ardatan deleted the retry-timeout branch December 13, 2024 13:52
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.

3 participants