I am trying to use graphql subscriptions using the following libraries:
graphql-subscription on the server-side
subscription-transport-ws on the client-side
and when not using the filtering mechanism every thing goes right. But when I add the withFilter
function into it, encounter the issue that no variable or context object receives to the filtering function.
For example I want to filter data according to the group. The client requests the server with the following query:
And at the server-side the implemented method is like this:
this.resolvers.Subscription[subscription.name] = {
subscribe: withFilter((...params) => {console.log('subscription params: ', ...params); return this.pubsub.asyncIterator(subscription.name.toUpperCase());}, (...params) => {
console.log('filtering params: ', ...params)
return true // payload[subscription.name]._group === variables._group;
}),
};
which is creating some subscriptions dynamically (and its dynamicity does not relate to this issue). Now the two logs that I have made above will be as following:
subscription params:
null {} null null
filtering params:
{ message_onMessage: { text: 'test', _offline_id: '1587981902663', _status: 3, time: 1587981902713, _id: 1587981902716, _rev: 1587981902716 } } {} null null
So that in the callback that is passed to the withFilter
function which is used to filter the data, I do not have the variables object and the context object to fetch the requester _group
parameter.
And the installed version of the libraries is as bellow:
// server
"graphql": "^14.6.0",
"graphql-subscriptions": "^1.1.0",
// client
"graphql": "^15.0.0",
"graphql-tag": "^2.10.3",
"subscriptions-transport-ws": "^0.9.16"