From 3a473e264336b0b2d5442ee4efb63aa8513de1c5 Mon Sep 17 00:00:00 2001 From: Guillaume Chau Date: Wed, 22 Jan 2020 13:28:41 +0100 Subject: [PATCH] fix: compare serialized variables to prevent unnecessary fetch --- packages/vue-apollo-composable/src/useQuery.ts | 11 ++++++++--- packages/vue-apollo-composable/src/useSubscription.ts | 11 ++++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/packages/vue-apollo-composable/src/useQuery.ts b/packages/vue-apollo-composable/src/useQuery.ts index c2e1178..2a56917 100644 --- a/packages/vue-apollo-composable/src/useQuery.ts +++ b/packages/vue-apollo-composable/src/useQuery.ts @@ -323,9 +323,14 @@ export function useQuery< // Applying variables let currentVariables: TVariables - watch(variablesRef, value => { - currentVariables = value - restart() + let currentVariablesSerialized: string + watch(variablesRef, (value, oldValue) => { + const serialized = JSON.stringify(value) + if (serialized !== currentVariablesSerialized) { + currentVariables = value + restart() + } + currentVariablesSerialized = serialized }, { deep: true, }) diff --git a/packages/vue-apollo-composable/src/useSubscription.ts b/packages/vue-apollo-composable/src/useSubscription.ts index 14c9072..79b6f58 100644 --- a/packages/vue-apollo-composable/src/useSubscription.ts +++ b/packages/vue-apollo-composable/src/useSubscription.ts @@ -211,9 +211,14 @@ export function useSubscription < // Applying variables let currentVariables: TVariables - watch(variablesRef, value => { - currentVariables = value - restart() + let currentVariablesSerialized: string + watch(variablesRef, (value, oldValue) => { + const serialized = JSON.stringify(value) + if (serialized !== currentVariablesSerialized) { + currentVariables = value + restart() + } + currentVariablesSerialized = serialized }, { deep: true, })