Hi, Im trying to change the incoming query subscription with Parse.Cloud.beforeSubscribe but im still getting every column at the client. Ive tried changing the subscription query with query.equalTo too but it doesnt have any effect.
I did it the same way as here: beforeFind
The intention is that some parameter needed for the right subscription shouldnt be displayed in the source code.
Thats my Cloud code:
Parse.Cloud.beforeSubscribe( 'Chat', ( request ) => {
if ( !request.user ) {
throw "Please login before you attempt to connect.";
}
var query = request.query;
query.select( 'message', 'username' );
return query;
});
Thats my Client code:
var chat = new Parse.Query( 'Chat' );
chat.subscribe().then(subscription=>{
subscription.on( 'open', function(){
console.log( 'Subscription to Chat opened...' );
});
});
Server
4.3.0CentOS 8localDatabase
MongoDB4.0.19localClient
JavaScript2.15Thanks for reporting.
Looking at your code, I see that you return query; at the end. This does not seem to be necessary according to the beforeSubscribe example. Instead it seems that by changing the request.query object, the change is already applied. Can you try removing the return query; line?
Ive already tried both ways. Removing the return query doesnt change anything. Im doing it now with ACL instead of subscription queries.
@mtrezza I was able to replicate, I'll provide a PR and better test cases for mutating the request query
@dblythy Thanks for looking into this so quickly. Can you give more details about the underlying issue, as in whether there is a workaround for it?
Yes, here in my maybeRunSubscribeTrigger I converted the request.query (which is previously JSON) to a Parse Query for the trigger, but after the trigger runs, I never converted it back, meaning that the LiveQuery tries to access .where, which is undefined. Mistake on my behalf, in my usage I was just throwing out of beforeSubscribe, and I should've created a test case for mutating the query. Sorry @maxiqsoft! Will have a PR very shortly with a few more tests as well.
Most helpful comment
Yes, here in my
maybeRunSubscribeTriggerI converted the request.query (which is previously JSON) to a Parse Query for the trigger, but after the trigger runs, I never converted it back, meaning that the LiveQuery tries to access .where, which is undefined. Mistake on my behalf, in my usage I was just throwing out ofbeforeSubscribe, and I should've created a test case for mutating the query. Sorry @maxiqsoft! Will have a PR very shortly with a few more tests as well.