Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

129
Views
Custom Decorators with Graphql decorator

I was making my own decorator to log input parameters and output result for each method. By the way, if I use the decorator with @Mutation decorator. It occurs error according to the order of use.

My decorator looks like:

export const Log = (): MethodDecorator => (target: Object, propertyKey: string, descriptor: PropertyDescriptor) => {
  const originalMethod = descriptor.value

  descriptor.value = async function (...args) {
    console.log(args); // Write input log
    const result = originalMethod.apply(this, args);
    console.log(result); // Write output log
    return result;
  }

  return descriptor;
}

Usage:

@Mutation(() => Question, { name: 'question' })
@Log()
async question(@Args('input') input: QuestionInput): Promise<Question> {
  return await this.questionService.createOne({ ...input });
}

It doesn't occur error if I use decorators @Mutation() -> @Log() order. But @Log() -> @Mutation() order doesn't work.

What should I check first? Is there any other idea for logging the input and output of a method?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!