vue.js - 手动运行 vue-apollo 查询时禁用缓存
问题描述
我使用 vue-apollo 来处理 GraphQL。
我通过安装它vue add apollo
,因此有一个用于配置的 vue-apollo.js。
当前配置:
// Call this in the Vue app file
export function createProvider (options = {}) {
// Create vue apollo provider
const apolloProvider = new VueApollo({
defaultClient: apolloClient,
defaultOptions: {
$query: {
fetchPolicy: 'no-cache',
// fetchPolicy: 'cache-and-network',
},
},
errorHandler (error) {
// eslint-disable-next-line no-console
console.log('%cError', 'background: red; color: white; padding: 2px 4px; border-radius: 3px; font-weight: bold;', error.message)
},
})
return apolloProvider
}
我想做的是禁用任何查询的缓存。现在,当我通过apollo:
组件属性进行查询时,它被禁用。但是当我通过 $apollo 实例手动运行查询时,它不起作用。
如果我为每个查询添加 fetchPolicy,它确实有效,例如:
const response = await this.$apollo.query({
query: documentSetListQuery,
variables: {
...mapFilters(this.getActualFilters(this.filters), whitelistFilters),
regime: false
},
fetchPolicy: 'no-cache'
})
no-cache
如果我通过手动运行查询,是否可以全局设置this.$apollo.query
?只是为了避免fetchPolity: 'no-cache'
重复
解决方案
推荐阅读
- node.js - Node Express js 未处理的拒绝错误 [ERR_HTTP_HEADERS_SENT]
- android - 库 com.google.android.gms:play-services-measurement-api 正在被其他各种库请求
- javascript - 如何在角度应用程序中调用 APP_INITIALIZER
- android - 如何在android中使用Adiantum进行加密?
- orientdb - 是否可以在 Nodejs 中使用 Tinkerpop/Gremlin 来操作 OrientDB 中的数据?
- android - 为什么我无法在以下棒棒糖版本中搜索位置?
- swift - 表视图中的 Swift Uicollection 视图
- excel - 如何将 excel 中的图像路径转换为 PowerApps 中的图像?
- reactjs - 有没有办法根据当前滚动的位置获取元素?
- java - Hibernate:如何在 Spring Boot JpaRepository 中获取最后 n 行?