optimistic UI 是否只适用于watch Query?
Does the optimistic UI only work with watch Query?
乐观 UI 是否只适用于 watchQuery 而不适用于订阅?我们通过 websocket 广泛使用订阅,无法使乐观 UI 工作,尽管它似乎与 watchQuery 一起工作。
所以我的问题很简单,我只需要确认乐观 ui 应该与订阅一起使用?
watchQuery 用于订阅缓存的更新(Apollo 通常将此称为 'store'),这与您的服务器不同。请参阅 Apollo documentation:
的注释
This watches the cache store of the query according to the options specified and returns an ObservableQuery. We can subscribe to this ObservableQuery and receive updated results through a GraphQL observer when the cache store changes. Note that this method is not an implementation of GraphQL subscriptions. Rather, it uses Apollo's store in order to reactively deliver updates to your query results.
基于服务器的完整实现称为 GraphQL 订阅。订阅更新是客户端在任意时间收到的内容。他们来了,他们就来了。由于无法做出预测,因此在订阅中没有乐观 UI 的用例。因此,为什么不支持它们。我能想到的唯一用例是客户端是否订阅了它自己的更改。在这种情况下,您可以使用 Mutation component 中的 optimisticResponse 和更新选项来进行更新。
乐观 UI 是否只适用于 watchQuery 而不适用于订阅?我们通过 websocket 广泛使用订阅,无法使乐观 UI 工作,尽管它似乎与 watchQuery 一起工作。
所以我的问题很简单,我只需要确认乐观 ui 应该与订阅一起使用?
watchQuery 用于订阅缓存的更新(Apollo 通常将此称为 'store'),这与您的服务器不同。请参阅 Apollo documentation:
的注释This watches the cache store of the query according to the options specified and returns an ObservableQuery. We can subscribe to this ObservableQuery and receive updated results through a GraphQL observer when the cache store changes. Note that this method is not an implementation of GraphQL subscriptions. Rather, it uses Apollo's store in order to reactively deliver updates to your query results.
基于服务器的完整实现称为 GraphQL 订阅。订阅更新是客户端在任意时间收到的内容。他们来了,他们就来了。由于无法做出预测,因此在订阅中没有乐观 UI 的用例。因此,为什么不支持它们。我能想到的唯一用例是客户端是否订阅了它自己的更改。在这种情况下,您可以使用 Mutation component 中的 optimisticResponse 和更新选项来进行更新。