Compare commits

..

4 Commits

Author SHA1 Message Date
Szilárd Dóró
fa045eed15 Merge pull request #1808 from nhost/changeset-release/main
chore: update versions
2023-04-03 16:35:43 +02:00
github-actions[bot]
61c0583b6d chore: update versions 2023-04-03 13:56:32 +00:00
Szilárd Dóró
1343a6f252 Merge pull request #1806 from nhost/fix/failed-subscriptions
fix: don't open unnecessary connections
2023-04-03 15:55:27 +02:00
Szilárd Dóró
0d73e87a83 fix: don't open unnecessary connections 2023-04-03 15:14:28 +02:00
8 changed files with 51 additions and 6 deletions

View File

@@ -1,5 +1,11 @@
# @nhost/dashboard
## 0.14.3
### Patch Changes
- @nhost/react-apollo@5.0.16
## 0.14.2
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "@nhost/dashboard",
"version": "0.14.2",
"version": "0.14.3",
"private": true,
"scripts": {
"preinstall": "npx only-allow pnpm",

View File

@@ -1,5 +1,12 @@
# @nhost/apollo
## 5.2.1
### Patch Changes
- 0d73e87a: fix(ws): don't open unnecessary connections
- 0d73e87a: fix(ws): increase retry attempts and implement exponential backoff
## 5.2.0
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "@nhost/apollo",
"version": "5.2.0",
"version": "5.2.1",
"description": "Nhost Apollo Client library",
"license": "MIT",
"keywords": [

View File

@@ -72,7 +72,22 @@ export const createApolloClient = ({
? createRestartableClient({
url: uri.startsWith('https') ? uri.replace(/^https/, 'wss') : uri.replace(/^http/, 'ws'),
shouldRetry: () => true,
retryAttempts: 10,
retryAttempts: 100,
retryWait: async (retries) => {
// start with 1 second delay
const baseDelay = 1000
// max 3 seconds of jitter
const maxJitter = 3000
// exponential backoff with jitter
return new Promise((resolve) =>
setTimeout(
resolve,
baseDelay * Math.pow(2, retries) + Math.floor(Math.random() * maxJitter)
)
)
},
connectionParams: () => ({
headers: {
...headers,
@@ -141,7 +156,7 @@ export const createApolloClient = ({
// update token
token = state.context.accessToken.value
if (!isBrowser) {
if (!isBrowser || !wsClient?.isOpen()) {
return
}

View File

@@ -3,6 +3,7 @@ import { Client, ClientOptions, createClient } from 'graphql-ws'
export interface RestartableClient extends Client {
restart(): void
isOpen(): boolean
}
export function createRestartableClient(options: ClientOptions): RestartableClient {
@@ -10,6 +11,8 @@ export function createRestartableClient(options: ClientOptions): RestartableClie
let restart = () => {
restartRequested = true
}
let connectionOpen = false
let socket: WebSocket
let timedOut: NodeJS.Timeout
@@ -46,6 +49,7 @@ export function createRestartableClient(options: ClientOptions): RestartableClie
opened: (originalSocket) => {
socket = originalSocket as WebSocket
options.on?.opened?.(socket)
connectionOpen = true
restart = () => {
if (socket.readyState === WebSocket.OPEN) {
@@ -63,12 +67,17 @@ export function createRestartableClient(options: ClientOptions): RestartableClie
restartRequested = false
restart()
}
},
closed: (event) => {
options?.on?.closed?.(event)
connectionOpen = false
}
}
})
return {
...client,
restart: () => restart()
restart: () => restart(),
isOpen: () => connectionOpen
}
}

View File

@@ -1,5 +1,13 @@
# @nhost/react-apollo
## 5.0.16
### Patch Changes
- Updated dependencies [0d73e87a]
- Updated dependencies [0d73e87a]
- @nhost/apollo@5.2.1
## 5.0.15
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "@nhost/react-apollo",
"version": "5.0.15",
"version": "5.0.16",
"description": "Nhost React Apollo client",
"license": "MIT",
"keywords": [