@@ -2,9 +2,13 @@ import { test, describe, expect } from "vitest";
2
2
import { assert , Equals } from "../test/type_testing.js" ;
3
3
import { v } from "../values/validator.js" ;
4
4
import {
5
+ ActionBuilder ,
5
6
ApiFromModules ,
6
7
DefaultFunctionArgs ,
8
+ QueryBuilder ,
9
+ actionGeneric ,
7
10
mutationGeneric ,
11
+ queryGeneric ,
8
12
} from "./index.js" ;
9
13
import { EmptyObject , MutationBuilder } from "./registration.js" ;
10
14
@@ -276,8 +280,10 @@ describe("argument inference", () => {
276
280
} ) ;
277
281
278
282
describe ( "argument and return value validators can be objects or validators" , ( ) => {
279
- // Test with mutation, but all the wrappers work the same way.
283
+ // Test with mutation, we aim for all the wrappers work the same way.
280
284
const mutation : MutationBuilder < any , "public" > = mutationGeneric ;
285
+ const query : QueryBuilder < any , "public" > = queryGeneric ;
286
+ const action : ActionBuilder < any , "public" > = actionGeneric ;
281
287
282
288
const module = {
283
289
configArgsObject : mutation ( {
@@ -314,6 +320,27 @@ describe("argument and return value validators can be objects or validators", ()
314
320
return { arg : "result" } ;
315
321
} ,
316
322
} ) ,
323
+
324
+ // test queries and actions just a bit too
325
+ q1 : query ( {
326
+ args : v . object ( {
327
+ arg : v . string ( ) ,
328
+ } ) ,
329
+ returns : { arg : v . string ( ) } ,
330
+ handler : ( _ , { arg } ) => {
331
+ return { arg : arg } ;
332
+ } ,
333
+ } ) ,
334
+
335
+ a1 : action ( {
336
+ args : v . object ( {
337
+ arg : v . string ( ) ,
338
+ } ) ,
339
+ returns : { arg : v . string ( ) } ,
340
+ handler : ( _ , { arg } ) => {
341
+ return { arg : arg } ;
342
+ } ,
343
+ } ) ,
317
344
} ;
318
345
type API = ApiFromModules < { module : typeof module } > ;
319
346
@@ -372,4 +399,20 @@ describe("argument and return value validators can be objects or validators", ()
372
399
const returnString = module . configOutputValidator . exportReturns ( ) ;
373
400
expect ( JSON . parse ( returnString ) ) . toEqual ( expectedReturnsExport ) ;
374
401
} ) ;
402
+
403
+ test ( "queries" , ( ) => {
404
+ type ReturnType = API [ "module" ] [ "q1" ] [ "_returnType" ] ;
405
+ type Expected = { arg : string } ;
406
+ assert < Equals < ReturnType , Expected > > ;
407
+ const returnString = module . configOutputValidator . exportReturns ( ) ;
408
+ expect ( JSON . parse ( returnString ) ) . toEqual ( expectedReturnsExport ) ;
409
+ } ) ;
410
+
411
+ test ( "actions" , ( ) => {
412
+ type ReturnType = API [ "module" ] [ "configOutputValidator" ] [ "_returnType" ] ;
413
+ type Expected = { arg : string } ;
414
+ assert < Equals < ReturnType , Expected > > ;
415
+ const returnString = module . configOutputValidator . exportReturns ( ) ;
416
+ expect ( JSON . parse ( returnString ) ) . toEqual ( expectedReturnsExport ) ;
417
+ } ) ;
375
418
} ) ;
0 commit comments