diff --git a/packages/test-e2e-composable-vue3/src/components/NoSetupScopeQuery.vue b/packages/test-e2e-composable-vue3/src/components/NoSetupScopeQuery.vue
new file mode 100644
index 00000000..c57c2128
--- /dev/null
+++ b/packages/test-e2e-composable-vue3/src/components/NoSetupScopeQuery.vue
@@ -0,0 +1,42 @@
+
+
+
+
+ {{ hello }}
+
+
diff --git a/packages/test-e2e-composable-vue3/src/router.ts b/packages/test-e2e-composable-vue3/src/router.ts
index 51bbbdc6..03615be8 100644
--- a/packages/test-e2e-composable-vue3/src/router.ts
+++ b/packages/test-e2e-composable-vue3/src/router.ts
@@ -72,5 +72,12 @@ export const router = createRouter({
layout: 'blank',
},
},
+ {
+ path: '/no-setup-scope-query',
+ component: () => import('./components/NoSetupScopeQuery.vue'),
+ meta: {
+ layout: 'blank',
+ },
+ },
],
})
diff --git a/packages/test-e2e-composable-vue3/tests/e2e/specs/test.cy.ts b/packages/test-e2e-composable-vue3/tests/e2e/specs/test.cy.ts
index d2a37ce1..f52279ba 100644
--- a/packages/test-e2e-composable-vue3/tests/e2e/specs/test.cy.ts
+++ b/packages/test-e2e-composable-vue3/tests/e2e/specs/test.cy.ts
@@ -119,4 +119,9 @@ describe('Vue 3 + Apollo Composable', () => {
cy.get('[data-test-id="global-loading"]').should('not.contain', 'Global loading...')
cy.contains('#app', 'Currently viewing # General')
})
+
+ it('supports queries outside of setup but within scope', () => {
+ cy.visit('/no-setup-scope-query')
+ cy.contains('.no-setup-scope-query', 'Hello world!')
+ })
})
diff --git a/packages/vue-apollo-composable/src/useApolloClient.ts b/packages/vue-apollo-composable/src/useApolloClient.ts
index cee3e60a..134392a1 100644
--- a/packages/vue-apollo-composable/src/useApolloClient.ts
+++ b/packages/vue-apollo-composable/src/useApolloClient.ts
@@ -1,4 +1,4 @@
-import { getCurrentInstance, getCurrentScope, inject } from 'vue-demi'
+import { hasInjectionContext, inject } from 'vue-demi'
import { ApolloClient } from '@apollo/client/core/index.js'
export const DefaultApolloClient = Symbol('default-apollo-client')
@@ -35,7 +35,7 @@ export function useApolloClient (clientId?: ClientId): UseApo
// Save current client in current closure scope
const savedCurrentClients = currentApolloClients
- if (!getCurrentInstance() && !getCurrentScope()) {
+ if (!hasInjectionContext()) {
resolveImpl = (id?: ClientId) => {
if (id) {
return resolveClientWithId(savedCurrentClients, id)