Skip to content

Commit

Permalink
fix: compare serialized variables to prevent unnecessary fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
Akryum committed Jan 22, 2020
1 parent 32d1f75 commit 3a473e2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
11 changes: 8 additions & 3 deletions packages/vue-apollo-composable/src/useQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand Down
11 changes: 8 additions & 3 deletions packages/vue-apollo-composable/src/useSubscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand Down

0 comments on commit 3a473e2

Please sign in to comment.