简体   繁体   English

前端 apollo 和 graphql 的奇怪问题

[英]Weird issues with frontend apollo and graphql

I'm using nuxt.js with apollo.我将 nuxt.js 与阿波罗一起使用。 So basically I have a button and when you press the button it makes a request to the graphql server.所以基本上我有一个按钮,当你按下按钮时,它会向 graphql 服务器发出请求。 The first time I press the button it works perfectly.我第一次按下按钮时它工作得很好。 But the second time it returns the same data.但第二次它返回相同的数据。 Even though it never contacted the server the second time.即使它第二次从未联系过服务器。 I think it has something to do with apollo mistakenly caching data.我认为这与阿波罗错误地缓存数据有关。 But I don't know how to fix it.但我不知道如何解决它。 Does anybody know how to fix this?有人知道如何解决这个问题吗?

To disable cache you can do it globally or for a specific query.要禁用缓存,您可以全局或针对特定查询执行此操作。

Globally:在全球范围内:

new ApolloClient({
  cache,
  link,
  defaultOptions: {
    fetchPolicy: 'no-cache'
  }
})

For a specific query:对于特定查询:

apollo: {
  foo: {
    query: ...,
    fetchPolicy: 'no-cache'
  }
}

It might also be apollo server setting that is returning same data.也可能是返回相同数据的阿波罗服务器设置。 Please check if there is any caching enabled at server end.请检查服务器端是否启用了任何缓存。

cacheControl: { defaultMaxAge: 5 },缓存控制:{ defaultMaxAge:5 },

defaultMaxAge shoud be either set to 0 or cacheControl shoild not be there at all. defaultMaxAge 应该设置为 0 或 cacheControl 根本不应该存在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM