Compare commits
4 Commits
@nhost/rea
...
@nhost/rea
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fa045eed15 | ||
|
|
61c0583b6d | ||
|
|
1343a6f252 | ||
|
|
0d73e87a83 |
@@ -1,5 +1,11 @@
|
|||||||
# @nhost/dashboard
|
# @nhost/dashboard
|
||||||
|
|
||||||
|
## 0.14.3
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- @nhost/react-apollo@5.0.16
|
||||||
|
|
||||||
## 0.14.2
|
## 0.14.2
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@nhost/dashboard",
|
"name": "@nhost/dashboard",
|
||||||
"version": "0.14.2",
|
"version": "0.14.3",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"preinstall": "npx only-allow pnpm",
|
"preinstall": "npx only-allow pnpm",
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
# @nhost/apollo
|
# @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
|
## 5.2.0
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@nhost/apollo",
|
"name": "@nhost/apollo",
|
||||||
"version": "5.2.0",
|
"version": "5.2.1",
|
||||||
"description": "Nhost Apollo Client library",
|
"description": "Nhost Apollo Client library",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
|
|||||||
@@ -72,7 +72,22 @@ export const createApolloClient = ({
|
|||||||
? createRestartableClient({
|
? createRestartableClient({
|
||||||
url: uri.startsWith('https') ? uri.replace(/^https/, 'wss') : uri.replace(/^http/, 'ws'),
|
url: uri.startsWith('https') ? uri.replace(/^https/, 'wss') : uri.replace(/^http/, 'ws'),
|
||||||
shouldRetry: () => true,
|
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: () => ({
|
connectionParams: () => ({
|
||||||
headers: {
|
headers: {
|
||||||
...headers,
|
...headers,
|
||||||
@@ -141,7 +156,7 @@ export const createApolloClient = ({
|
|||||||
// update token
|
// update token
|
||||||
token = state.context.accessToken.value
|
token = state.context.accessToken.value
|
||||||
|
|
||||||
if (!isBrowser) {
|
if (!isBrowser || !wsClient?.isOpen()) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { Client, ClientOptions, createClient } from 'graphql-ws'
|
|||||||
|
|
||||||
export interface RestartableClient extends Client {
|
export interface RestartableClient extends Client {
|
||||||
restart(): void
|
restart(): void
|
||||||
|
isOpen(): boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createRestartableClient(options: ClientOptions): RestartableClient {
|
export function createRestartableClient(options: ClientOptions): RestartableClient {
|
||||||
@@ -10,6 +11,8 @@ export function createRestartableClient(options: ClientOptions): RestartableClie
|
|||||||
let restart = () => {
|
let restart = () => {
|
||||||
restartRequested = true
|
restartRequested = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let connectionOpen = false
|
||||||
let socket: WebSocket
|
let socket: WebSocket
|
||||||
let timedOut: NodeJS.Timeout
|
let timedOut: NodeJS.Timeout
|
||||||
|
|
||||||
@@ -46,6 +49,7 @@ export function createRestartableClient(options: ClientOptions): RestartableClie
|
|||||||
opened: (originalSocket) => {
|
opened: (originalSocket) => {
|
||||||
socket = originalSocket as WebSocket
|
socket = originalSocket as WebSocket
|
||||||
options.on?.opened?.(socket)
|
options.on?.opened?.(socket)
|
||||||
|
connectionOpen = true
|
||||||
|
|
||||||
restart = () => {
|
restart = () => {
|
||||||
if (socket.readyState === WebSocket.OPEN) {
|
if (socket.readyState === WebSocket.OPEN) {
|
||||||
@@ -63,12 +67,17 @@ export function createRestartableClient(options: ClientOptions): RestartableClie
|
|||||||
restartRequested = false
|
restartRequested = false
|
||||||
restart()
|
restart()
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
closed: (event) => {
|
||||||
|
options?.on?.closed?.(event)
|
||||||
|
connectionOpen = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...client,
|
...client,
|
||||||
restart: () => restart()
|
restart: () => restart(),
|
||||||
|
isOpen: () => connectionOpen
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
# @nhost/react-apollo
|
# @nhost/react-apollo
|
||||||
|
|
||||||
|
## 5.0.16
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [0d73e87a]
|
||||||
|
- Updated dependencies [0d73e87a]
|
||||||
|
- @nhost/apollo@5.2.1
|
||||||
|
|
||||||
## 5.0.15
|
## 5.0.15
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@nhost/react-apollo",
|
"name": "@nhost/react-apollo",
|
||||||
"version": "5.0.15",
|
"version": "5.0.16",
|
||||||
"description": "Nhost React Apollo client",
|
"description": "Nhost React Apollo client",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
|
|||||||
Reference in New Issue
Block a user