Skip to content

Error in created hook: "TypeError: _this.networkInterface.subscribe is not a function" #1282

Open
@JavaScript7

Description

@JavaScript7

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions