apollo - 如何使用 apollo 缓存来匹配作为子数组/子 ID 列表的输入变量?
问题描述
如何使用 apollo 缓存来匹配作为缓存中 id 的子数组/子列表的输入变量?
特别是,当我执行 apollo 查询时,我想返回一个参数列表子集的响应。
换句话说,我怎样才能在缓存中添加额外的条目,以便我的缓存可以匹配未来的“子查询”,例如
fetch({
variables: {
ids: ['1']
}
})
当我之前询问过
fetch({
variables: {
ids: ['1', '2', '3']
}
})
完整示例如下:
// This code is not working, but just used to illustrate an example.
const [fetch, data] = useQuery( /* graphql params here */ );
// Apollo cache will cache the response for `ids: ['1', '2', '3']`
fetch({
variables: {
ids: ['1', '2', '3']
}
})
// In these subsequent call, I don't want to hit the server and want to hit the cache.
// Can I leverage apollo cache for this?
fetch({
variables: {
ids: ['1']
}
})
fetch({
variables: {
ids: ['2','3']
}
})
fetch({
variables: {
ids: ['1','2']
}
})
解决方案
推荐阅读
- c++ - C++ 发生二进制文件 i\o 错误
- javascript - Promise 的动态顺序执行
- react-native-ios - 如何检查是否在 React Native 项目中触发了本机代码
- javascript - JSON data, cant load console error
- ios - How to correctly use Apollo GraphQL on iOS with background session configuration?
- flutter - Flutter: HttpClient post contentLength -- exception
- css - How can i calculate percentages in pure css3 slider for 10 slides
- java - 基于主题通知 FCM 的 Android Studio 自定义声音
- database - 连接这 3 个表以删除虚假行的 SQL 查询 - OWNER、TYPE、PERSON
- ios - 如何在 tableview 中重用动态原型单元格