Skip to content

Commit

Permalink
close graphql subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
CurryYangxx committed Jan 6, 2025
1 parent 1df8fc1 commit 8303eaa
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/insomnia/src/ui/hooks/use-close-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { useCallback, useEffect } from 'react';

import * as models from '../../models';
import { isGrpcRequestId } from '../../models/grpc-request';
import { isEventStreamRequest, isRequestId } from '../../models/request';
import { isEventStreamRequest, isGraphqlSubscriptionRequest, isRequestId } from '../../models/request';
import { isWebSocketRequestId } from '../../models/websocket-request';
import uiEventBus, { UIEventType } from '../eventBus';

export const useCloseConnection = () => {
// close websocket&grpc&SSE connections
const closeConnection = useCallback((ids: 'all' | string[]) => {
const closeConnection = useCallback((_: string, ids: 'all' | string[]) => {
if (ids === 'all') {
window.main.webSocket.closeAll();
window.main.grpc.closeAll();
Expand All @@ -19,11 +19,13 @@ export const useCloseConnection = () => {
ids.forEach(async id => {
if (isGrpcRequestId(id)) {
window.main.grpc.cancel(id);
} else if (isWebSocketRequestId()) {
} else if (isWebSocketRequestId(id)) {
window.main.webSocket.close({ requestId: id });
} else if (isRequestId(id)) {
const request = await models.request.getById(id);
if (request && isEventStreamRequest(request)) {
window.main.curl.close({ requestId: id });
} else if (request && isGraphqlSubscriptionRequest(request)) {
window.main.webSocket.close({ requestId: id });
}
}
Expand Down

0 comments on commit 8303eaa

Please sign in to comment.