chore: added gql decorator and complexity plugin

This commit is contained in:
ankitsridhar16
2022-12-07 23:09:15 +05:30
parent 06ef17048a
commit ee002df110
2 changed files with 61 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
import { createParamDecorator, ExecutionContext } from '@nestjs/common';
import { User } from '../user/user.model';
import { GqlExecutionContext } from '@nestjs/graphql';
export const GqlUser = createParamDecorator<any, any, User>(
(_data: any, context: ExecutionContext) => {
const { user } = GqlExecutionContext.create(context).getContext<{
user: User;
}>();
if (!user)
throw new Error(
'@GqlUser decorator use with null user. Make sure the resolve has the @GqlAuthGuard present.',
);
return user;
},
);