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

Add support for fields in LiveQuery #3671

Closed
rogerhu opened this issue Mar 27, 2017 · 7 comments
Closed

Add support for fields in LiveQuery #3671

rogerhu opened this issue Mar 27, 2017 · 7 comments

Comments

@rogerhu
Copy link
Contributor

rogerhu commented Mar 27, 2017

Issue Description

Parse LiveQuery specifications are supposed to take a fields in the query. Parse server does not handle these fields, nor do the iOS and Android clients.

https://github.com/ParsePlatform/parse-server/wiki/Parse-LiveQuery-Protocol-Specification

{
  "op": "subscribe",
  "requestId": 1,
  "query": {
      "className": "Player",
      "where": {"name": "test"},
      "fields": ["name"] // Optional
  },
  "sessionToken": "" // Optional
}

https://github.com/ParsePlatform/ParseLiveQuery-iOS-OSX/blob/master/Sources/ParseLiveQuery/Internal/QueryEncoder.swift

parse-community/ParseLiveQuery-Android#18

Steps to reproduce

Create a Parse Query with fields:


@ParseClassName("Message")
public class Message extends ParseObject {
    public static final String USER_ID_KEY = "userId";
    public static final String BODY_KEY = "body";

    public String getUserId() {
        return getString(USER_ID_KEY);
    }

    public String getBody() {
        return getString(BODY_KEY);
    }

    public void setUserId(String userId) {
        put(USER_ID_KEY, userId);
    }

    public void setBody(String body) {
        put(BODY_KEY, body);
    }
}
ParseLiveQueryClient<Message> parseLiveQueryClient =
                    ParseLiveQueryClient.Factory.getClient(new URI(ChatApplication.wsURI));

ParseQuery<Message> parseQuery = ParseQuery.getQuery(Message.class);
parseQuery.selectKeys(["userId"]);

            SubscriptionHandling<Message> subscriptionHandling = parseLiveQueryClient.subscribe(parseQuery);
            subscriptionHandling.handleEvents(
   new SubscriptionHandling.HandleEventsCallback<Message>() {
                        @Override
                        public void onEvents(ParseQuery<Message> query,
                                SubscriptionHandling.Event event,
                                Message object)
                        {
          }
}

Expected Results

Expect only fields to come out.

Actual Outcome

All fields are returned.

Environment Setup

  • Server

    • parse-server version (Be specific! Don't say 'latest'.) : 2.3.7
    • Operating System: MacOS
    • Hardware: [FILL THIS OUT]
    • Localhost or remote server? (AWS, Heroku, Azure, Digital Ocean, etc): localhost, Heroku
  • Database

    • MongoDB version: 3.2.1

Logs/Trace

Include all relevant logs. You can turn on additional logging by configuring VERBOSE=1 in your environment.

@TimNZ
Copy link

TimNZ commented Nov 27, 2017

@flovilmart

I just went looking through JS SDK for fields support on live query subscriptions.

Can we just add an additional 'options' or 'fields' arg to 'subscribe' function in LiveQueryClient.js, and upstream subscribe functions that call it?

@flovilmart
Copy link
Contributor

It would require some serverside work, i’ll Be happy to review a Pull Request :) that would be easier than the CLP’s

@TimNZ
Copy link

TimNZ commented Nov 28, 2017

Oh, the server isn't complete either?
I was using the Live Query protocol wiki as a guide and hadn't looked at the server code.

Ok, will add to my future dev list :)

@TimNZ
Copy link

TimNZ commented Nov 28, 2017

As far as I can tell Parse Server is using subscriptionInfo.fields if specified to filter the response object, before pushing it to the client.

Do you know for a fact that the server needs dev for this?

lib/LiveQuery/Client.js

_pushEvent(type: string): Function {
    return function(subscriptionId: number, parseObjectJSON: any): void {
      const response: Message = {
        'op' : type,
        'clientId' : this.id
      };
      if (typeof subscriptionId !== 'undefined') {
        response['requestId'] = subscriptionId;
      }
      if (typeof parseObjectJSON !== 'undefined') {
        let fields;
        if (this.subscriptionInfos.has(subscriptionId)) {
          fields = this.subscriptionInfos.get(subscriptionId).fields;
        }
        response['object'] = this._toJSONWithFields(parseObjectJSON, fields);
      }
      Client.pushResponse(this.parseWebSocket, JSON.stringify(response));
    }
  }

@montymxb
Copy link
Contributor

@TimNZ we could always use more devs ;)

@TimNZ
Copy link

TimNZ commented Nov 28, 2017

Ok, still on my todo list :)

@TimNZ
Copy link

TimNZ commented Dec 1, 2017

Submitted pull.
No changes to server required.

parse-community/Parse-SDK-JS#518

@dplewis dplewis closed this as completed Mar 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants