···11+---
22+'@urql/vue': minor
33+---
44+55+Provide the client as a ref so it can observe changes. This change is potentially breaking for
66+anyone using the `useClient` import as it will now return a `Ref<Client>` rather than a `Client`
+12-12
packages/vue-urql/src/useClient.ts
···11-import { App, getCurrentInstance, inject, provide, Ref, isRef } from 'vue';
11+import { App, getCurrentInstance, inject, provide, Ref, isRef, ref } from 'vue';
22import { Client, ClientOptions } from '@urql/core';
3344export function provideClient(opts: ClientOptions | Client | Ref<Client>) {
55- let client: Client;
66- if (isRef(opts)) {
77- client = opts.value;
55+ let client: Ref<Client>;
66+ if (!isRef(opts)) {
77+ client = ref(opts instanceof Client ? opts : new Client(opts));
88 } else {
99- client = opts instanceof Client ? opts : new Client(opts);
99+ client = opts;
1010 }
11111212 provide('$urql', client);
1313- return client;
1313+ return client.value;
1414}
15151616export function install(app: App, opts: ClientOptions | Client | Ref<Client>) {
1717- let client: Client;
1818- if (isRef(opts)) {
1919- client = opts.value;
1717+ let client: Ref<Client>;
1818+ if (!isRef(opts)) {
1919+ client = ref(opts instanceof Client ? opts : new Client(opts));
2020 } else {
2121- client = opts instanceof Client ? opts : new Client(opts);
2121+ client = opts;
2222 }
2323 app.provide('$urql', client);
2424}
25252626-export function useClient(): Client {
2626+export function useClient(): Ref<Client> {
2727 if (process.env.NODE_ENV !== 'production' && !getCurrentInstance()) {
2828 throw new Error(
2929 'use* functions may only be called during the `setup()` or other lifecycle hooks.'
3030 );
3131 }
32323333- const client = inject('$urql') as Client;
3333+ const client = inject('$urql') as Ref<Client>;
3434 if (process.env.NODE_ENV !== 'production' && !client) {
3535 throw new Error(
3636 'No urql Client was provided. Did you forget to install the plugin or call `provideClient` in a parent?'