Skip to content

Enable a disabled useQuery outside of setup() -- alpha 12 #1082

Open
@rebz

Description

@rebz

Describe the bug
Using useQuery and attempting to enable a disabled query when used outside of setup(). Looks like the ApolloClient is coming back as null.

vue.runtime.esm.js:619 [Vue warn]: Error in callback for watcher "function () { return source.value; }": "Error: Apollo client with id default not found. Use provideApolloClient() if you are outside of a component setup."
Error: Apollo client with id default not found. Use provideApolloClient() if you are outside of a component setup.

image

Logging out the following in useApolloClient...
image
image

To Reproduce
Steps to reproduce the behavior:

  1. Clone this v4 repo
  2. Go to /packages/test-e2e-composable-vue3/src/components/NoSetupQuery.vue
  3. Update the <script> tag with what you see below
  4. Try running your no-setup-query test.
<script lang="ts">
import { apolloClient } from '@/apollo'
import { gql } from '@apollo/client/core'
import { provideApolloClient, useQuery, useResult } from '@vue/apollo-composable'
import { defineComponent, ref } from 'vue'

// Global query

const enabled = ref(false)

const query = provideApolloClient(apolloClient)(() => useQuery(gql`
  query hello {
    hello
  }
`, null, () => ({ enabled: enabled.value })))

const hello = useResult(query.result, [])

function enable () {
  enabled.value = true
}

export default defineComponent({
  setup () {
    enable()
    return {
      hello,
    }
  },
})
</script>

Expected behavior
I expect the default ApolloClient, provided using provideApolloClient(), to be found by useQuery() and and for the query to execute once enabled.

Versions
vue: 2.6 w/ @vue/composition-api plugin
vue-apollo: 4.0.0-alpha.12
apollo-client: 3.2.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions