Skip to content

Commit 2cab632

Browse files
feat(gateway): add support for new Hive CDN mirror and circuit breaker (#1738)
Co-authored-by: Denis Badurina <[email protected]>
1 parent 9280cc0 commit 2cab632

File tree

9 files changed

+540
-200
lines changed

9 files changed

+540
-200
lines changed

.changeset/cold-bags-confess.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
'@graphql-hive/gateway-runtime': minor
3+
---
4+
5+
New Hive CDN mirror and circuit breaker
6+
7+
Hive CDN introduced a new CDN mirror and circuit breaker to mitigate the risk related to Cloudflare
8+
services failures.
9+
10+
You can now provide multiple endpoint in Hive Console related features, and configure the circuit
11+
breaker handling CDN failure and how it switches to the CDN mirror.
12+
13+
### Usage
14+
15+
To enable this feature, please provide the mirror endpoint in `supergraph` and `persistedDocument`
16+
options:
17+
18+
```diff
19+
import { defineConfig } from '@graphql-hive/gateway'
20+
21+
export const gatewayConfig = defineConfig({
22+
supergraph: {
23+
type: 'hive',
24+
- endpoint: 'https://cdn.graphql-hive.com/artifacts/v1/<target-id>/supergraph',
25+
+ endpoint: [
26+
+ 'https://cdn.graphql-hive.com/artifacts/v1/<target-id>/supergraph',
27+
+ 'https://cdn-mirror.graphql-hive.com/artifacts/v1/<target-id>/supergraph'
28+
+ ]
29+
},
30+
31+
persistedDocuments: {
32+
- endpoint: 'https://cdn.graphql-hive.com/<target-id>',
33+
+ endpoint: [
34+
+ 'https://cdn.graphql-hive.com/<target-id>',
35+
+ 'https://cdn-mirror.graphql-hive.com/<target-id>'
36+
+ ]
37+
}
38+
})
39+
```
40+
41+
### Configuration
42+
43+
The circuit breaker has production ready default configuration, but you customize its behavior:
44+
45+
```ts
46+
import { defineConfig, CircuitBreakerConfiguration } from '@graphql-hive/gateway';
47+
48+
const circuitBreaker: CircuitBreakerConfiguration = {
49+
resetTimeout: 30_000; // 30s
50+
errorThresholdPercentage: 50;
51+
volumeThreshold: 5;
52+
}
53+
54+
export const gatewayConfig = defineConfig({
55+
supergraph: {
56+
type: 'hive',
57+
endpoint: [...],
58+
circuitBreaker,
59+
},
60+
61+
persistedDocuments: {
62+
type: 'hive',
63+
endpoint: [...],
64+
circuitBreaker,
65+
},
66+
});
67+
```

e2e/cloudflare-workers/wrangler.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ compatibility_date = "2024-01-01"
77
"@graphql-tools/batch-delegate" = "../../packages/batch-delegate/src/index.ts"
88
"@graphql-tools/delegate" = "../../packages/delegate/src/index.ts"
99
"@graphql-hive/signal" = "../../packages/signal/src/index.ts"
10-
"@graphql-hive/logger" = "../../packages/logger/src/index.ts"
10+
"@graphql-hive/logger" = "../../packages/logger/src/index.ts"

e2e/self-hosting-hive/self-hosting-hive.e2e.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ describe('Self Hosting Hive', () => {
6060
/\[hiveSupergraphFetcher\] GET .* succeeded with status 200/,
6161
);
6262
expect(gwLogs).toMatch(
63-
/\[useHiveConsole\] POST .* succeeded with status 200/,
63+
/\[useHiveConsole\] POST .*\/usage .* succeeded with status 200/,
6464
);
6565
});
6666
});

0 commit comments

Comments
 (0)