如何解决手动运行 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'
重复
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。