@@ -582,6 +582,101 @@ describe("Directives", () => {
582
582
} ) ;
583
583
} ) ;
584
584
585
+ describe ( "multiline and leading white spaces" , ( ) => {
586
+ let schema : GraphQLSchema ;
587
+ beforeAll ( async ( ) => {
588
+ @Resolver ( )
589
+ class SampleResolver {
590
+ @Directive ( "\n@test" )
591
+ @Query ( )
592
+ multiline ( ) : boolean {
593
+ return true ;
594
+ }
595
+
596
+ @Directive ( " @test" )
597
+ @Query ( )
598
+ leadingWhiteSpaces ( ) : boolean {
599
+ return true ;
600
+ }
601
+
602
+ @Directive ( "\n @test" )
603
+ @Query ( )
604
+ multilineAndLeadingWhiteSpaces ( ) : boolean {
605
+ return true ;
606
+ }
607
+
608
+ @Directive ( `
609
+ @test(
610
+ argNonNullDefault: "argNonNullDefault",
611
+ argNullDefault: "argNullDefault",
612
+ argNull: "argNull"
613
+ )
614
+ ` )
615
+ @Query ( )
616
+ rawMultilineAndLeadingWhiteSpaces ( ) : boolean {
617
+ return true ;
618
+ }
619
+ }
620
+
621
+ schema = await buildSchema ( {
622
+ resolvers : [ SampleResolver ] ,
623
+ directives : [ testDirective ] ,
624
+ validate : false ,
625
+ } ) ;
626
+ schema = testDirectiveTransformer ( schema ) ;
627
+ } ) ;
628
+
629
+ it ( "should properly emit directive in AST" , ( ) => {
630
+ const multilineInfo = schema . getRootType ( OperationTypeNode . QUERY ) ! . getFields ( ) . multiline ;
631
+ const leadingWhiteSpacesInfo = schema
632
+ . getRootType ( OperationTypeNode . QUERY ) !
633
+ . getFields ( ) . leadingWhiteSpaces ;
634
+ const multilineAndLeadingWhiteSpacesInfo = schema
635
+ . getRootType ( OperationTypeNode . QUERY ) !
636
+ . getFields ( ) . multilineAndLeadingWhiteSpaces ;
637
+ const rawMultilineAndLeadingWhiteSpacesInfo = schema
638
+ . getRootType ( OperationTypeNode . QUERY ) !
639
+ . getFields ( ) . rawMultilineAndLeadingWhiteSpaces ;
640
+
641
+ expect ( ( ) => {
642
+ assertValidDirective ( multilineInfo . astNode , "test" ) ;
643
+ assertValidDirective ( leadingWhiteSpacesInfo . astNode , "test" ) ;
644
+ assertValidDirective ( multilineAndLeadingWhiteSpacesInfo . astNode , "test" ) ;
645
+ assertValidDirective ( rawMultilineAndLeadingWhiteSpacesInfo . astNode , "test" , {
646
+ argNonNullDefault : `"argNonNullDefault"` ,
647
+ argNullDefault : `"argNullDefault"` ,
648
+ argNull : `"argNull"` ,
649
+ } ) ;
650
+ } ) . not . toThrow ( ) ;
651
+ } ) ;
652
+
653
+ it ( "should properly apply directive mapper" , async ( ) => {
654
+ const multilineInfo = schema . getRootType ( OperationTypeNode . QUERY ) ! . getFields ( ) . multiline ;
655
+ const leadingWhiteSpacesInfo = schema
656
+ . getRootType ( OperationTypeNode . QUERY ) !
657
+ . getFields ( ) . leadingWhiteSpaces ;
658
+ const multilineAndLeadingWhiteSpacesInfo = schema
659
+ . getRootType ( OperationTypeNode . QUERY ) !
660
+ . getFields ( ) . multilineAndLeadingWhiteSpaces ;
661
+ const rawMultilineAndLeadingWhiteSpacesInfo = schema
662
+ . getRootType ( OperationTypeNode . QUERY ) !
663
+ . getFields ( ) . rawMultilineAndLeadingWhiteSpaces ;
664
+
665
+ expect ( multilineInfo . extensions ) . toMatchObject ( {
666
+ TypeGraphQL : { isMappedByDirective : true } ,
667
+ } ) ;
668
+ expect ( leadingWhiteSpacesInfo . extensions ) . toMatchObject ( {
669
+ TypeGraphQL : { isMappedByDirective : true } ,
670
+ } ) ;
671
+ expect ( multilineAndLeadingWhiteSpacesInfo . extensions ) . toMatchObject ( {
672
+ TypeGraphQL : { isMappedByDirective : true } ,
673
+ } ) ;
674
+ expect ( rawMultilineAndLeadingWhiteSpacesInfo . extensions ) . toMatchObject ( {
675
+ TypeGraphQL : { isMappedByDirective : true } ,
676
+ } ) ;
677
+ } ) ;
678
+ } ) ;
679
+
585
680
describe ( "errors" , ( ) => {
586
681
beforeEach ( async ( ) => {
587
682
getMetadataStorage ( ) . clear ( ) ;
0 commit comments