Skip to content
This repository has been archived by the owner on Oct 6, 2023. It is now read-only.

Commit

Permalink
feat(ui): improve graphql client config
Browse files Browse the repository at this point in the history
  • Loading branch information
Akryum committed Jan 21, 2022
1 parent c36b777 commit 12fc87d
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion packages/peeky-client/src/apollo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,29 @@ class WebSocketLink extends ApolloLink {

constructor (options: ClientOptions) {
super()
this.client = createClient(options)
let activeSocket: any
let timedOut: any
this.client = createClient({
lazy: true,
retryAttempts: Infinity,
keepAlive: 10_000, // 10s
...options,
on: {
opened: (socket) => (activeSocket = socket),
ping: (received) => {
if (!received /* sent */) {
timedOut = setTimeout(() => {
if (activeSocket.readyState === WebSocket.OPEN) { activeSocket.close(4408, 'Request Timeout') }
}, 5_000) // wait 5 seconds for the pong and then close the connection
}
},
pong: (received) => {
if (received) {
clearTimeout(timedOut) // pong is received, clear connection close timeout
}
},
},
})
}

public request (operation: Operation): Observable<FetchResult> {
Expand Down

0 comments on commit 12fc87d

Please sign in to comment.