@@ -384,18 +384,196 @@ describe('getTypeInfos', () => {
384
384
` ) ;
385
385
} ) ;
386
386
} ) ;
387
+ describe ( 'namingConvention' , ( ) => {
388
+ it ( 'renames type by namingConvention' , ( ) => {
389
+ const schema = buildSchema ( `
390
+ type Type {
391
+ field1: String!
392
+ field2: SubType!
393
+ }
394
+ type SubType {
395
+ field: String!
396
+ }
397
+ ` ) ;
398
+ const config : Config = fakeConfig ( {
399
+ convert : convertFactory ( { namingConvention : 'change-case-all#lowerCase' } ) ,
400
+ } ) ;
401
+ expect ( getTypeInfos ( config , schema ) [ 0 ] ) . toMatchInlineSnapshot ( `
402
+ {
403
+ "comment": undefined,
404
+ "fields": [
405
+ {
406
+ "comment": undefined,
407
+ "name": "field1",
408
+ "typeString": "type['field1'] | undefined",
409
+ },
410
+ {
411
+ "comment": undefined,
412
+ "name": "field2",
413
+ "typeString": "Optionalsubtype | undefined",
414
+ },
415
+ ],
416
+ "name": "type",
417
+ }
418
+ ` ) ;
419
+ } ) ;
420
+ // FIXME
421
+ it ( 'does not effect to __typename and __is<AbstractType>' , ( ) => {
422
+ const schema = buildSchema ( `
423
+ type Type {
424
+ field: String!
425
+ }
426
+ union Union = Type
427
+ ` ) ;
428
+ const config : Config = fakeConfig ( {
429
+ skipTypename : false ,
430
+ skipIsAbstractType : false ,
431
+ convert : convertFactory ( { namingConvention : 'change-case-all#lowerCase' } ) ,
432
+ } ) ;
433
+ expect ( getTypeInfos ( config , schema ) [ 0 ] ?. fields ) . toMatchInlineSnapshot ( `
434
+ [
435
+ {
436
+ "name": "__typename",
437
+ "typeString": "'type'",
438
+ },
439
+ {
440
+ "name": "__isUnion",
441
+ "typeString": "'type'",
442
+ },
443
+ {
444
+ "comment": undefined,
445
+ "name": "field",
446
+ "typeString": "type['field'] | undefined",
447
+ },
448
+ ]
449
+ ` ) ;
450
+ } ) ;
451
+ } ) ;
452
+ describe ( 'typesPrefix' , ( ) => {
453
+ it ( 'renames type by typesPrefix' , ( ) => {
454
+ const schema = buildSchema ( `
455
+ type Type {
456
+ field1: String!
457
+ field2: SubType!
458
+ }
459
+ type SubType {
460
+ field: String!
461
+ }
462
+ ` ) ;
463
+ const config : Config = fakeConfig ( { typesPrefix : 'I' } ) ;
464
+ expect ( getTypeInfos ( config , schema ) [ 0 ] ) . toMatchInlineSnapshot ( `
465
+ {
466
+ "comment": undefined,
467
+ "fields": [
468
+ {
469
+ "comment": undefined,
470
+ "name": "field1",
471
+ "typeString": "IType['field1'] | undefined",
472
+ },
473
+ {
474
+ "comment": undefined,
475
+ "name": "field2",
476
+ "typeString": "OptionalISubType | undefined",
477
+ },
478
+ ],
479
+ "name": "IType",
480
+ }
481
+ ` ) ;
482
+ } ) ;
483
+ // FIXME
484
+ it ( 'does not effect to __typename and __is<AbstractType>' , ( ) => {
485
+ const schema = buildSchema ( `
486
+ type Type {
487
+ field: String!
488
+ }
489
+ union Union = Type
490
+ ` ) ;
491
+ const config : Config = fakeConfig ( {
492
+ skipTypename : false ,
493
+ skipIsAbstractType : false ,
494
+ typesPrefix : 'I' ,
495
+ } ) ;
496
+ expect ( getTypeInfos ( config , schema ) [ 0 ] ?. fields ) . toMatchInlineSnapshot ( `
497
+ [
498
+ {
499
+ "name": "__typename",
500
+ "typeString": "'IType'",
501
+ },
502
+ {
503
+ "name": "__isUnion",
504
+ "typeString": "'IType'",
505
+ },
506
+ {
507
+ "comment": undefined,
508
+ "name": "field",
509
+ "typeString": "IType['field'] | undefined",
510
+ },
511
+ ]
512
+ ` ) ;
513
+ } ) ;
514
+ } ) ;
515
+ describe ( 'typesSuffix' , ( ) => {
516
+ it ( 'renames type by typesSuffix' , ( ) => {
517
+ const schema = buildSchema ( `
518
+ type Type {
519
+ field1: String!
520
+ field2: SubType!
521
+ }
522
+ type SubType {
523
+ field: String!
524
+ }
525
+ ` ) ;
526
+ const config : Config = fakeConfig ( { typesSuffix : 'I' } ) ;
527
+ expect ( getTypeInfos ( config , schema ) [ 0 ] ) . toMatchInlineSnapshot ( `
528
+ {
529
+ "comment": undefined,
530
+ "fields": [
531
+ {
532
+ "comment": undefined,
533
+ "name": "field1",
534
+ "typeString": "TypeI['field1'] | undefined",
535
+ },
536
+ {
537
+ "comment": undefined,
538
+ "name": "field2",
539
+ "typeString": "OptionalSubTypeI | undefined",
540
+ },
541
+ ],
542
+ "name": "TypeI",
543
+ }
544
+ ` ) ;
545
+ } ) ;
546
+ // FIXME
547
+ it ( 'does not effect to __typename and __is<AbstractType>' , ( ) => {
548
+ const schema = buildSchema ( `
549
+ type Type {
550
+ field: String!
551
+ }
552
+ union Union = Type
553
+ ` ) ;
554
+ const config : Config = fakeConfig ( {
555
+ skipTypename : false ,
556
+ skipIsAbstractType : false ,
557
+ typesSuffix : 'I' ,
558
+ } ) ;
559
+ expect ( getTypeInfos ( config , schema ) [ 0 ] ?. fields ) . toMatchInlineSnapshot ( `
560
+ [
561
+ {
562
+ "name": "__typename",
563
+ "typeString": "'TypeI'",
564
+ },
565
+ {
566
+ "name": "__isUnion",
567
+ "typeString": "'TypeI'",
568
+ },
569
+ {
570
+ "comment": undefined,
571
+ "name": "field",
572
+ "typeString": "TypeI['field'] | undefined",
573
+ },
574
+ ]
575
+ ` ) ;
576
+ } ) ;
577
+ } ) ;
387
578
} ) ;
388
- // it('renames type by namingConvention', () => {
389
- // const schema = buildSchema(`
390
- // type Type {
391
- // field1: String!
392
- // field2: SubType!
393
- // }
394
- // type SubType {
395
- // field: String!
396
- // }
397
- // `);
398
- // const config: Config = fakeConfig({ convert: convertFactory({ namingConvention: 'change-case-all#lowerCase' }) });
399
- // expect(getTypeInfos(config, schema)[0]).toMatchInlineSnapshot();
400
- // });
401
579
} ) ;
0 commit comments