Created
September 26, 2019 14:50
-
-
Save denisrudnei/46aef7835bff74c7fc6d8ea060f80b75 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Vue from 'vue' | |
import VueApollo from 'vue-apollo' | |
import { ApolloClient } from 'apollo-client' | |
import { createHttpLink } from 'apollo-link-http' | |
import { split } from 'apollo-link' | |
import { WebSocketLink } from 'apollo-link-ws' | |
import { InMemoryCache } from 'apollo-cache-inmemory' | |
import { getMainDefinition } from 'apollo-utilities' | |
const httpLink = createHttpLink({ | |
uri: '/api/graphql' | |
}) | |
const wsLink = new WebSocketLink({ | |
uri: `ws://${window.location.host}/api/subscriptions`, | |
options: { | |
reconnect: true | |
} | |
}) | |
const link = split( | |
({ query }) => { | |
const definition = getMainDefinition(query) | |
return ( | |
definition.kind === 'OperationDefinition' && | |
definition.operation === 'subscription' | |
) | |
}, | |
wsLink, | |
httpLink | |
) | |
const cache = new InMemoryCache() | |
const apolloClient = new ApolloClient({ | |
link, | |
cache, | |
connectToDevTools: true | |
}) | |
const apolloProvider = new VueApollo({ | |
defaultClient: apolloClient | |
}) | |
Vue.prototype.$apolloProvider = apolloProvider | |
Vue.use(VueApollo) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment