@@ -6,14 +6,19 @@ import type { obj } from './utils';
6
6
type getInputObjectTypeRec <
7
7
InputFields ,
8
8
Introspection extends IntrospectionLikeType ,
9
+ InputObject = { } ,
9
10
> = InputFields extends [ infer InputField , ...infer Rest ]
10
- ? ( InputField extends { name : any ; type : any }
11
- ? InputField [ 'type' ] extends { kind : 'NON_NULL' }
12
- ? { [ Name in InputField [ 'name' ] ] : unwrapType < InputField [ 'type' ] , Introspection > }
13
- : { [ Name in InputField [ 'name' ] ] ?: unwrapType < InputField [ 'type' ] , Introspection > }
14
- : { } ) &
15
- getInputObjectTypeRec < Rest , Introspection >
16
- : { } ;
11
+ ? getInputObjectTypeRec <
12
+ Rest ,
13
+ Introspection ,
14
+ ( InputField extends { name : any ; type : any }
15
+ ? InputField [ 'type' ] extends { kind : 'NON_NULL' }
16
+ ? { [ Name in InputField [ 'name' ] ] : unwrapType < InputField [ 'type' ] , Introspection > }
17
+ : { [ Name in InputField [ 'name' ] ] ?: unwrapType < InputField [ 'type' ] , Introspection > }
18
+ : { } ) &
19
+ InputObject
20
+ >
21
+ : InputObject ;
17
22
18
23
type getScalarType <
19
24
TypeName ,
@@ -62,27 +67,32 @@ type unwrapTypeRef<Type, Introspection extends IntrospectionLikeType> = Type ext
62
67
? _unwrapTypeRefRec < Type [ 'type' ] , Introspection >
63
68
: null | _unwrapTypeRefRec < Type , Introspection > ;
64
69
65
- type getVariablesRec < Variables , Introspection extends IntrospectionLikeType > = Variables extends [
66
- infer Variable ,
67
- ...infer Rest ,
68
- ]
69
- ? ( Variable extends { kind : Kind . VARIABLE_DEFINITION ; variable : any ; type : any }
70
- ? Variable extends { defaultValue : undefined ; type : { kind : Kind . NON_NULL_TYPE } }
71
- ? {
72
- [ Name in Variable [ 'variable' ] [ 'name' ] [ 'value' ] ] : unwrapTypeRef <
73
- Variable [ 'type' ] ,
74
- Introspection
75
- > ;
76
- }
77
- : {
78
- [ Name in Variable [ 'variable' ] [ 'name' ] [ 'value' ] ] ?: unwrapTypeRef <
79
- Variable [ 'type' ] ,
80
- Introspection
81
- > ;
82
- }
83
- : { } ) &
84
- getVariablesRec < Rest , Introspection >
85
- : { } ;
70
+ type _getVariablesRec <
71
+ Variables ,
72
+ Introspection extends IntrospectionLikeType ,
73
+ VariablesObject = { } ,
74
+ > = Variables extends [ infer Variable , ...infer Rest ]
75
+ ? _getVariablesRec <
76
+ Rest ,
77
+ Introspection ,
78
+ ( Variable extends { kind : Kind . VARIABLE_DEFINITION ; variable : any ; type : any }
79
+ ? Variable extends { defaultValue : undefined ; type : { kind : Kind . NON_NULL_TYPE } }
80
+ ? {
81
+ [ Name in Variable [ 'variable' ] [ 'name' ] [ 'value' ] ] : unwrapTypeRef <
82
+ Variable [ 'type' ] ,
83
+ Introspection
84
+ > ;
85
+ }
86
+ : {
87
+ [ Name in Variable [ 'variable' ] [ 'name' ] [ 'value' ] ] ?: unwrapTypeRef <
88
+ Variable [ 'type' ] ,
89
+ Introspection
90
+ > ;
91
+ }
92
+ : { } ) &
93
+ VariablesObject
94
+ >
95
+ : VariablesObject ;
86
96
87
97
type getVariablesType <
88
98
Document extends DocumentNodeLike ,
@@ -91,7 +101,7 @@ type getVariablesType<
91
101
kind : Kind . OPERATION_DEFINITION ;
92
102
variableDefinitions : any ;
93
103
}
94
- ? obj < getVariablesRec < Document [ 'definitions' ] [ 0 ] [ 'variableDefinitions' ] , Introspection > >
104
+ ? obj < _getVariablesRec < Document [ 'definitions' ] [ 0 ] [ 'variableDefinitions' ] , Introspection > >
95
105
: { } ;
96
106
97
107
export type { getVariablesType } ;
0 commit comments