Description
apolloClient.js:
`
import Vue from 'vue'
import { ApolloClient } from 'apollo-client'
import { HttpLink, createHttpLink } from 'apollo-link-http'
import { WebSocketLink } from 'apollo-link-ws'
import { split } from 'apollo-link'
import { getMainDefinition } from 'apollo-utilities'
import { InMemoryCache } from 'apollo-cache-inmemory'
import { setContext } from 'apollo-link-context'
import VueApollo from 'vue-apollo'
Vue.use(VueApollo)
const httpLink = new HttpLink({
uri: "https://******"
})
const wsLink = new WebSocketLink({
uri: "wss://*****"
options: {
reconnect: true
}
})
const link = split(
({ query }) => {
const definition = getMainDefinition(query)
return definition.kind === 'OperationDefinition' &&
definition.operation === 'subscription'
},
wsLink,
httpLink
)
const apolloClient = new ApolloClient({
link: link,
cache: new InMemoryCache(),
connectToDevTools: true
})
export const apolloProvider = new VueApollo({
defaultClient: apolloClient
})main.js:
import { apolloProvider } from './assets/js/apolloClient'
new Vue({
router,
store,
i18n,
apolloProvider,
render: h => h(App),
}).$mount("#app")
home.vue:
data:{},
apollo: {
$subscribe: {
messages: {
query: gql subscription messages{ messages { data type } }
,
result ({data}) {
console.log(data)
}
}
}
}
`
According to the above writing method, but this problem occurs。
Error in created hook: "TypeError: _this.networkInterface.subscribe is not a function" ?
what should I do?