graphql-compose / graphql-compose/graphql-compose-mongoose

withMiddlewares does not fire within a custom resolver

Open
#322 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
706
Forks
98
PR merge metrics
No merged PRs in 30d

Description

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]),
});
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.