Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add retry info to connect events #507

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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