chore: refactor a lot, add codegen and upgrade vue
This commit is contained in:
+10
-10
@@ -1,7 +1,9 @@
|
||||
import { ApolloClient, InMemoryCache, createHttpLink } from '@apollo/client/core'
|
||||
import {
|
||||
ApolloClient,
|
||||
InMemoryCache,
|
||||
createHttpLink
|
||||
} from '@apollo/client/core'
|
||||
import { setContext } from '@apollo/client/link/context'
|
||||
import { provide } from '@vue/composition-api'
|
||||
import { DefaultApolloClient } from '@vue/apollo-composable'
|
||||
import { useAuth } from './auth'
|
||||
|
||||
const apiUrl = process.env.graphqlApi || '/query'
|
||||
@@ -12,12 +14,12 @@ const httpLink = createHttpLink({
|
||||
uri: apiUrl
|
||||
})
|
||||
|
||||
const getToken = async (options) => {
|
||||
const getToken = (options) => {
|
||||
const { getTokenSilently } = useAuth()
|
||||
return getTokenSilently.value(options)
|
||||
return getTokenSilently(options)
|
||||
}
|
||||
|
||||
const authLink = setContext(async (_, { headers }) => {
|
||||
const authLink = setContext((_, { headers }) => {
|
||||
return getToken().then((token) => ({
|
||||
headers: {
|
||||
...headers,
|
||||
@@ -42,8 +44,6 @@ const instance = new ApolloClient({
|
||||
}
|
||||
})
|
||||
|
||||
export default function ({ app }) {
|
||||
app.setup = () => {
|
||||
provide(DefaultApolloClient, instance)
|
||||
}
|
||||
export default function (_, inject) {
|
||||
inject('apollo', instance)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user