55 lines
1.3 KiB
JavaScript
55 lines
1.3 KiB
JavaScript
import {ApolloClient, ApolloLink, HttpLink, InMemoryCache} from '@apollo/client/core'
|
|
import {createApolloProvider} from "@vue/apollo-option";
|
|
import { createUploadLink } from 'apollo-upload-client';
|
|
|
|
const httpLink = new HttpLink({
|
|
uri: 'http://localhost:8000/graphql',
|
|
credentials: 'include'
|
|
})
|
|
|
|
const uploadLink = createUploadLink({
|
|
uri: 'http://localhost:8000/graphql',
|
|
credentials: 'include'
|
|
})
|
|
|
|
export const apolloClient = new ApolloClient({
|
|
link: ApolloLink.from([uploadLink]),
|
|
cache: new InMemoryCache(),
|
|
connectToDevTools: true,
|
|
})
|
|
|
|
export const apolloWrapper = {
|
|
query(query, variables = {}) {
|
|
return apolloClient.query({
|
|
query: query,
|
|
fetchPolicy: 'no-cache',
|
|
variables: variables
|
|
})
|
|
.then((response) => response)
|
|
.catch(err => {
|
|
console.error("Error during query: ", err)
|
|
})
|
|
},
|
|
|
|
mutate(mutation, variables, onUpdate = () => {}) {
|
|
return apolloClient
|
|
.mutate({
|
|
mutation: mutation,
|
|
fetchPolicy: 'no-cache',
|
|
variables: variables,
|
|
update: () => {
|
|
onUpdate();
|
|
},
|
|
})
|
|
.then((response) => response)
|
|
.catch(err => {
|
|
console.error("Error during mutation: ", err);
|
|
})
|
|
},
|
|
}
|
|
|
|
// @see https://v4.apollo.vuejs.org/migration/
|
|
export const apolloProvider = createApolloProvider({
|
|
defaultClient: apolloClient,
|
|
})
|