diff --git a/src/variables.ts b/src/variables.ts index 157ab214..030685d0 100644 --- a/src/variables.ts +++ b/src/variables.ts @@ -42,24 +42,22 @@ type unwrapTypeRec< : null | _getScalarType : unknown; -type _unwrapTypeRefRec = Type extends { - kind: Kind.NON_NULL_TYPE; - type: any; -} - ? _unwrapTypeRefRec +type unwrapTypeRefRec< + Type, + Introspection extends IntrospectionLikeType, + IsOptional, +> = Type extends { kind: Kind.NON_NULL_TYPE; type: any } + ? unwrapTypeRefRec : Type extends { kind: Kind.LIST_TYPE; type: any } - ? Array> + ? IsOptional extends false + ? Array> + : null | Array> : Type extends { kind: Kind.NAMED_TYPE; name: any } - ? _getScalarType + ? IsOptional extends false + ? _getScalarType + : null | _getScalarType : unknown; -type unwrapTypeRef = Type extends { - kind: Kind.NON_NULL_TYPE; - type: any; -} - ? _unwrapTypeRefRec - : null | _unwrapTypeRefRec; - type _getVariablesRec< Variables, Introspection extends IntrospectionLikeType, @@ -71,15 +69,17 @@ type _getVariablesRec< (Variable extends { kind: Kind.VARIABLE_DEFINITION; variable: any; type: any } ? Variable extends { defaultValue: undefined; type: { kind: Kind.NON_NULL_TYPE } } ? { - [Name in Variable['variable']['name']['value']]: unwrapTypeRef< + [Name in Variable['variable']['name']['value']]: unwrapTypeRefRec< Variable['type'], - Introspection + Introspection, + true >; } : { - [Name in Variable['variable']['name']['value']]?: unwrapTypeRef< + [Name in Variable['variable']['name']['value']]?: unwrapTypeRefRec< Variable['type'], - Introspection + Introspection, + true >; } : {}) &