ChilliCream / graphql-platform

Welcome to the home of the Hot Chocolate GraphQL server for .NET, the Strawberry Shake GraphQL client for .NET and Banana Cake Pop the awesome Monaco based GraphQL IDE.
https://chillicream.com
MIT License
4.96k stars 722 forks source link

Subscription with filtering should not send empty messages #7049

Open Droni opened 1 month ago

Droni commented 1 month ago

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.

michaelstaib commented 3 weeks ago

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

Droni commented 3 weeks ago

@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 commented 3 weeks ago

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

Droni commented 3 weeks ago

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

Droni commented 3 weeks ago

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);