Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscription with filtering should not send empty messages #7049

Open
Droni opened this issue Apr 12, 2024 · 5 comments
Open

Subscription with filtering should not send empty messages #7049

Droni opened this issue Apr 12, 2024 · 5 comments
Labels
🌶️ hot chocolate ❓ question This issue is a question about feature of Hot Chocolate.

Comments

@Droni
Copy link

Droni commented Apr 12, 2024

Product

Hot Chocolate

Is your feature request related to a problem?

When we use a filtered subscription and the response does not match the filter criteria, still an empty message will be sent, but it shouldn't.

The solution you'd like

I expect that if the message is empty, then it shouldn't be sent.

@Droni Droni added the 🎉 enhancement New feature or request label Apr 12, 2024
@glen-84 glen-84 changed the title Sibscription with filtering should not send empy messages Subscription with filtering should not send empty messages Apr 22, 2024
@michaelstaib
Copy link
Member

Its up to you to optimize this ... in the stream you can choose to not send a payload.

@michaelstaib michaelstaib added ❓ question This issue is a question about feature of Hot Chocolate. 🌶️ hot chocolate and removed 🎉 enhancement New feature or request labels Apr 22, 2024
@Droni
Copy link
Author

Droni commented Apr 24, 2024

@michaelstaib Thanks for your reply. The proposed option does not suit us. Ideally, we can make many separate subscriptions, but since the subscription is carried out through the browser, and it has a limit on the number of open subscriptions, this option is not suitable for us. We chose the single subscription path with multiple possible output messages and filtering options.
Please look at the example:

    [Subscribe]
    [UseFiltering]
    public CommonEvent<ReadModelEventChangeData>? ReadModelChanged([EventMessage] CommonEvent<ReadModelEventChangeData> ev, IResolverContext context)
        => new[] { ev }.AsQueryable().Filter(context).FirstOrDefault();

```

@michaelstaib
Copy link
Member

Sure, but still implement the stream and you get full control. The subscription has two parts.

@Droni
Copy link
Author

Droni commented Apr 24, 2024

@michaelstaib Interesting offer. Is it possible to look at an example somewhere? I found only such an implementation in the documentation.

@Droni
Copy link
Author

Droni commented Apr 24, 2024

If you mean the moment of sending, from the example below. Then at this stage we cannot get a filter for a specific subscriber. And perhaps for one subscriber the filter will say that this message is not empty, but for another it will be empty.

        var topicName = nameof(Subscriptions.ReadModelChanged);
        return topicEventSender.SendAsync(topicName, readModelEvent, cancellationToken);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🌶️ hot chocolate ❓ question This issue is a question about feature of Hot Chocolate.
Projects
None yet
Development

No branches or pull requests

2 participants