feat: fix gqlclient race condition

This commit is contained in:
Andrew Bastin
2021-11-02 19:11:16 +05:30
committed by liyasthomas
parent 874b846e60
commit b0dd6b0bd6

View File

@@ -7,6 +7,7 @@ import {
watchSyncEffect, watchSyncEffect,
WatchStopHandle, WatchStopHandle,
set, set,
isRef,
} from "@nuxtjs/composition-api" } from "@nuxtjs/composition-api"
import { import {
createClient, createClient,
@@ -120,8 +121,8 @@ const createHoppClient = () =>
}), }),
fetchExchange, fetchExchange,
subscriptionExchange({ subscriptionExchange({
// @ts-expect-error: An issue with the Urql typing
forwardSubscription: (operation) => forwardSubscription: (operation) =>
// @ts-expect-error: An issue with the Urql typing
subscriptionClient.request(operation), subscriptionClient.request(operation),
}), }),
], ],
@@ -259,8 +260,10 @@ export const useGQLQuery = <DocType, DocVarType, DocErrorType extends string>(
onEnd(() => { onEnd(() => {
loading.value = false loading.value = false
isStale.value = false isStale.value = false
console.log("end")
}), }),
subscribe((res) => { subscribe((res) => {
if (res.operation.key === request.value.key) {
data.value = pipe( data.value = pipe(
// The target // The target
res.data as DocType | undefined, res.data as DocType | undefined,
@@ -292,6 +295,7 @@ export const useGQLQuery = <DocType, DocVarType, DocErrorType extends string>(
) )
loading.value = false loading.value = false
}
}) })
).unsubscribe ).unsubscribe
) )
@@ -302,8 +306,11 @@ export const useGQLQuery = <DocType, DocVarType, DocErrorType extends string>(
const execute = (updatedVars?: DocVarType) => { const execute = (updatedVars?: DocVarType) => {
if (updatedVars) { if (updatedVars) {
if (isRef(args.variables)) {
args.variables.value = updatedVars
} else {
set(args, "variables", updatedVars) set(args, "variables", updatedVars)
// args.variables = updatedVars as any }
} }
isPaused.value = false isPaused.value = false