@@ -2,9 +2,13 @@ import { test, describe, expect } from "vitest";
22import { assert , Equals } from "../test/type_testing.js" ;
33import { v } from "../values/validator.js" ;
44import {
5+ ActionBuilder ,
56 ApiFromModules ,
67 DefaultFunctionArgs ,
8+ QueryBuilder ,
9+ actionGeneric ,
710 mutationGeneric ,
11+ queryGeneric ,
812} from "./index.js" ;
913import { EmptyObject , MutationBuilder } from "./registration.js" ;
1014
@@ -276,8 +280,10 @@ describe("argument inference", () => {
276280} ) ;
277281
278282describe ( "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.
280284 const mutation : MutationBuilder < any , "public" > = mutationGeneric ;
285+ const query : QueryBuilder < any , "public" > = queryGeneric ;
286+ const action : ActionBuilder < any , "public" > = actionGeneric ;
281287
282288 const module = {
283289 configArgsObject : mutation ( {
@@ -314,6 +320,27 @@ describe("argument and return value validators can be objects or validators", ()
314320 return { arg : "result" } ;
315321 } ,
316322 } ) ,
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+ } ) ,
317344 } ;
318345 type API = ApiFromModules < { module : typeof module } > ;
319346
@@ -372,4 +399,20 @@ describe("argument and return value validators can be objects or validators", ()
372399 const returnString = module . configOutputValidator . exportReturns ( ) ;
373400 expect ( JSON . parse ( returnString ) ) . toEqual ( expectedReturnsExport ) ;
374401 } ) ;
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+ } ) ;
375418} ) ;
0 commit comments