Skip to content

Instantly share code, notes, and snippets.

@smolinari
Created October 4, 2018 14:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smolinari/41f6a1a620ff03caddb6f8d77febf222 to your computer and use it in GitHub Desktop.
Save smolinari/41f6a1a620ff03caddb6f8d77febf222 to your computer and use it in GitHub Desktop.
The plugin file for Quasar and Vue-Apollo
import { ApolloClient } from 'apollo-client'
import { InMemoryCache } from 'apollo-cache-inmemory'
import VueApollo from 'vue-apollo'
import fetch from 'node-fetch'
import { createHttpLink } from 'apollo-link-http'
const httpLink = createHttpLink({ uri: 'http://localhost:4000/graphql', fetch: fetch })
// Create the apollo client
const apolloClient = new ApolloClient({
link: httpLink,
cache: new InMemoryCache(),
connectToDevTools: true
})
export const apolloProvider = new VueApollo({
defaultClient: apolloClient,
errorHandler ({ graphQLErrors, networkError }) {
if (graphQLErrors) {
graphQLErrors.map(({ message, locations, path }) =>
console.log(
`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`
)
)
}
if (networkError) {
console.log(`[Network error]: ${networkError}`)
}
}
})
export default ({ app, Vue }) => {
Vue.use(VueApollo)
app.apolloProvider = apolloProvider
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment