diff --git a/src/lib/requests/RequestManager.ts b/src/lib/requests/RequestManager.ts index f32433c3..5fe47a58 100644 --- a/src/lib/requests/RequestManager.ts +++ b/src/lib/requests/RequestManager.ts @@ -473,8 +473,10 @@ export class RequestManager { AuthManager.setAuthRequired(null); AuthManager.setAuthInitialized(false); AuthManager.removeTokens(); - this.graphQLClient.client.resetStore(); - this.graphQLClient.terminateSubscriptions(); + + this.graphQLClient.reset(); + this.restClient.reset(); + this.cache.clear(); this.imageQueue.clear(); } diff --git a/src/lib/requests/client/BaseClient.ts b/src/lib/requests/client/BaseClient.ts index e6d6201d..3ccb78e1 100644 --- a/src/lib/requests/client/BaseClient.ts +++ b/src/lib/requests/client/BaseClient.ts @@ -32,6 +32,11 @@ export abstract class BaseClient { protected requestQueue: QueuedRequest[] = []; + public reset(): void { + BaseClient.activeTokenRefreshPromise = null; + this.clearQueue(new Error('Client reset')); + } + public static setTokenRefreshCompleteCallback(callback: (() => void) | null): void { BaseClient.onTokenRefreshComplete = callback; } diff --git a/src/lib/requests/client/GraphQLClient.ts b/src/lib/requests/client/GraphQLClient.ts index daaa0f03..8abd8dc1 100644 --- a/src/lib/requests/client/GraphQLClient.ts +++ b/src/lib/requests/client/GraphQLClient.ts @@ -211,8 +211,32 @@ export class GraphQLClient extends BaseClient< return `${super.getBaseUrl()}/api/graphql`; } - public terminateSubscriptions(): void { + override reset(): void { + super.reset(); + + this.client.clearStore(); + this.client.stop(); + + this.resetWsClient(false); + this.createClient(); + } + + private resetWsClient(recreateClient: boolean): void { + this.wsClient.dispose(); this.wsClient.terminate(); + + if (!recreateClient) { + return; + } + + this.createWSClient(false); + this.client.setLink(this.createLink()); + + this.restartAllSubscriptions(); + } + + private restartAllSubscriptions(): void { + this.activeConnectionSubscriptions.forEach((callback) => callback()); } protected override shouldQueueRequest(operationName: string | undefined): boolean { @@ -346,18 +370,12 @@ export class GraphQLClient extends BaseClient< return; } - this.wsClient.dispose(); - this.wsClient.terminate(); - - this.createWSClient(false); - this.client.setLink(this.createLink()); - - this.activeConnectionSubscriptions.forEach((callback) => callback()); + this.resetWsClient(true); }, checkHeartbeatInterval); } - protected createClient() { - this.createWSClient(); + protected createClient(createWsClientLazily?: boolean) { + this.createWSClient(createWsClientLazily); this.client = new ApolloClient({ cache: new InMemoryCache({ // for whatever reason there is some weird TypeError complaining that