GlobalMiddlewares are called once before each @Field #902
-
as I understand GlobalMiddlewares run before each @query, @mutation, @fieldResolver, @subscription, but do it run also before each @field in the ObjectType when we return its fields? example for that : resolver: @ObjectType()
class TestObject {
@Field()
test: string;
@Field()
test2: string;
}
@Resolver((of) => TestObject)
export class TestResolver {
@Query((returns) => TestObject)
async testResolver(): Promise<TestObject> {
console.log('TestResolver...1');
return <TestObject><unknown>{ test1: "test1", test2: "test2" };
}
} middleware: getUserMiddleware: async ({ context: { request } }: any, next: any) => {
console.log("getUserMiddleware....")
return next();
}, schema: await buildSchema({
resolvers: [TestResolver],
globalMiddlewares: [getUserMiddleware],
}); test code: if it's so, is there a way to prevent that ? and thankstypegraphql version: "^1.1.1" |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Yes, global middlewares runs on every graphql resolver - query, mutation, field. There's no API for limiting that, you can only check |
Beta Was this translation helpful? Give feedback.
Yes, global middlewares runs on every graphql resolver - query, mutation, field.
There's no API for limiting that, you can only check
info
and quick exit on fields if you don't want that behavior.