4 Commits

Author SHA1 Message Date
Kristaps Fabians Geikins 315d4be6c7 incremented package version 2022-12-09 16:28:36 +02:00
Kristaps Fabians Geikins f4c56afb53 fix: ensuring useQuery immediately returns results from cache, to prevent hydration errors 2022-12-09 16:28:08 +02:00
Kristaps Fabians Geikins 31657ada67 package changes for published fork 2022-11-16 13:19:35 +02:00
Kristaps Fabians Geikins d19a090df2 gaa 2022-11-16 13:19:25 +02:00
2 changed files with 20 additions and 4 deletions
+4 -4
View File
@@ -1,10 +1,10 @@
{
"name": "@vue/apollo-composable",
"version": "4.0.0-beta.1",
"name": "@speckle/vue-apollo-composable",
"version": "4.0.0-beta.2",
"description": "Apollo GraphQL for Vue Composition API",
"repository": {
"type": "git",
"url": "https://github.com/vuejs/vue-apollo.git",
"url": "https://github.com/specklesystems/apollo.git",
"directory": "packages/vue-apollo-composable"
},
"keywords": [
@@ -32,7 +32,7 @@
"dev": "rimraf dist && nodemon --exec 'pnpm run build:code' --watch src --ext js,ts",
"build": "rimraf dist && pnpm run build:code",
"build:code": "node esbuild.mjs && tsc -d --emitDeclarationOnly",
"prepublishOnly": "pnpm run test && pnpm run build",
"prepublishOnly": "pnpm run test && pnpm run build:code",
"test": "pnpm run test:types",
"test:types": "tsc -p tests/types/"
},
@@ -21,6 +21,7 @@ import {
ObservableSubscription,
TypedDocumentNode,
ApolloError,
NetworkStatus
} from '@apollo/client/core'
import { throttle, debounce } from 'throttle-debounce'
import { useApolloClient } from './useApolloClient'
@@ -221,6 +222,7 @@ export function useQueryImpl<
const query: Ref<ObservableQuery<TResult, TVariables> | null | undefined> = ref()
let observer: ObservableSubscription | undefined
let started = false
let isFirstRun = true
/**
* Starts watching the query
@@ -258,12 +260,26 @@ export function useQueryImpl<
addSubscribeToMore(item)
}
}
isFirstRun = false
}
function startQuerySubscription () {
if (observer && !observer.closed) return
if (!query.value) return
// If hydrating already finished queries, just handle result immediately
if (!isServer && isFirstRun) {
const currentResult = query.value.getCurrentResult()
if (currentResult) {
if (currentResult.networkStatus === NetworkStatus.ready) {
onNextResult(currentResult)
} else if (currentResult.networkStatus === NetworkStatus.error && currentResult.error) {
onError(currentResult.error)
}
}
}
// Create subscription
observer = query.value.subscribe({
next: onNextResult,