Parse-server: beforeSubscribe doesnt change incoming query

Created on 19 Aug 2020  路  5Comments  路  Source: parse-community/parse-server

Issue Description

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...' );
       });
});

Environment

Server

  • Parse Server version: 4.3.0
  • Operating system: CentOS 8
  • Local or remote host (AWS, Azure, Google Cloud, Heroku, Digital Ocean, etc): local

Database

  • System (MongoDB or Postgres): MongoDB
  • Database version: 4.0.19
  • Local or remote host (MongoDB Atlas, mLab, AWS, Azure, Google Cloud, etc): local

Client

  • SDK (iOS, Android, JavaScript, PHP, Unity, etc): JavaScript
  • SDK version: 2.15

Logs

bug

Most helpful comment

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.

All 5 comments

Thanks 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.

Was this page helpful?
0 / 5 - 0 ratings