Vue-apollo: How to change default fetchPolicy?

Created on 20 Dec 2017  路  2Comments  路  Source: vuejs/vue-apollo

I want to change the default fetch policy for all my queries - how is this possible?

Most helpful comment

In Vue Apollo 2.x it seems like you have to define this on ApolloClient directly:

const apolloClient = new ApolloClient({
  link: httpLink,
  // link: batchHttpLink,
  cache: new InMemoryCache(),
  connectToDevTools: true,
  defaultOptions: {
    watchQuery: {
      fetchPolicy: 'cache-and-network'
    },
    query: {
      fetchPolicy: 'network-only'
    }
  }
})

All 2 comments

https://github.com/Akryum/vue-apollo#special-options you can use all this variables https://github.com/Akryum/vue-apollo/blob/next/src/consts.js

const apolloProvider = new VueApollo({
  defaultClient: apolloClient,
  defaultOptions: {
    // apollo options applied to all components that are using apollo
    $fetchPolicy: 'cache-and-network',
  },
})

In Vue Apollo 2.x it seems like you have to define this on ApolloClient directly:

const apolloClient = new ApolloClient({
  link: httpLink,
  // link: batchHttpLink,
  cache: new InMemoryCache(),
  connectToDevTools: true,
  defaultOptions: {
    watchQuery: {
      fetchPolicy: 'cache-and-network'
    },
    query: {
      fetchPolicy: 'network-only'
    }
  }
})
Was this page helpful?
0 / 5 - 0 ratings