How to disable cache in apollo-link or apollo-client?

前端 未结 3 1285
粉色の甜心
粉色の甜心 2021-02-01 00:21

I\'m using apollo-client, apollo-link and react-apollo, I want to fully disable cache, but don\'t know how to do it.

I read the source of

3条回答
  •  清酒与你
    2021-02-01 01:21

    You can set defaultOptions to your client like this:

    const defaultOptions: DefaultOptions = {
          watchQuery: {
            fetchPolicy: 'no-cache',
            errorPolicy: 'ignore',
          },
          query: {
            fetchPolicy: 'no-cache',
            errorPolicy: 'all',
          },
        }
    
    const client = new ApolloClient({
        link: concat(authMiddleware, httpLink),
        cache: new InMemoryCache(),
        defaultOptions: defaultOptions,
    
    });
    

    fetchPolicy as no-cache avoids using the cache.

    See https://www.apollographql.com/docs/react/api/apollo-client/#apolloclient-functions

提交回复
热议问题