@@ -12,20 +12,25 @@ import { expect } from 'chai';
12
12
13
13
import {
14
14
GraphQLScalarType ,
15
+ GraphQLBoolean ,
16
+ GraphQLID ,
17
+ GraphQLInt ,
18
+ GraphQLFloat ,
19
+ GraphQLString ,
15
20
GraphQLEnumType ,
16
21
GraphQLInputObjectType ,
17
22
GraphQLInterfaceType ,
18
23
GraphQLObjectType ,
19
24
GraphQLUnionType ,
20
25
GraphQLList ,
21
26
GraphQLNonNull ,
22
- GraphQLString ,
23
27
GraphQLDirective ,
24
28
GraphQLIncludeDirective ,
25
29
GraphQLSkipDirective ,
26
30
GraphQLDeprecatedDirective ,
27
31
isType ,
28
32
isScalarType ,
33
+ isSpecifiedScalarType ,
29
34
isObjectType ,
30
35
isInterfaceType ,
31
36
isUnionType ,
@@ -82,6 +87,10 @@ const ScalarType = new GraphQLScalarType({
82
87
name : 'Scalar' ,
83
88
serialize ( ) { } ,
84
89
} ) ;
90
+ const Directive = new GraphQLDirective ( {
91
+ name : 'Directive' ,
92
+ locations : [ 'QUERY' ] ,
93
+ } ) ;
85
94
86
95
describe ( 'Type predicates' , ( ) => {
87
96
describe ( 'isType' , ( ) => {
@@ -119,6 +128,11 @@ describe('Type predicates', () => {
119
128
expect ( ( ) => assertScalarType ( ScalarType ) ) . not . to . throw ( ) ;
120
129
} ) ;
121
130
131
+ it ( 'returns false for scalar class (rather than instance)' , ( ) => {
132
+ expect ( isScalarType ( GraphQLScalarType ) ) . to . equal ( false ) ;
133
+ expect ( ( ) => assertScalarType ( GraphQLScalarType ) ) . to . throw ( ) ;
134
+ } ) ;
135
+
122
136
it ( 'returns false for wrapped scalar' , ( ) => {
123
137
expect ( isScalarType ( GraphQLList ( ScalarType ) ) ) . to . equal ( false ) ;
124
138
expect ( ( ) => assertScalarType ( GraphQLList ( ScalarType ) ) ) . to . throw ( ) ;
@@ -127,6 +141,56 @@ describe('Type predicates', () => {
127
141
it ( 'returns false for non-scalar' , ( ) => {
128
142
expect ( isScalarType ( EnumType ) ) . to . equal ( false ) ;
129
143
expect ( ( ) => assertScalarType ( EnumType ) ) . to . throw ( ) ;
144
+ expect ( isScalarType ( Directive ) ) . to . equal ( false ) ;
145
+ expect ( ( ) => assertScalarType ( Directive ) ) . to . throw ( ) ;
146
+ } ) ;
147
+
148
+ it ( 'returns false for random garbage' , ( ) => {
149
+ expect ( isScalarType ( { what : 'is this' } ) ) . to . equal ( false ) ;
150
+ expect ( ( ) => assertScalarType ( { what : 'is this' } ) ) . to . throw ( ) ;
151
+ } ) ;
152
+ } ) ;
153
+
154
+ describe ( 'isSpecifiedScalarType' , ( ) => {
155
+ it ( 'returns true for specified scalars' , ( ) => {
156
+ expect ( isSpecifiedScalarType ( GraphQLString ) ) . to . equal ( true ) ;
157
+ expect ( isSpecifiedScalarType ( GraphQLInt ) ) . to . equal ( true ) ;
158
+ expect ( isSpecifiedScalarType ( GraphQLFloat ) ) . to . equal ( true ) ;
159
+ expect ( isSpecifiedScalarType ( GraphQLBoolean ) ) . to . equal ( true ) ;
160
+ expect ( isSpecifiedScalarType ( GraphQLID ) ) . to . equal ( true ) ;
161
+ } ) ;
162
+
163
+ it ( 'returns false for custom scalar' , ( ) => {
164
+ expect ( isSpecifiedScalarType ( ScalarType ) ) . to . equal ( false ) ;
165
+ } ) ;
166
+
167
+ it ( 'returns false for scalar class (rather than specified instance)' , ( ) => {
168
+ expect ( isSpecifiedScalarType ( GraphQLScalarType ) ) . to . equal ( false ) ;
169
+ } ) ;
170
+
171
+ it ( 'returns false for wrapped specified scalar' , ( ) => {
172
+ expect ( isSpecifiedScalarType ( GraphQLList ( GraphQLString ) ) ) . to . equal ( false ) ;
173
+ } ) ;
174
+
175
+ it ( 'returns false for non-scalar' , ( ) => {
176
+ expect ( isSpecifiedScalarType ( EnumType ) ) . to . equal ( false ) ;
177
+ expect ( isSpecifiedScalarType ( Directive ) ) . to . equal ( false ) ;
178
+ } ) ;
179
+
180
+ it ( 'returns false for spec defined directive' , ( ) => {
181
+ expect ( isSpecifiedScalarType ( GraphQLSkipDirective ) ) . to . equal ( false ) ;
182
+ } ) ;
183
+
184
+ it ( 'returns false for object type named like specified scalar' , ( ) => {
185
+ const ObjectNamedLikeScalar = new GraphQLObjectType ( {
186
+ name : 'String' ,
187
+ fields : { serialize : { type : GraphQLString } } ,
188
+ } ) ;
189
+ expect ( isSpecifiedScalarType ( ObjectNamedLikeScalar ) ) . to . equal ( false ) ;
190
+ } ) ;
191
+
192
+ it ( 'returns false for random garbage' , ( ) => {
193
+ expect ( isSpecifiedScalarType ( { what : 'is this' } ) ) . to . equal ( false ) ;
130
194
} ) ;
131
195
} ) ;
132
196
@@ -593,30 +657,26 @@ describe('Type predicates', () => {
593
657
594
658
describe ( 'Directive predicates' , ( ) => {
595
659
describe ( 'isDirective' , ( ) => {
596
- it ( 'returns true for directives' , ( ) => {
597
- const directive = new GraphQLDirective ( {
598
- name : 'Foo' ,
599
- locations : [ 'QUERY' ] ,
600
- } ) ;
601
- expect ( isDirective ( directive ) ) . to . equal ( true ) ;
602
- expect ( ( ) => assertDirective ( directive ) ) . not . to . throw ( ) ;
660
+ it ( 'returns true for spec defined directive' , ( ) => {
603
661
expect ( isDirective ( GraphQLSkipDirective ) ) . to . equal ( true ) ;
604
662
expect ( ( ) => assertDirective ( GraphQLSkipDirective ) ) . not . to . throw ( ) ;
605
663
} ) ;
606
664
665
+ it ( 'returns true for custom directive' , ( ) => {
666
+ expect ( isDirective ( Directive ) ) . to . equal ( true ) ;
667
+ expect ( ( ) => assertDirective ( Directive ) ) . not . to . throw ( ) ;
668
+ } ) ;
669
+
607
670
it ( 'returns false for directive class (rather than instance)' , ( ) => {
608
671
expect ( isDirective ( GraphQLDirective ) ) . to . equal ( false ) ;
609
672
expect ( ( ) => assertDirective ( GraphQLDirective ) ) . to . throw ( ) ;
610
673
} ) ;
611
674
612
- it ( 'returns false for object type' , ( ) => {
613
- expect ( isDirective ( ObjectType ) ) . to . equal ( false ) ;
614
- expect ( ( ) => assertDirective ( ObjectType ) ) . to . throw ( ) ;
615
- } ) ;
616
-
617
- it ( 'returns false for scalar type' , ( ) => {
618
- expect ( isDirective ( GraphQLString ) ) . to . equal ( false ) ;
619
- expect ( ( ) => assertDirective ( GraphQLString ) ) . to . throw ( ) ;
675
+ it ( 'returns false for non-directive' , ( ) => {
676
+ expect ( isDirective ( EnumType ) ) . to . equal ( false ) ;
677
+ expect ( ( ) => assertDirective ( EnumType ) ) . to . throw ( ) ;
678
+ expect ( isDirective ( ScalarType ) ) . to . equal ( false ) ;
679
+ expect ( ( ) => assertDirective ( ScalarType ) ) . to . throw ( ) ;
620
680
} ) ;
621
681
622
682
it ( 'returns false for random garbage' , ( ) => {
@@ -632,30 +692,31 @@ describe('Directive predicates', () => {
632
692
} ) ;
633
693
634
694
it ( 'returns false for custom directive' , ( ) => {
635
- const directive = new GraphQLDirective ( {
636
- name : 'Foo' ,
637
- locations : [ 'QUERY' ] ,
638
- } ) ;
639
- expect ( isSpecifiedDirective ( directive ) ) . to . equal ( false ) ;
695
+ expect ( isSpecifiedDirective ( Directive ) ) . to . equal ( false ) ;
640
696
} ) ;
641
697
642
698
it ( 'returns false for directive class (rather than specified instance)' , ( ) => {
643
- // $DisableFlowOnNegativeTest
644
699
expect ( isSpecifiedDirective ( GraphQLDirective ) ) . to . equal ( false ) ;
645
700
} ) ;
646
701
647
- it ( 'returns false for object type ' , ( ) => {
648
- // $DisableFlowOnNegativeTest
649
- expect ( isSpecifiedDirective ( ObjectType ) ) . to . equal ( false ) ;
702
+ it ( 'returns false for non-directive ' , ( ) => {
703
+ expect ( isSpecifiedDirective ( EnumType ) ) . to . equal ( false ) ;
704
+ expect ( isSpecifiedDirective ( ScalarType ) ) . to . equal ( false ) ;
650
705
} ) ;
651
706
652
707
it ( 'returns false for spec defined scalar type' , ( ) => {
653
- // $DisableFlowOnNegativeTest
654
708
expect ( isSpecifiedDirective ( GraphQLString ) ) . to . equal ( false ) ;
655
709
} ) ;
656
710
711
+ it ( 'returns false for scalar type named like specified directive' , ( ) => {
712
+ const ScalarNamedLikeDirective = new GraphQLScalarType ( {
713
+ name : 'deprecated' ,
714
+ serialize : ( ) => null ,
715
+ } ) ;
716
+ expect ( isSpecifiedDirective ( ScalarNamedLikeDirective ) ) . to . equal ( false ) ;
717
+ } ) ;
718
+
657
719
it ( 'returns false for random garbage' , ( ) => {
658
- // $DisableFlowOnNegativeTest
659
720
expect ( isSpecifiedDirective ( { what : 'is this' } ) ) . to . equal ( false ) ;
660
721
} ) ;
661
722
} ) ;
0 commit comments