import { createParamDecorator , ExecutionContext } from '@nestjs/common' ; import { GqlContextType , GqlExecutionContext } from '@nestjs/graphql' ; import type { Request } from 'express' ; export const ReqUser = createParamDecorator ( ( _data , context ) => { let request ; if ( context . getType < GqlContextType > ( ) === 'graphql' ) { const ctx = GqlExecutionContext . create ( context ) . getContext ( ) ; request = < Request > ctx . req ; } else { request = context . switchToHttp ( ) . getRequest < Request > ( ) ; } return request . user ; } ) ;