Skip to content

Commit aa4fab1

Browse files
committed
Refactor to remove unnecessary steps
1 parent 8a07e0a commit aa4fab1

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

‎packages/javascript-api/src/lib/services/graphql/graphql.service.ts‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,11 @@ export class GraphqlService {
218218
this.messageSubscribers.set(messageId, subscriber);
219219

220220
return () => {
221-
this.sendMessage(messageId, MessageType.GQL_STOP, null);
222-
this.cleanUpSubscription(messageId);
223-
224-
if (!this.erroredSubscriptionsMessageIds.size) {
225-
this.haveAnySubscriptionsErrored$.next(false);
221+
if (this.messageSubscribers.has(messageId)) {
222+
this.sendMessage(messageId, MessageType.GQL_STOP, null);
226223
}
224+
225+
this.cleanUpSubscription(messageId);
227226
};
228227
});
229228
}
@@ -290,6 +289,10 @@ export class GraphqlService {
290289
this.subscriptions = this.subscriptions.filter(
291290
(subscription) => subscription.messageId !== messageId,
292291
);
292+
293+
if (!this.erroredSubscriptionsMessageIds.size) {
294+
this.haveAnySubscriptionsErrored$.next(false);
295+
}
293296
}
294297

295298
private async openSocket(): Promise<void> {
@@ -431,8 +434,9 @@ export class GraphqlService {
431434
break;
432435

433436
case MessageType.GQL_COMPLETE: {
434-
this.messageSubscribers.get(message.id)?.complete();
437+
const subscriber = this.messageSubscribers.get(message.id);
435438
this.cleanUpSubscription(message.id);
439+
subscriber?.complete();
436440
break;
437441
}
438442

@@ -461,11 +465,11 @@ export class GraphqlService {
461465
}
462466

463467
if (message.payload?.data) {
464-
subscriber.error(message.payload.data);
465468
this.cleanUpSubscription(message.id);
469+
subscriber.error(message.payload.data);
466470
} else if (message.payload?.errors?.length) {
467-
subscriber.error(message.payload.errors);
468471
this.cleanUpSubscription(message.id);
472+
subscriber.error(message.payload.errors);
469473
}
470474
}
471475
}

0 commit comments

Comments
 (0)