Vue-apollo: v4: useQuery and potentially others are broken with latest @vue/composition-api (0.6.1)

Created on 10 Jun 2020  路  5Comments  路  Source: vuejs/vue-apollo

Describe the bug
useQuery seems to be watching for optionRef and documentRef but watch is not executed immediately unless {immediate: true} specified, so you end up with undefined values causing execution to fail with quite weird errors.

To Reproduce
Create a vue component.
in setup() call useQuery()

Observation:
the query will never be executed. if you force start you will get error due to undefined currentOption.

Expected behavior
A clear and concise description of what you expected to happen.

Versions
"vue": "^2.6.11",
"@vue/composition-api": "^0.6.1",
"@vue/apollo-composable": "^4.0.0-alpha.8",
"apollo-boost": "^0.4.9",

Additional context

https://github.com/vuejs/vue-apollo/blob/v4/packages/vue-apollo-composable/src/useQuery.ts#L318-L352

  let currentDocument: DocumentNode // will be undefined
  watch(documentRef, value => {
    currentDocument = value
    restart()
  })

  // Applying variables
  let currentVariables: TVariables  // will be undefined
  let currentVariablesSerialized: string  // will be undefined
  watch(variablesRef, (value, oldValue) => {
    const serialized = JSON.stringify(value)
    if (serialized !== currentVariablesSerialized) {
      currentVariables = value
      restart()
    }
    currentVariablesSerialized = serialized
  }, {
    deep: true,
  })

  // Applying options
  const currentOptions = ref<UseQueryOptions<TResult, TVariables>>()  // will be undefined
  watch(() => isRef(optionsRef) ? optionsRef.value : optionsRef, value => {
    if (currentOptions.value && (
      currentOptions.value.throttle !== value.throttle ||
      currentOptions.value.debounce !== value.debounce
    )) {
      updateRestartFn()
    }
    currentOptions.value = value
    restart()
  }, {
    deep: true,
  })
v4

Most helpful comment

@Akryum is there something we can do to help on this ?(there's already a pr, does it need more work ?)

All 5 comments

Confirm this issue

temporally works downgrading to v.0.5.0

@Akryum is there something we can do to help on this ?(there's already a pr, does it need more work ?)

One more confirmation.

I guess this can be closed since https://github.com/vuejs/vue-apollo/pull/1000 got merged and released with v4.0.0-alpha.10 ? Or is it still happening?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sadhakbj picture sadhakbj  路  3Comments

alsofronie picture alsofronie  路  3Comments

agosto-chrisbartling picture agosto-chrisbartling  路  4Comments

anymost picture anymost  路  3Comments

apertureless picture apertureless  路  4Comments