fix(useSubscription): don't start on server

This commit is contained in:
Guillaume Chau
2019-12-02 03:41:08 +01:00
parent 5d3b7dc598
commit 4c72ff24c0
@@ -1,6 +1,6 @@
import { DocumentNode } from 'graphql'
import Vue from 'vue'
import { Ref, ref, watch, isRef, onUnmounted, computed } from '@vue/composition-api'
import { Ref, ref, watch, isRef, onUnmounted, computed, getCurrentInstance } from '@vue/composition-api'
import { OperationVariables, SubscriptionOptions } from 'apollo-client'
import { Observable, Subscription } from 'apollo-client/util/Observable'
import { FetchResult } from 'apollo-link'
@@ -30,6 +30,10 @@ export function useSubscription <
variables: TVariables | Ref<TVariables> | ReactiveFunction<TVariables> = null,
options: UseSubscriptionOptions<TResult, TVariables> | Ref<UseSubscriptionOptions<TResult, TVariables>> | ReactiveFunction<UseSubscriptionOptions<TResult, TVariables>> = null
) {
// Is on server?
const vm = getCurrentInstance()
const isServer = vm.$isServer
if (variables == null) variables = ref()
if (!options) options = {}
const documentRef = paramToRef(document)
@@ -52,7 +56,7 @@ export function useSubscription <
let started = false
function start () {
if (started || !isEnabled.value) return
if (started || !isEnabled.value || isServer) return
started = true
loading.value = true