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?