chore: completed subscription to create a SharedRequest

This commit is contained in:
Balu Babu
2023-10-25 21:49:04 +05:30
parent b74c1abf6f
commit b7462ab014
3 changed files with 23 additions and 2 deletions

View File

@@ -1,4 +1,11 @@
import { Args, ID, Resolver, Query, Mutation } from '@nestjs/graphql';
import {
Args,
ID,
Resolver,
Query,
Mutation,
Subscription,
} from '@nestjs/graphql';
import { SharedRequest } from './shared-requests.model';
import { GqlThrottlerGuard } from 'src/guards/gql-throttler.guard';
import { UseGuards } from '@nestjs/common';
@@ -10,6 +17,7 @@ import { GqlAuthGuard } from 'src/guards/gql-auth.guard';
import { throwErr } from 'src/utils';
import { GqlUser } from 'src/decorators/gql-user.decorator';
import { AuthUser } from 'src/types/AuthUser';
import { SkipThrottle } from '@nestjs/throttler';
@UseGuards(GqlThrottlerGuard)
@Resolver(() => SharedRequest)
@@ -67,4 +75,15 @@ export class SharedRequestResolver {
if (E.isLeft(result)) throwErr(result.left);
return result.right;
}
/* Subscriptions */
@Subscription(() => SharedRequest, {
description: 'Listen for shortcode creation',
resolve: (value) => value,
})
@SkipThrottle()
@UseGuards(GqlAuthGuard)
mySharedRequestCreated(@GqlUser() user: AuthUser) {
return this.pubsub.asyncIterator(`shared_request/${user.uid}/created`);
}
}