@@ -10,7 +10,6 @@ import { Kind } from '../../language/kinds';
10
10
import { parse } from '../../language/parser' ;
11
11
import { print } from '../../language/printer' ;
12
12
13
- import type { GraphQLNamedType } from '../../type/definition' ;
14
13
import { GraphQLSchema } from '../../type/schema' ;
15
14
import { validateSchema } from '../../type/validate' ;
16
15
import { __Schema , __EnumValue } from '../../type/introspection' ;
@@ -51,18 +50,16 @@ function cycleSDL(sdl: string): string {
51
50
return printSchema ( buildSchema ( sdl ) ) ;
52
51
}
53
52
54
- function printASTNode ( obj : ?{ + astNode : ?ASTNode , ... } ) : string {
55
- // istanbul ignore next (FIXME)
53
+ function expectASTNode ( obj : ?{ + astNode : ?ASTNode , ... } ) {
56
54
invariant ( obj ?. astNode != null ) ;
57
- return print ( obj . astNode ) ;
55
+ return expect ( print ( obj . astNode ) ) ;
58
56
}
59
57
60
- function printAllASTNodes ( obj : GraphQLNamedType ) : string {
61
- invariant ( obj . astNode != null ) ;
62
- return print ( {
63
- kind : Kind . DOCUMENT ,
64
- definitions : [ obj . astNode , ...obj . extensionASTNodes ] ,
65
- } ) ;
58
+ function expectExtensionASTNodes ( obj : {
59
+ + extensionASTNodes : $ReadOnlyArray < ASTNode > ,
60
+ ...
61
+ } ) {
62
+ return expect ( obj . extensionASTNodes . map ( print ) . join ( '\n\n' ) ) ;
66
63
}
67
64
68
65
describe ( 'Schema Builder' , ( ) => {
@@ -714,15 +711,11 @@ describe('Schema Builder', () => {
714
711
} ) ;
715
712
716
713
it ( 'Correctly extend scalar type' , ( ) => {
717
- const scalarSDL = dedent `
714
+ const schema = buildSchema ( `
718
715
scalar SomeScalar
719
-
720
716
extend scalar SomeScalar @foo
721
-
722
717
extend scalar SomeScalar @bar
723
- ` ;
724
- const schema = buildSchema ( `
725
- ${ scalarSDL }
718
+
726
719
directive @foo on SCALAR
727
720
directive @bar on SCALAR
728
721
` ) ;
@@ -732,11 +725,16 @@ describe('Schema Builder', () => {
732
725
scalar SomeScalar
733
726
` ) ;
734
727
735
- expect ( printAllASTNodes ( someScalar ) ) . to . equal ( scalarSDL ) ;
728
+ expectASTNode ( someScalar ) . to . equal ( 'scalar SomeScalar' ) ;
729
+ expectExtensionASTNodes ( someScalar ) . to . equal ( dedent `
730
+ extend scalar SomeScalar @foo
731
+
732
+ extend scalar SomeScalar @bar
733
+ ` ) ;
736
734
} ) ;
737
735
738
736
it ( 'Correctly extend object type' , ( ) => {
739
- const objectSDL = dedent `
737
+ const schema = buildSchema ( `
740
738
type SomeObject implements Foo {
741
739
first: String
742
740
}
@@ -748,9 +746,7 @@ describe('Schema Builder', () => {
748
746
extend type SomeObject implements Baz {
749
747
third: Float
750
748
}
751
- ` ;
752
- const schema = buildSchema ( `
753
- ${ objectSDL }
749
+
754
750
interface Foo
755
751
interface Bar
756
752
interface Baz
@@ -765,11 +761,24 @@ describe('Schema Builder', () => {
765
761
}
766
762
` ) ;
767
763
768
- expect ( printAllASTNodes ( someObject ) ) . to . equal ( objectSDL ) ;
764
+ expectASTNode ( someObject ) . to . equal ( dedent `
765
+ type SomeObject implements Foo {
766
+ first: String
767
+ }
768
+ ` ) ;
769
+ expectExtensionASTNodes ( someObject ) . to . equal ( dedent `
770
+ extend type SomeObject implements Bar {
771
+ second: Int
772
+ }
773
+
774
+ extend type SomeObject implements Baz {
775
+ third: Float
776
+ }
777
+ ` ) ;
769
778
} ) ;
770
779
771
780
it ( 'Correctly extend interface type' , ( ) => {
772
- const interfaceSDL = dedent `
781
+ const schema = buildSchema ( dedent `
773
782
interface SomeInterface {
774
783
first: String
775
784
}
@@ -781,8 +790,7 @@ describe('Schema Builder', () => {
781
790
extend interface SomeInterface {
782
791
third: Float
783
792
}
784
- ` ;
785
- const schema = buildSchema ( interfaceSDL ) ;
793
+ ` ) ;
786
794
787
795
const someInterface = assertInterfaceType ( schema . getType ( 'SomeInterface' ) ) ;
788
796
expect ( printType ( someInterface ) ) . to . equal ( dedent `
@@ -793,19 +801,28 @@ describe('Schema Builder', () => {
793
801
}
794
802
` ) ;
795
803
796
- expect ( printAllASTNodes ( someInterface ) ) . to . equal ( interfaceSDL ) ;
804
+ expectASTNode ( someInterface ) . to . equal ( dedent `
805
+ interface SomeInterface {
806
+ first: String
807
+ }
808
+ ` ) ;
809
+ expectExtensionASTNodes ( someInterface ) . to . equal ( dedent `
810
+ extend interface SomeInterface {
811
+ second: Int
812
+ }
813
+
814
+ extend interface SomeInterface {
815
+ third: Float
816
+ }
817
+ ` ) ;
797
818
} ) ;
798
819
799
820
it ( 'Correctly extend union type' , ( ) => {
800
- const unionSDL = dedent `
821
+ const schema = buildSchema ( `
801
822
union SomeUnion = FirstType
802
-
803
823
extend union SomeUnion = SecondType
804
-
805
824
extend union SomeUnion = ThirdType
806
- ` ;
807
- const schema = buildSchema ( `
808
- ${ unionSDL }
825
+
809
826
type FirstType
810
827
type SecondType
811
828
type ThirdType
@@ -816,11 +833,16 @@ describe('Schema Builder', () => {
816
833
union SomeUnion = FirstType | SecondType | ThirdType
817
834
` ) ;
818
835
819
- expect ( printAllASTNodes ( someUnion ) ) . to . equal ( unionSDL ) ;
836
+ expectASTNode ( someUnion ) . to . equal ( 'union SomeUnion = FirstType' ) ;
837
+ expectExtensionASTNodes ( someUnion ) . to . equal ( dedent `
838
+ extend union SomeUnion = SecondType
839
+
840
+ extend union SomeUnion = ThirdType
841
+ ` ) ;
820
842
} ) ;
821
843
822
844
it ( 'Correctly extend enum type' , ( ) => {
823
- const enumSDL = dedent `
845
+ const schema = buildSchema ( dedent `
824
846
enum SomeEnum {
825
847
FIRST
826
848
}
@@ -832,8 +854,7 @@ describe('Schema Builder', () => {
832
854
extend enum SomeEnum {
833
855
THIRD
834
856
}
835
- ` ;
836
- const schema = buildSchema ( enumSDL ) ;
857
+ ` ) ;
837
858
838
859
const someEnum = assertEnumType ( schema . getType ( 'SomeEnum' ) ) ;
839
860
expect ( printType ( someEnum ) ) . to . equal ( dedent `
@@ -844,11 +865,24 @@ describe('Schema Builder', () => {
844
865
}
845
866
` ) ;
846
867
847
- expect ( printAllASTNodes ( someEnum ) ) . to . equal ( enumSDL ) ;
868
+ expectASTNode ( someEnum ) . to . equal ( dedent `
869
+ enum SomeEnum {
870
+ FIRST
871
+ }
872
+ ` ) ;
873
+ expectExtensionASTNodes ( someEnum ) . to . equal ( dedent `
874
+ extend enum SomeEnum {
875
+ SECOND
876
+ }
877
+
878
+ extend enum SomeEnum {
879
+ THIRD
880
+ }
881
+ ` ) ;
848
882
} ) ;
849
883
850
884
it ( 'Correctly extend input object type' , ( ) => {
851
- const inputSDL = dedent `
885
+ const schema = buildSchema ( dedent `
852
886
input SomeInput {
853
887
first: String
854
888
}
@@ -860,8 +894,7 @@ describe('Schema Builder', () => {
860
894
extend input SomeInput {
861
895
third: Float
862
896
}
863
- ` ;
864
- const schema = buildSchema ( inputSDL ) ;
897
+ ` ) ;
865
898
866
899
const someInput = assertInputObjectType ( schema . getType ( 'SomeInput' ) ) ;
867
900
expect ( printType ( someInput ) ) . to . equal ( dedent `
@@ -872,7 +905,20 @@ describe('Schema Builder', () => {
872
905
}
873
906
` ) ;
874
907
875
- expect ( printAllASTNodes ( someInput ) ) . to . equal ( inputSDL ) ;
908
+ expectASTNode ( someInput ) . to . equal ( dedent `
909
+ input SomeInput {
910
+ first: String
911
+ }
912
+ ` ) ;
913
+ expectExtensionASTNodes ( someInput ) . to . equal ( dedent `
914
+ extend input SomeInput {
915
+ second: Int
916
+ }
917
+
918
+ extend input SomeInput {
919
+ third: Float
920
+ }
921
+ ` ) ;
876
922
} ) ;
877
923
878
924
it ( 'Correctly assign AST nodes' , ( ) => {
@@ -932,25 +978,23 @@ describe('Schema Builder', () => {
932
978
] ) . to . be . deep . equal ( ast . definitions ) ;
933
979
934
980
const testField = query . getFields ( ) . testField ;
935
- expect ( printASTNode ( testField ) ) . to . equal (
981
+ expectASTNode ( testField ) . to . equal (
936
982
'testField(testArg: TestInput): TestUnion' ,
937
983
) ;
938
- expect ( printASTNode ( testField . args [ 0 ] ) ) . to . equal ( 'testArg: TestInput' ) ;
939
- expect ( printASTNode ( testInput . getFields ( ) . testInputField ) ) . to . equal (
984
+ expectASTNode ( testField . args [ 0 ] ) . to . equal ( 'testArg: TestInput' ) ;
985
+ expectASTNode ( testInput . getFields ( ) . testInputField ) . to . equal (
940
986
'testInputField: TestEnum' ,
941
987
) ;
942
988
943
- expect ( printASTNode ( testEnum . getValue ( 'TEST_VALUE' ) ) ) . to . equal (
944
- 'TEST_VALUE' ,
945
- ) ;
989
+ expectASTNode ( testEnum . getValue ( 'TEST_VALUE' ) ) . to . equal ( 'TEST_VALUE' ) ;
946
990
947
- expect ( printASTNode ( testInterface . getFields ( ) . interfaceField ) ) . to . equal (
991
+ expectASTNode ( testInterface . getFields ( ) . interfaceField ) . to . equal (
948
992
'interfaceField: String' ,
949
993
) ;
950
- expect ( printASTNode ( testType . getFields ( ) . interfaceField ) ) . to . equal (
994
+ expectASTNode ( testType . getFields ( ) . interfaceField ) . to . equal (
951
995
'interfaceField: String' ,
952
996
) ;
953
- expect ( printASTNode ( testDirective . args [ 0 ] ) ) . to . equal ( 'arg: TestScalar' ) ;
997
+ expectASTNode ( testDirective . args [ 0 ] ) . to . equal ( 'arg: TestScalar' ) ;
954
998
} ) ;
955
999
956
1000
it ( 'Root operation types with custom names' , ( ) => {
0 commit comments