function createProvider(options = {}) {
  // Create apollo client
  const { apolloClient, wsClient } = createApolloClient({
    ...defaultOptions,
    ...options
  })

  // Override connection params
  wsClient.connectionParams = () => {
    const token = localStorage.getItem(AUTH_TOKEN)
    return {
      headers: {
        Authorization: token ? `Bearer ${token}` : ''
      }
    }
  }

  apolloClient.wsClient = wsClient

  // Create vue apollo provider
  const apolloProvider = new VueApollo({
    defaultClient: apolloClient,
    defaultOptions: {
      $query: {
        // 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
}
// Call this in the Vue app file
Call this in the Vue app file
Call this in the Vue app file
function createProvider(options = {}) {
  const { apolloClient, wsClient } = createApolloClient({
    ...defaultOptions,
    ...options
  })
  wsClient.connectionParams = () => {
    const token = localStorage.getItem(AUTH_TOKEN)
    return {
      headers: {
        Authorization: token ? `Bearer ${token}` : ''
      }
    }
  }
  apolloClient.wsClient = wsClient
  const apolloProvider = new VueApollo({
    defaultClient: apolloClient,
    defaultOptions: {
      $query: {
      }
    },
    errorHandler(error) {
      console.log(
        '%cError',
        'background: red; color: white; padding: 2px 4px; border-radius: 3px; font-weight: bold;',
        error.message
      )
    }
  })
  return apolloProvider
}
function createProvider ( options = { } ) { const { apolloClient , wsClient } = createApolloClient ( { ... defaultOptions , ... options } ) wsClient . connectionParams = ( ) => { const token = localStorage . getItem ( AUTH_TOKEN ) return { headers : { Authorization : token ? ` ${ token } ` : '' } } } apolloClient . wsClient = wsClient const apolloProvider = new VueApollo ( { defaultClient : apolloClient , defaultOptions : { $query : { } } , errorHandler ( error ) { console . log ( '%cError' , 'background: red; color: white; padding: 2px 4px; border-radius: 3px; font-weight: bold;' , error . message ) } } ) return apolloProvider }
Call this in the Vue app file
Call this in the Vue app file
// Create apollo client // Override connection params // Create vue apollo provider // fetchPolicy: 'cache-and-network', // eslint-disable-next-line no-console