Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

beforeSubscribe doesnt change incoming query #6866

Closed
maxiqsoft opened this issue Aug 19, 2020 · 5 comments · Fixed by #6868
Closed

beforeSubscribe doesnt change incoming query #6866

maxiqsoft opened this issue Aug 19, 2020 · 5 comments · Fixed by #6868
Labels
type:bug Impaired feature or lacking behavior that is likely assumed

Comments

@maxiqsoft
Copy link

maxiqsoft commented Aug 19, 2020

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

@mtrezza
Copy link
Member

mtrezza commented Aug 19, 2020

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?

@maxiqsoft
Copy link
Author

Ive already tried both ways. Removing the return query doesnt change anything. Im doing it now with ACL instead of subscription queries.

@dblythy
Copy link
Member

dblythy commented Aug 19, 2020

@mtrezza I was able to replicate, I'll provide a PR and better test cases for mutating the request query

@mtrezza
Copy link
Member

mtrezza commented Aug 19, 2020

@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?

@dblythy
Copy link
Member

dblythy commented Aug 19, 2020

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.

@mtrezza mtrezza added type:bug Impaired feature or lacking behavior that is likely assumed and removed troubleshooting labels Aug 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Impaired feature or lacking behavior that is likely assumed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants