mardok
mardok

Reputation: 2415

How to pass argument to Class-based Middleware

I have custom class-based middleware like:

@Service()
export class MyMiddleware implements MiddlewareInterface<Context> {
  constructor(private readonly service: Service) {}

  async use({ info, context }: ResolverData<Context>, next: NextFn) {
    // this.service.doSomeDbLogicHere()
    return next();
  }
}


@UseMiddleware(MyMiddleware)
@Mutation(() => User)
public async createuser() {}

I wonder how I can pass custom static values to my middleware, but still have other objects injected via DI.

Upvotes: 0

Views: 187

Answers (1)

Michał Lytek
Michał Lytek

Reputation: 12127

You need to create a function that accepts a static value and return a middleware class.

Upvotes: 1

Related Questions