Subscriptions aren't adaptable enough.
I'm submitting a...
[ ] Regression
[X] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behaviour
It is not possible to use this in the subscription resolve function. This makes it incredibly hard to use services to retrieve information from given information.
https://objects.black-out.xyz/a0f6d2b https://objects.black-out.xyz/200c4ce Some screenshots of the current behaviour ^
The code I had when using type-graphql https://objects.black-out.xyz/3172643
Expected behavior
The ability to use this or services in the subscription resolve function. type-graphql didn't force an async iterator to be returned so it was very easy to use add the equivalent of a resolve function in the actual function.
Minimal reproduction of the problem with instructions
- Create a resolver.
- Inject a service into the resolver.
- Create a subscription and attempt to use the service in the
resolve function.
It could look something like https://objects.black-out.xyz/a4cef78
What is the motivation / use case for changing the behavior?
The current behaviour isn't adaptable enough to build bigger graphql apps compared to things like type-graphql
I did spend quite some time with a member of the discord and neither of us could think of any workarounds.
There might be a nice way to do it with DI but I'm not aware.
Environment
Nest version: 6.2.4
Nest GraphQL version: 6.4.2
@Yomanz ! Maybe use function instead of arrow function ?
@Yomanz ! Maybe use function instead of arrow function ?
I have sadly already tried that :(
Let's try this :
class Message {
@Subscription(returns => String, {
resolve: async (message: any) => {
...
const ret = Message.prototype.messageService.fetchMessage(...);
return Message.resolve(ret[0]);
}
})
public async message(...) {
...
}
https://objects.black-out.xyz/deb891f https://i-am.bigno.se/b33b49f.png
Sadly, this doesn't work
I think it's normal that you cannot use class properties / methods in a decorator configuration. You may find a way to get the message in you Subscription decorated method params to apply your fetchMessage process then emit the result to the pubsub...
The message it receives contains information used to get further information. This is really the last part of my application and I don't know what to do at this point.
Let me check if there is anything that we can do to fix your issue.
Thanks very much!
hey - im experiencing the same issue right now, is there any eta for when this will be fixed
Let me check if there is anything that we can do to fix your issue.
Hey @kamilmysliwiec, any luck?
up
Update @nestjs/graphql to 6.5.0 version. Once package is installed, you can use something like this:
@Resolver(of => Model)
class Message {
@Subscription(returns => String, {
resolve(this: Message, message: any) => {
// this will point at an instance of `Message`
// hence, you can use all injected dependencies here
}
})
async onMessage(...) {}
}
Thanks
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.