INIT commit
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import {ApolloClient, ApolloLink, HttpLink, InMemoryCache} from '@apollo/client/core'
|
||||
import {createApolloProvider} from "@vue/apollo-option";
|
||||
|
||||
const httpLink = new HttpLink({
|
||||
uri: 'http://localhost:8000/graphql',
|
||||
credentials: 'include'
|
||||
})
|
||||
|
||||
export const apolloClient = new ApolloClient({
|
||||
link: ApolloLink.from([httpLink]),
|
||||
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,
|
||||
})
|
||||
Reference in New Issue
Block a user