diff --git a/packages/hoppscotch-backend/src/user-environment/user-environments.module.ts b/packages/hoppscotch-backend/src/user-environment/user-environments.module.ts index d82a1e899..04f391682 100644 --- a/packages/hoppscotch-backend/src/user-environment/user-environments.module.ts +++ b/packages/hoppscotch-backend/src/user-environment/user-environments.module.ts @@ -5,7 +5,6 @@ import { UserModule } from '../user/user.module'; import { UserEnvsUserResolver } from './user.resolver'; import { UserEnvironmentsResolver } from './user-environments.resolver'; import { UserEnvironmentsService } from './user-environments.service'; -import { SubscriptionHandler } from '../subscription-handler'; @Module({ imports: [PrismaModule, PubSubModule, UserModule], @@ -13,7 +12,6 @@ import { SubscriptionHandler } from '../subscription-handler'; UserEnvironmentsResolver, UserEnvironmentsService, UserEnvsUserResolver, - SubscriptionHandler, ], exports: [UserEnvironmentsService], }) diff --git a/packages/hoppscotch-backend/src/user-environment/user-environments.service.spec.ts b/packages/hoppscotch-backend/src/user-environment/user-environments.service.spec.ts index 894872cde..849b589e1 100644 --- a/packages/hoppscotch-backend/src/user-environment/user-environments.service.spec.ts +++ b/packages/hoppscotch-backend/src/user-environment/user-environments.service.spec.ts @@ -9,19 +9,15 @@ import { USER_ENVIRONMENT_INVALID_ENVIRONMENT_NAME, } from '../errors'; import { PubSubService } from '../pubsub/pubsub.service'; -import { SubscriptionHandler } from '../subscription-handler'; -import { SubscriptionType } from '../types/subscription-types'; const mockPrisma = mockDeep(); const mockPubSub = mockDeep(); -const mockSubscriptionHandler = mockDeep(); // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore const userEnvironmentsService = new UserEnvironmentsService( mockPrisma, mockPubSub as any, - mockSubscriptionHandler, ); const userPersonalEnvironments = [ @@ -245,9 +241,8 @@ describe('UserEnvironmentsService', () => { false, ); - return expect(mockSubscriptionHandler.publish).toHaveBeenCalledWith( - `user_environment/${result.userUid}`, - SubscriptionType.Created, + return expect(mockPubSub.publish).toHaveBeenCalledWith( + `user_environment/${result.userUid}/created`, result, ); }); @@ -276,9 +271,8 @@ describe('UserEnvironmentsService', () => { true, ); - return expect(mockSubscriptionHandler.publish).toHaveBeenCalledWith( - `user_environment/${result.userUid}`, - SubscriptionType.Created, + return expect(mockPubSub.publish).toHaveBeenCalledWith( + `user_environment/${result.userUid}/created`, result, ); }); @@ -374,9 +368,8 @@ describe('UserEnvironmentsService', () => { '[{}]', ); - return expect(mockSubscriptionHandler.publish).toHaveBeenCalledWith( - `user_environment/${result.id}`, - SubscriptionType.Updated, + return expect(mockPubSub.publish).toHaveBeenCalledWith( + `user_environment/${result.id}/updated`, result, ); }); @@ -404,9 +397,8 @@ describe('UserEnvironmentsService', () => { '[{}]', ); - return expect(mockSubscriptionHandler.publish).toHaveBeenCalledWith( - `user_environment/${result.id}`, - SubscriptionType.Updated, + return expect(mockPubSub.publish).toHaveBeenCalledWith( + `user_environment/${result.id}/updated`, result, ); }); @@ -470,9 +462,8 @@ describe('UserEnvironmentsService', () => { await userEnvironmentsService.deleteUserEnvironment('abc123', 'env1'); - return expect(mockSubscriptionHandler.publish).toHaveBeenCalledWith( - `user_environment/${result.id}`, - SubscriptionType.Deleted, + return expect(mockPubSub.publish).toHaveBeenCalledWith( + `user_environment/${result.id}/deleted`, result, ); }); @@ -486,9 +477,8 @@ describe('UserEnvironmentsService', () => { await userEnvironmentsService.deleteUserEnvironments('abc123'); - return expect(mockSubscriptionHandler.publish).toHaveBeenCalledWith( - `user_environment/abc123`, - SubscriptionType.DeleteMany, + return expect(mockPubSub.publish).toHaveBeenCalledWith( + `user_environment/${'abc123'}/deleted_many`, 1, ); }); @@ -566,9 +556,8 @@ describe('UserEnvironmentsService', () => { await userEnvironmentsService.clearGlobalEnvironments('abc123', 'env1'); - return expect(mockSubscriptionHandler.publish).toHaveBeenCalledWith( - `user_environment/${result.id}`, - SubscriptionType.Updated, + return expect(mockPubSub.publish).toHaveBeenCalledWith( + `user_environment/${result.id}/updated`, result, ); }); diff --git a/packages/hoppscotch-backend/src/user-environment/user-environments.service.ts b/packages/hoppscotch-backend/src/user-environment/user-environments.service.ts index a08549e0c..872395351 100644 --- a/packages/hoppscotch-backend/src/user-environment/user-environments.service.ts +++ b/packages/hoppscotch-backend/src/user-environment/user-environments.service.ts @@ -13,8 +13,6 @@ import { USER_ENVIRONMENT_UPDATE_FAILED, USER_ENVIRONMENT_INVALID_ENVIRONMENT_NAME, } from '../errors'; -import { SubscriptionHandler } from '../subscription-handler'; -import { SubscriptionType } from '../types/subscription-types'; import { stringToJson } from '../utils'; @Injectable() @@ -22,7 +20,6 @@ export class UserEnvironmentsService { constructor( private readonly prisma: PrismaService, private readonly pubsub: PubSubService, - private readonly subscriptionHandler: SubscriptionHandler, ) {} /** @@ -119,9 +116,8 @@ export class UserEnvironmentsService { isGlobal: createdEnvironment.isGlobal, }; // Publish subscription for environment creation - await this.subscriptionHandler.publish( - `user_environment/${userEnvironment.userUid}`, - SubscriptionType.Created, + await this.pubsub.publish( + `user_environment/${userEnvironment.userUid}/created`, userEnvironment, ); return E.right(userEnvironment); @@ -154,9 +150,8 @@ export class UserEnvironmentsService { isGlobal: updatedEnvironment.isGlobal, }; // Publish subscription for environment update - await this.subscriptionHandler.publish( - `user_environment/${updatedUserEnvironment.id}`, - SubscriptionType.Updated, + await this.pubsub.publish( + `user_environment/${updatedUserEnvironment.id}/updated`, updatedUserEnvironment, ); return E.right(updatedUserEnvironment); @@ -196,9 +191,8 @@ export class UserEnvironmentsService { }; // Publish subscription for environment deletion - await this.subscriptionHandler.publish( - `user_environment/${deletedUserEnvironment.id}`, - SubscriptionType.Deleted, + await this.pubsub.publish( + `user_environment/${deletedUserEnvironment.id}/deleted`, deletedUserEnvironment, ); return E.right(true); @@ -220,9 +214,13 @@ export class UserEnvironmentsService { }, }); - await this.subscriptionHandler.publish( - `user_environment/${uid}`, - SubscriptionType.DeleteMany, + // await this.subscriptionHandler.publish( + // `user_environment/${uid}`, + // SubscriptionType.DeleteMany, + // deletedEnvironments.count, + // ); + await this.pubsub.publish( + `user_environment/${uid}/deleted_many`, deletedEnvironments.count, ); @@ -258,9 +256,8 @@ export class UserEnvironmentsService { }; // Publish subscription for environment update - await this.subscriptionHandler.publish( - `user_environment/${updatedUserEnvironment.id}`, - SubscriptionType.Updated, + await this.pubsub.publish( + `user_environment/${updatedUserEnvironment.id}/updated`, updatedUserEnvironment, ); return E.right(updatedUserEnvironment);