可能是由于缓存更新时未更新视图导致问题。可以使用 watch(query:completionHandler:)
方法观察查询并在查询的结果更新时手动重新渲染视图,以确保缓存正确更新且视图正确显示最新数据。
示例代码:
class MyViewController: UIViewController {
var apollo: ApolloClient!
override func viewDidLoad() {
super.viewDidLoad()
let query = MyQuery()
apollo.watch(query: query) { [weak self] result in
switch result {
case .success(let graphQLResult):
// Update the view with the new data
self?.updateView(graphQLResult: graphQLResult)
case .failure(let error):
// Handle errors
print("Error: \(error)")
}
}
}
func updateView(graphQLResult: GraphQLResult) {
// Update the view
}
}