parse-community / parse-community/parse-server

Allow to run queries through LiveQueryClient

Open
#9,086 12 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bounty:$500 bounty:sponsored type:feature
Dominant language
JavaScript
Stars
21.4k
Forks
4.8k
Avg merge
7h 45m
Merged PRs (30d)
11

Description

Current Limitation

When developing applications using Parse, you want to sync the App with the Server when the App is re-opened after being killed, shut down or restored from the background.

You need a Query to obtain the most current data and subscribe to a LiveQuery to receive real-time updates while the application is in use.

In complex apps with multiple collections, a large number of Query + LiveQuery combinations are necessary every time the app is restored from the background, requiring several REST calls and a WebSocket connection.

Feature / Enhancement Description

It should be possible to run Queries through a LiveQueryClient, and/or to request query results along with LiveQuery subscription to enable syncing collections and subscribing to LiveQueries with a single WebSocket connection.

We believe that this improvement makes a difference. It's easy to develop and maintain, with minimal changes to the Parse Server and client SDKs.

This is not a breaking change, it is fully retrocompatible, and existing apps can be improved easily.

EDIT Apr 30:
It would be beneficial to have the option to use WebSocket for all requests, including Queries, Saves, Cloud Functions, and all CRUD operations.

Example Use Case

Imagine a complex TODO mobile app with six collections: boards, tasks, goals, categories, tags, and users.

Every time the user opens the App after from background, especially after being offline, you need to run six Parse Queries and subscribe to them.

Each of the six queries is an HTTP/REST API call, while all LiveQueries travel on a single Websocket connection.

Current Approach:

const tasks = getTasksFromLocalDb();

const query = new Parse.Query('Tasks');
query.greaterThan("updatedAt", getLastTimeOpenedApp());

// This is the standard (and only) way so far to retrieve objects. 
const results = await query.find(); // For each Query, the SDK triggers the REST API Call we want to avoid.
results.forEach(task => tasks[task.id] = task);

const subscription = await query.subscribe();
subscription.on('create', task => tasks[task.id] = task);

Possible Alternative 1:
Get query results leveraging the subscription

subscription.on('result', task => tasks[task.id] = task);
subscription.find(); // or subscription.first(); or getResults() or runQuery(), or any other naming that makes sense.

Possible Alternative 2:
Allow running any query from a LiveQueryClient. This potentially enables developers to run queries through WebSocket, detached from a subscription.

const client = new LiveQueryClient({ ... });
const querySubscription = client.querySubscribe(query);
querySubscription.on('result', task => tasks[task.id] = task);

Ideally, both alternatives 1 and 2 should be developed, with one serving as a shortcut for the other.

3rd Party References

Firebase onSnapshot event.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the LiveQueryClient, Parse.Query, and subscription flow described in the examples, then determine how query results would travel over the existing WebSocket connection. Done means the project has a decided API for running queries through LiveQueryClient or a subscription, with the requested synchronization behavior and backward compatibility preserved.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
api, backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Needs clarification
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.