graphql-compose-mongoose
graphql-compose-mongoose copied to clipboard
withMiddlewares does not fire within a custom resolver
Take a look at the code blocks below.
In the first code block, the myMiddleware never executes. The reason I added the withMiddlewares property inside that object is because it's part of the Resolver.d.ts file so I assumed that this is the correct place to add middlewares for a custom resolver and technically this should have worked.
In the second code block the myMiddeware executes correctly.
First code block (middleware does not fire)
const UserTC = composeMongoose(User);
schemaComposer.Query.addFields({
myCustomResolver: {
args: {},
type: UserTC.getType(),
resolve: userGetMe,
withMiddlewares: [myMiddleware]
}
});
Second code block (middleware fires OK)
const UserTC = composeMongoose(User);
schemaComposer.Query.addFields({
myCustomResolver: UserTC.addResolver({
args:{},
name: 'userGetMe',
type: UserTC.getType(),
resolve: userGetMe,
description: 'Returns current logged in user based on Authorization headers.',
})
.getResolver('userGetMe')
.withMiddlewares([myMiddleware]),
});
withMiddlewares is method of Resolver, you can chaining withMiddlewares with your resolver resolve: userGetMe.withMiddlewares([myMiddleware]) if userGetMe is instance of Resolver.
if you use object in addFields = type of ObjectTypeComposerFieldConfigAsObjectDefinition