11import { describe , expect , it } from "vitest" ;
2- import type { App , MaybeRef } from "vue" ;
3- import { createApp , defineComponent , ref } from "vue" ;
4- import { Client , CombinedError , provideClient , useQuery } from "@urql/vue" ;
2+ import type { MaybeRef } from "vue" ;
3+ import { ref } from "vue" ;
4+ import { Client , CombinedError , useQuery } from "@urql/vue" ;
55import gql from "graphql-tag" ;
66import { fromValue , never } from "wonka" ;
77
8- type SetupFunction = ( ) => Record < string , unknown > ;
9-
10- interface WithSetupsOptions {
11- setupParent : SetupFunction ;
12- setupChild : SetupFunction ;
13- }
14-
15- class DisposableApp implements Disposable {
16- constructor ( private app : App ) { }
17-
18- [ Symbol . dispose ] ( ) {
19- this . app . unmount ( ) ;
20- }
21- }
22-
23- function withSetups ( options : WithSetupsOptions ) {
24- const ParentComponent = defineComponent ( {
25- setup : options . setupParent ,
26- template : "<child-component />" ,
27- } ) ;
28-
29- const ChildComponent = defineComponent ( {
30- setup : options . setupChild ,
31- template : "<template />" ,
32- } ) ;
33-
34- const app = createApp ( ParentComponent ) ;
35- app . component ( "ChildComponent" , ChildComponent ) ;
36- app . mount ( document . createElement ( "div" ) ) ;
37- const disposable = new DisposableApp ( app ) ;
38- return { app, [ Symbol . dispose ] : ( ) => disposable [ Symbol . dispose ] ( ) } ;
39- }
8+ import { useInSetupWithUrqlClient } from "@/graphql/tests" ;
409
4110export const FooDocument = gql `
4211 query foo {
@@ -50,19 +19,11 @@ export type FooQuery = {
5019} ;
5120
5221function useQueryFromClient ( client : MaybeRef < Client > ) {
53- let query : ReturnType < typeof useQuery < FooQuery > > | undefined ;
54- const app = withSetups ( {
55- setupParent ( ) {
56- provideClient ( client ) ;
57- return { } ;
58- } ,
59- setupChild ( ) {
60- query = useQuery < FooQuery > ( { query : FooDocument } ) ;
61- return { } ;
62- } ,
63- } ) ;
64- if ( ! query ) throw new Error ( "query is undefined" ) ;
65- return { ...app , query, [ Symbol . dispose ] : ( ) => app [ Symbol . dispose ] ( ) } ;
22+ const { ret : query , [ Symbol . dispose ] : dispose } = useInSetupWithUrqlClient (
23+ ( ) => useQuery < FooQuery > ( { query : FooDocument } ) ,
24+ client ,
25+ ) ;
26+ return { query, [ Symbol . dispose ] : ( ) => dispose ( ) } ;
6627}
6728
6829describe ( "one" , ( ) => {
0 commit comments