@@ -326,42 +326,37 @@ export class GraphQLAstExplorer {
326
326
name : string ;
327
327
required : boolean ;
328
328
} {
329
- const { required, type } = this . getNestedType ( typeNode ) ;
330
-
331
- const isArray = type . kind === 'ListType' ;
332
- if ( isArray ) {
333
- const { type : arrayType , required : arrayTypeRequired } =
334
- this . getNestedType ( get ( type , 'type' ) ) ;
335
-
336
- const typeName = this . addSymbolIfRoot ( get ( arrayType , 'name.value' ) ) ;
337
- const name = arrayTypeRequired
329
+ const stringifyType = ( typeNode : TypeNode ) => {
330
+ const { type, required } = this . unwrapTypeIfNonNull ( typeNode ) ;
331
+ const isArray = type . kind === 'ListType' ;
332
+
333
+ if ( isArray ) {
334
+ const arrayType = get ( type , 'type' ) ;
335
+ return required
336
+ ? `${ stringifyType ( arrayType ) } []`
337
+ : `Nullable<${ stringifyType ( arrayType ) } []>` ;
338
+ }
339
+ const typeName = this . addSymbolIfRoot ( get ( type , 'name.value' ) ) ;
340
+ return required
338
341
? this . getType ( typeName , options )
339
342
: `Nullable<${ this . getType ( typeName , options ) } >` ;
343
+ } ;
340
344
341
- return {
342
- name : required ? name + '[]' : `Nullable<${ name } []>` ,
343
- required,
344
- } ;
345
- }
346
-
347
- const typeName = this . addSymbolIfRoot ( get ( type , 'name.value' ) ) ;
348
-
345
+ const { required } = this . unwrapTypeIfNonNull ( typeNode ) ;
349
346
return {
350
- name : required
351
- ? this . getType ( typeName , options )
352
- : `Nullable<${ this . getType ( typeName , options ) } >` ,
347
+ name : stringifyType ( typeNode ) ,
353
348
required,
354
349
} ;
355
350
}
356
351
357
- getNestedType ( type : TypeNode ) : {
352
+ unwrapTypeIfNonNull ( type : TypeNode ) : {
358
353
type : TypeNode ;
359
354
required : boolean ;
360
355
} {
361
356
const isNonNullType = type . kind === 'NonNullType' ;
362
357
if ( isNonNullType ) {
363
358
return {
364
- type : this . getNestedType ( get ( type , 'type' ) ) . type ,
359
+ type : this . unwrapTypeIfNonNull ( get ( type , 'type' ) ) . type ,
365
360
required : isNonNullType ,
366
361
} ;
367
362
}
0 commit comments