fix: remove $isServer, closes #1241
This commit is contained in:
@@ -30,6 +30,7 @@ import { paramToReactive } from './util/paramToReactive'
|
||||
import { useEventHook } from './util/useEventHook'
|
||||
import { trackQuery } from './util/loadingTracking'
|
||||
import { toApolloError } from './util/toApolloError'
|
||||
import { isServer } from './util/env'
|
||||
|
||||
import type { CurrentInstance } from './util/types'
|
||||
|
||||
@@ -142,7 +143,6 @@ export function useQueryImpl<
|
||||
): UseQueryReturn<TResult, TVariables> {
|
||||
// Is on server?
|
||||
const vm = getCurrentInstance() as CurrentInstance | null
|
||||
const isServer = vm?.$isServer ?? false
|
||||
|
||||
const currentOptions = ref<UseQueryOptions<TResult, TVariables>>()
|
||||
|
||||
|
||||
@@ -25,9 +25,9 @@ import { paramToReactive } from './util/paramToReactive'
|
||||
import { useApolloClient } from './useApolloClient'
|
||||
import { useEventHook } from './util/useEventHook'
|
||||
import { trackSubscription } from './util/loadingTracking'
|
||||
|
||||
import type { CurrentInstance } from './util/types'
|
||||
import { toApolloError } from './util/toApolloError'
|
||||
import { isServer } from './util/env'
|
||||
|
||||
export interface UseSubscriptionOptions <
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
@@ -113,7 +113,6 @@ export function useSubscription <
|
||||
): UseSubscriptionReturn<TResult, TVariables> {
|
||||
// Is on server?
|
||||
const vm = getCurrentInstance() as CurrentInstance | null
|
||||
const isServer = vm?.$isServer ?? false
|
||||
|
||||
const documentRef = paramToRef(document)
|
||||
const variablesRef = paramToRef(variables)
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
export const isServer = typeof window === 'undefined'
|
||||
@@ -5,5 +5,4 @@ export interface CurrentInstance extends Omit<ComponentInternalInstance, 'root'
|
||||
_apolloAppTracking?: AppLoadingTracking
|
||||
$root?: CurrentInstance
|
||||
root?: CurrentInstance
|
||||
$isServer?: boolean
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import SmartQuery from './smart-query'
|
||||
import SmartSubscription from './smart-subscription'
|
||||
import { reapply } from '../lib/utils'
|
||||
|
||||
import { isServer } from './env'
|
||||
export class DollarApollo {
|
||||
constructor (vm, provider) {
|
||||
this._apolloSubscriptions = []
|
||||
@@ -61,7 +61,7 @@ export class DollarApollo {
|
||||
}
|
||||
|
||||
subscribe (options) {
|
||||
if (!this.vm.$isServer) {
|
||||
if (!isServer) {
|
||||
const observable = this.getClient(options).subscribe(options)
|
||||
const _subscribe = observable.subscribe.bind(observable)
|
||||
observable.subscribe = (options) => {
|
||||
@@ -114,11 +114,11 @@ export class DollarApollo {
|
||||
}
|
||||
|
||||
const smart = this.queries[key] = new SmartQuery(this.vm, key, finalOptions, false)
|
||||
if (!this.vm.$isServer || finalOptions.prefetch !== false) {
|
||||
if (!isServer || finalOptions.prefetch !== false) {
|
||||
smart.autostart()
|
||||
}
|
||||
|
||||
if (!this.vm.$isServer) {
|
||||
if (!isServer) {
|
||||
const subs = finalOptions.subscribeToMore
|
||||
if (subs) {
|
||||
if (Array.isArray(subs)) {
|
||||
@@ -141,7 +141,7 @@ export class DollarApollo {
|
||||
}
|
||||
|
||||
addSmartSubscription (key, options) {
|
||||
if (!this.vm.$isServer) {
|
||||
if (!isServer) {
|
||||
options = reapply(options, this.vm)
|
||||
|
||||
const smart = this.subscriptions[key] = new SmartSubscription(this.vm, key, options, false)
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
export const isServer = typeof window === 'undefined'
|
||||
@@ -1,5 +1,6 @@
|
||||
import { reapply } from '../lib/utils'
|
||||
import { DollarApollo } from './dollar-apollo'
|
||||
import { isServer } from './env'
|
||||
|
||||
function hasProperty (holder, key) {
|
||||
return typeof holder !== 'undefined' && Object.prototype.hasOwnProperty.call(holder, key)
|
||||
@@ -70,7 +71,7 @@ function launch () {
|
||||
if (key.charAt(0) !== '$') {
|
||||
let options = apollo[key]
|
||||
const smart = this.$apollo.addSmartQuery(key, options)
|
||||
if (this.$isServer) {
|
||||
if (isServer) {
|
||||
options = reapply(options, this)
|
||||
if (apolloProvider.prefetch !== false && options.prefetch !== false && apollo.$prefetch !== false && !smart.skip) {
|
||||
this.$_apolloPromises.push(smart.firstRun)
|
||||
@@ -123,7 +124,7 @@ export function installMixin (app, provider) {
|
||||
beforeCreate () {
|
||||
this.$apollo = new DollarApollo(this, provider)
|
||||
proxyData.call(this)
|
||||
if (this.$isServer) {
|
||||
if (isServer) {
|
||||
// Patch render function to cleanup apollo
|
||||
const render = this.$options.render
|
||||
this.$options.render = (h) => {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { throttle, debounce, omit, addGqlError } from '../lib/utils'
|
||||
import { isServer } from './env'
|
||||
|
||||
export default class SmartApollo {
|
||||
type = null
|
||||
@@ -95,7 +96,7 @@ export default class SmartApollo {
|
||||
this.options[prop] = query
|
||||
this.refresh()
|
||||
}
|
||||
if (!this.vm.$isServer) {
|
||||
if (!isServer) {
|
||||
cb = this.options.throttle ? throttle(cb, this.options.throttle) : cb
|
||||
cb = this.options.debounce ? debounce(cb, this.options.debounce) : cb
|
||||
}
|
||||
@@ -108,7 +109,7 @@ export default class SmartApollo {
|
||||
// GraphQL Variables
|
||||
if (typeof this.options.variables === 'function') {
|
||||
let cb = this.executeApollo.bind(this)
|
||||
if (!this.vm.$isServer) {
|
||||
if (!isServer) {
|
||||
cb = this.options.throttle ? throttle(cb, this.options.throttle) : cb
|
||||
cb = this.options.debounce ? debounce(cb, this.options.debounce) : cb
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import SmartApollo from './smart-apollo'
|
||||
import { VUE_APOLLO_QUERY_KEYWORDS } from '../lib/consts'
|
||||
import { isServer } from './env'
|
||||
|
||||
export default class SmartQuery extends SmartApollo {
|
||||
type = 'query'
|
||||
@@ -19,14 +20,14 @@ export default class SmartQuery extends SmartApollo {
|
||||
|
||||
super(vm, key, options, false)
|
||||
|
||||
if (vm.$isServer) {
|
||||
if (isServer) {
|
||||
this.firstRun = new Promise((resolve, reject) => {
|
||||
this._firstRunResolve = resolve
|
||||
this._firstRunReject = reject
|
||||
})
|
||||
}
|
||||
|
||||
if (this.vm.$isServer) {
|
||||
if (isServer) {
|
||||
this.options.fetchPolicy = 'network-only'
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user