【问题标题】:LiveQuery Parse server subscription does not trigger eventsLiveQuery Parse 服务器订阅不触发事件
【发布时间】:2019-10-19 11:33:50
【问题描述】:

我一直在尝试使用订阅在 Parse 服务器上创建实时查询,但似乎某些事件没有被触发。

我记录了订阅接收到的每个事件,并且我知道触发了“打开”。但是,当我更改应该影响查询结果的数据时,我没有收到任何其他事件。我在 Sashido Parse 服务器上为 CanvasVersion 和 Sticky 在后端启用了实时查询类。

这是客户端代码:

const relation = this.canvasVersion.stickies;
const query = relation.query();
query.equalTo("segment", this.id);

this.segmentUpdatedSubscription = await query.subscribe();

this.segmentUpdatedSubscription.on('open', () => {
    console.log('Subscription opened');
})

this.segmentUpdatedSubscription.on('error', (error) => {
    console.log('error', error);
})

this.segmentUpdatedSubscription.on('create', (sticky) => {
    console.log('Created: ' + sticky);
});

继续 'update'、'enter'、'delete'、'leave' 和 'close',其中 this.canvasVersion.stickies 是 canvasVersion 和 Sticky 对象之间的关系。

解析服务器使用以下代码初始化:

static initialize() {
   Parse.initialize(environment.parse.appId, environment.parse.appKey);
   (Parse as any).serverURL = environment.parse.serverURL;
}

有人知道为什么这些事件没有被触发,我该如何解决?提前感谢您的帮助。

【问题讨论】:

  • 您能分享一下您用来初始化 Parse 服务器的选项吗?
  • 这就是我用来初始化 Parse 服务器的选项的意思吗?
  • 我尝试开始订阅 Sticky(一个 Parse 对象)的查询,这似乎有效。会不会是订阅不适用于解析关系?
  • 我不确定。你介意在开源代码库中打开一个问题以便更好地调查它吗?
  • 我认为订阅不适用于解析关系。 github.com/parse-community/parse-server/issues/2946

标签: parse-platform subscription livequery


【解决方案1】:

解析订阅(Parse LiveQuery)不支持关系订阅。

https://github.com/parse-community/parse-server/issues/5610#issuecomment-495277400

使用带有条件的普通方式订阅。

const query = Parse.Object.extend('Sticky').query();
query.equalTo("segment", this.id);

const segmentUpdatedSubscription = await query.subscribe();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多