You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I simply cannot get websockets to work with Hasura and Vue-cli-plugin-apollo.
In particular Vue Apollo stop complaining about missing websockets connection headers (at least explicitly) but it's now throwing the following error:
'Error: start received before the connection is initialised'.
I have in vue-apollo.js:
/* eslint-disable */importVuefrom'vue'importVueApollofrom'vue-apollo'import{createApolloClient,restartWebsockets}from'vue-cli-plugin-apollo/graphql-client'importauthServicefrom'./auth/authService'import{InMemoryCache}from'apollo-cache-inmemory'import{SubscriptionClient}from"subscriptions-transport-ws";// Install the vue pluginVue.use(VueApollo)// Name of the localStorage itemconstAUTH_TOKEN='apollo-token'// Http endpoint: puedo poner 'https://vuejs-auth0-graphql.herokuapp.com/v1/graphql'consthttpEndpoint='https://vuejs-auth0-graphql.herokuapp.com/v1/graphql'// Files URL rootexportconstfilesRoot='https://vuejs-auth0-graphql.herokuapp.com'Vue.prototype.$filesRoot=filesRoot// ConfigconstdefaultOptions={// You can use `https` for secure connection (recommended in production)
httpEndpoint,// You can use `wss` for secure connection (recommended in production)// Use `null` to disable subscriptionswsEndpoint: 'wss://vuejs-auth0-graphql.herokuapp.com/v1/graphql',// LocalStorage tokentokenName: AUTH_TOKEN,// Enable Automatic Query persisting with Apollo Enginepersisting: false,// Use websockets for everything (no HTTP)// You need to pass a `wsEndpoint` for this to workwebsocketsOnly: false,// Is being rendered on the server?ssr: false,// Override default apollo link// note: don't override httpLink here, specify httpLink options in the// httpLinkOptions property of defaultOptions.// link: myLink// Override default cachecache: newInMemoryCache({freezeResults: false}),// cache: new InMemoryCache(),// Override the way the Authorization header is set// getAuth: (tokenName) => ...// Additional ApolloClient options// apollo: { ... }// Client local data (see apollo-link-state)// clientState: { resolvers: { ... }, defaults: { ... } }getAuth: tokenName=>{// get the authentication token from local storage if it exists// return the headers to the context so httpLink can read themconsttoken=localStorage.getItem('apollo-token')if(token){return'Bearer '+token}else{return''}},}// Call this in the Vue app fileexportfunctioncreateProvider(options={}){// Create apollo clientconst{ apolloClient, wsClient }=createApolloClient({
...defaultOptions,
...options})wsClient.lazy=truewsClient.reconnect=true// Override connection paramswsClient.connectionParams=()=>{constauthorization=getAuth(tokenName)returnauthorization ? {headers: { authorization }} : {}}// Set apollo client's websocket clientapolloClient.wsClient=wsClient// Create vue apollo providerconstapolloProvider=newVueApollo({defaultClient: apolloClient,defaultOptions: {$query: {//fetchPolicy: 'cache-and-network',}},errorHandler(error){// eslint-disable-next-line no-consoleconsole.log('%cError','background: red; color: white; padding: 2px 4px; border-radius: 3px; font-weight: bold;',error.message)}})returnapolloProvider}// las otras opciones son no usar plugin completo y editar vue apollo plugin// Manually call this when user log inexportasyncfunctiononLogin(apolloClient,token){if(typeoflocalStorage!=='undefined'&&token){localStorage.setItem(AUTH_TOKEN,token)}if(apolloClient.wsClient)restartWebsockets(apolloClient.wsClient)try{awaitapolloClient.resetStore()}catch(e){// eslint-disable-next-line no-consoleconsole.log('%cError on cache reset (login)','color: orange;',e.message)}}// Manually call this when user log outexportasyncfunctiononLogout(apolloClient){if(typeoflocalStorage!=='undefined'){localStorage.removeItem(AUTH_TOKEN)}if(apolloClient.wsClient)restartWebsockets(apolloClient.wsClient)try{awaitapolloClient.resetStore()}catch(e){// eslint-disable-next-line no-consoleconsole.log('%cError on cache reset (logout)','color: orange;',e.message)}}
I don't understand why is failing the websockets connection.
Please help me to find what is missing.
Thanks for your time.
The text was updated successfully, but these errors were encountered:
Hi all:
I simply cannot get websockets to work with Hasura and Vue-cli-plugin-apollo.
In particular Vue Apollo stop complaining about missing websockets connection headers (at least explicitly) but it's now throwing the following error:
'Error: start received before the connection is initialised'.
I have in vue-apollo.js:
I don't understand why is failing the websockets connection.
Please help me to find what is missing.
Thanks for your time.
The text was updated successfully, but these errors were encountered: