Will we be able to subscribe to a query?

following up on question: Will 1.2 subscription logic be able to be customized based on a query.

I would like to be able to subscribe to a custom DQL query, something like:

type Query @withSubscription {
    channels(ownerId: String!): CountResponse @withSubscription @custom(dql: """
        	query q($ownerId: string) {
            		channels(func: type(Channel)) @filter(eq(Channel.ownerId, $ownerId)) {
                			count(uid)
                		}
            	}
        	""")
}

My subscriptions for a Type work as expected but if I try to subscribe for the query type above I get {message: "input:2: Cannot query field "channels" on type "Subscription".↵"} .

Of course for the example above I can figure out something different, but I have more complicated custom queries that I’d like to subscribe to.

Is it possible (what I’m missing?) / Will it be possible (when?)

Thanks!

This sounds like a valid use case that allows you to subscribe to the underlying DQL queries. We could look into supporting it in the release for early next year.

From v20.11 (which should be out soon on Slash GraphQL), we’ll have support for aggregation queries which you could also subscribe to. Would that work for you?

2 Likes

We have added support to subscribe to custom DQL query about a month ago. Sorry, I forgot to mention it here. It’s currently added in master branch and will be avaliable in 21.03 release.
PR:feat(GraphQL):This PR adds subscriptions to custom DQL. by JatinDevDG · Pull Request #7385 · dgraph-io/dgraph · GitHub