From 30d8d5b819c9dbf735d8dfcfa9505fa329fa77f1 Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Mon, 4 Mar 2024 10:01:04 +0000 Subject: [PATCH] Merge _unwrapTypeRefRec and unwrapTypeRef in variables.ts --- src/variables.ts | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) 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 >; } : {}) &