Mirror: The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

(vue) - allow for passing in the client as a ref (#1962)

* allow for passing in the client as a ref

* amend changeset to include install

authored by

Jovi De Croock and committed by
GitHub
9446377a 63eec7eb

+21 -5
+5
.changeset/tasty-dragons-check.md
··· 1 + --- 2 + '@urql/vue': minor 3 + --- 4 + 5 + Allow passing in a Ref of client to `provideClient` and `install`
+16 -5
packages/vue-urql/src/useClient.ts
··· 1 - import { App, getCurrentInstance, inject, provide } from 'vue'; 1 + import { App, getCurrentInstance, inject, provide, Ref, isRef } from 'vue'; 2 2 import { Client, ClientOptions } from '@urql/core'; 3 3 4 - export function provideClient(opts: ClientOptions | Client) { 5 - const client = opts instanceof Client ? opts : new Client(opts); 4 + export function provideClient(opts: ClientOptions | Client | Ref<Client>) { 5 + let client: Client; 6 + if (isRef(opts)) { 7 + client = opts.value; 8 + } else { 9 + client = opts instanceof Client ? opts : new Client(opts); 10 + } 11 + 6 12 provide('$urql', client); 7 13 return client; 8 14 } 9 15 10 - export function install(app: App, opts: ClientOptions | Client) { 11 - const client = opts instanceof Client ? opts : new Client(opts); 16 + export function install(app: App, opts: ClientOptions | Client | Ref<Client>) { 17 + let client: Client; 18 + if (isRef(opts)) { 19 + client = opts.value; 20 + } else { 21 + client = opts instanceof Client ? opts : new Client(opts); 22 + } 12 23 app.provide('$urql', client); 13 24 } 14 25