Skip to content

Commit

Permalink
feat(server): Add is retry flag to connect events (#507)
Browse files Browse the repository at this point in the history
  • Loading branch information
telemenar authored Feb 12, 2024
1 parent e45d6b1 commit 9ad853f
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export type Event =
| EventError;

/** @category Client */
export type EventConnectingListener = () => void;
export type EventConnectingListener = (isRetry: boolean) => void;

/**
* The first argument is actually the `WebSocket`, but to avoid
Expand All @@ -124,6 +124,7 @@ export type EventOpenedListener = (socket: unknown) => void;
export type EventConnectedListener = (
socket: unknown,
payload: ConnectionAckMessage['payload'],
wasRetry: boolean,
) => void;

/**
Expand Down Expand Up @@ -637,7 +638,7 @@ export function createClient<
retries++;
}

emitter.emit('connecting');
emitter.emit('connecting', retrying);
const socket = new WebSocketImpl(
typeof url === 'function' ? await url() : url,
GRAPHQL_TRANSPORT_WS_PROTOCOL,
Expand Down Expand Up @@ -760,7 +761,7 @@ export function createClient<
);
clearTimeout(connectionAckTimeout);
acknowledged = true;
emitter.emit('connected', socket, message.payload); // connected = socket opened + acknowledged
emitter.emit('connected', socket, message.payload, retrying); // connected = socket opened + acknowledged
retrying = false; // future lazy connects are not retries
retries = 0; // reset the retries on connect
connected([
Expand Down

0 comments on commit 9ad853f

Please sign in to comment.