feat: reinit gql client after login
This commit is contained in:
@@ -69,7 +69,7 @@ authIdToken$.subscribe(() => {
|
|||||||
subscriptionClient.client.close()
|
subscriptionClient.client.close()
|
||||||
})
|
})
|
||||||
|
|
||||||
export const client = createClient({
|
const createHoppClient = () => createClient({
|
||||||
url: BACKEND_GQL_URL,
|
url: BACKEND_GQL_URL,
|
||||||
exchanges: [
|
exchanges: [
|
||||||
devtoolsExchange,
|
devtoolsExchange,
|
||||||
@@ -125,6 +125,12 @@ export const client = createClient({
|
|||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export const client = ref(createHoppClient())
|
||||||
|
|
||||||
|
authIdToken$.subscribe(() => {
|
||||||
|
client.value = createHoppClient()
|
||||||
|
})
|
||||||
|
|
||||||
type MaybeRef<X> = X | Ref<X>
|
type MaybeRef<X> = X | Ref<X>
|
||||||
|
|
||||||
type UseQueryOptions<T = any, V = object> = {
|
type UseQueryOptions<T = any, V = object> = {
|
||||||
@@ -192,7 +198,7 @@ export const useGQLQuery = <DocType, DocVarType, DocErrorType extends string>(
|
|||||||
watchEffect(
|
watchEffect(
|
||||||
() => {
|
() => {
|
||||||
source.value = !isPaused.value
|
source.value = !isPaused.value
|
||||||
? client.executeQuery<DocType, DocVarType>(request.value, {
|
? client.value.executeQuery<DocType, DocVarType>(request.value, {
|
||||||
requestPolicy: "cache-and-network",
|
requestPolicy: "cache-and-network",
|
||||||
})
|
})
|
||||||
: undefined
|
: undefined
|
||||||
@@ -210,7 +216,7 @@ export const useGQLQuery = <DocType, DocVarType, DocErrorType extends string>(
|
|||||||
console.log("create sub")
|
console.log("create sub")
|
||||||
|
|
||||||
return wonkaPipe(
|
return wonkaPipe(
|
||||||
client.executeSubscription(sub),
|
client.value.executeSubscription(sub),
|
||||||
onEnd(() => {
|
onEnd(() => {
|
||||||
if (source.value) execute()
|
if (source.value) execute()
|
||||||
}),
|
}),
|
||||||
@@ -307,6 +313,7 @@ export const runMutation = <
|
|||||||
TE.tryCatch(
|
TE.tryCatch(
|
||||||
() =>
|
() =>
|
||||||
client
|
client
|
||||||
|
.value
|
||||||
.mutation(mutation, variables, {
|
.mutation(mutation, variables, {
|
||||||
requestPolicy: "cache-and-network",
|
requestPolicy: "cache-and-network",
|
||||||
...additionalConfig,
|
...additionalConfig,
|
||||||
|
|||||||
Reference in New Issue
Block a user