@@ -105,7 +105,7 @@ export type FilterNever<T extends Record<string, unknown>> = NonNeverKeys<T> ext
105105 * >; // { apple: "red" }
106106 * ```
107107 */
108- type InnerSelect < Schema , Selection extends FieldSelection | null | undefined > = IfAny <
108+ type InnerSelect < Schema , Selection extends FieldSelection | FieldSelectionWithArgs | null | undefined > = IfAny <
109109 Selection ,
110110 never ,
111111 Selection extends null | undefined
@@ -115,10 +115,12 @@ type InnerSelect<Schema, Selection extends FieldSelection | null | undefined> =
115115 : Schema extends null
116116 ? InnerSelect < Exclude < Schema , null > , Selection > | null
117117 : {
118- [ Key in keyof Selection & keyof Schema ] : Selection [ Key ] extends true
118+ [ Key in Exclude < keyof Selection , typeof $args > & keyof Schema ] : Selection [ Key ] extends true
119119 ? Schema [ Key ]
120- : Selection [ Key ] extends FieldSelection
121- ? InnerSelect < Schema [ Key ] , Selection [ Key ] >
120+ : Selection [ Key ] extends FieldSelection | FieldSelectionWithArgs
121+ ? Exclude < keyof Selection [ Key ] , typeof $args > extends never
122+ ? Schema [ Key ]
123+ : InnerSelect < Schema [ Key ] , Selection [ Key ] >
122124 : never ;
123125 }
124126> ;
@@ -148,7 +150,9 @@ export type DeepFilterNever<T> = T extends Record<string, unknown>
148150 * >; // { apple: "red" }
149151 * ```
150152 */
151- export type Select < Schema , Selection extends FieldSelection | null | undefined > = DeepFilterNever < InnerSelect < Schema , Selection > > ;
153+ export type Select < Schema , Selection extends FieldSelection | FieldSelectionWithArgs | null | undefined > = DeepFilterNever <
154+ InnerSelect < Schema , Selection >
155+ > ;
152156
153157/** Represents an amount of some currency. Specified as a string so user's aren't tempted to do math on the value. */
154158export type CurrencyAmount = string ;
@@ -1004,10 +1008,22 @@ export type ViewResult<F extends ViewFunction<any, any>> = Awaited<
10041008 F extends ViewFunctionWithVariables < any , infer Result > ? Result : F extends ViewFunctionWithoutVariables < infer Result > ? Result : never
10051009> ;
10061010
1011+ /** Symbol key for field arguments in selections */
1012+ export const $args : unique symbol = Symbol . for ( "gadget/fieldArgs" ) ;
1013+
1014+ /** Field arguments (e.g., pagination, filtering) */
1015+ export type FieldArgs = Record < string , any > ;
1016+
10071017/**
10081018 * Represents a list of fields selected from a GraphQL API call. Allows nesting, conditional selection.
10091019 * Example: `{ id: true, name: false, richText: { markdown: true, html: false } }`
10101020 **/
10111021export interface FieldSelection {
10121022 [ key : string ] : boolean | null | undefined | FieldSelection ;
10131023}
1024+
1025+ /** A field selection that includes field arguments via the $args symbol key */
1026+ export type FieldSelectionWithArgs = {
1027+ [ $args ] : FieldArgs ;
1028+ [ key : string ] : boolean | null | undefined | FieldSelection | FieldSelectionWithArgs ;
1029+ } ;
0 commit comments