@@ -15,11 +15,17 @@ import {
15
15
GraphQLObjectType ,
16
16
GraphQLSchema ,
17
17
GraphQLString ,
18
+ GraphQLInputObjectType ,
19
+ GraphQLScalarType ,
20
+ GraphQLEnumType ,
21
+ GraphQLList ,
22
+ GraphQLNonNull ,
18
23
graphql
19
24
} from 'graphql' ;
20
25
21
26
import {
22
- pluralIdentifyingRootField
27
+ pluralIdentifyingRootField ,
28
+ nonNull
23
29
} from '../plural' ;
24
30
25
31
var userType = new GraphQLObjectType ( {
@@ -42,6 +48,7 @@ var queryType = new GraphQLObjectType({
42
48
description : 'Map from a username to the user' ,
43
49
inputType : GraphQLString ,
44
50
outputType : userType ,
51
+ // $FlowFixMe : rootValue Graphql(mixed) -> relay(object)
45
52
resolveSingleInput : ( username , context , { rootValue : { lang} } ) => ( {
46
53
username : username ,
47
54
url : 'www.facebook.com/' + username + '?lang=' + lang
@@ -157,3 +164,60 @@ describe('pluralIdentifyingRootField()', () => {
157
164
return expect ( graphql ( schema , query ) ) . to . become ( { data : expected } ) ;
158
165
} ) ;
159
166
} ) ;
167
+
168
+ describe ( 'nonNull()' , ( ) => {
169
+ function qlScalar ( ) {
170
+ return new GraphQLScalarType ( {
171
+ name : 'scalar' ,
172
+ serialize : String ,
173
+ description : 'test'
174
+ } ) ;
175
+ }
176
+
177
+ it ( 'covert GraphQLInputObjectType to NonNull type' , ( ) => {
178
+ const inputType = new GraphQLInputObjectType ( {
179
+ name : 'input' ,
180
+ fields : {
181
+ test : {
182
+ type : qlScalar ( )
183
+ }
184
+ }
185
+ } ) ;
186
+ const result = nonNull ( inputType ) ;
187
+ expect ( result ) . to . be . an . instanceof ( GraphQLNonNull ) ;
188
+ expect ( result . ofType ) . to . deep . equal ( inputType ) ;
189
+ } ) ;
190
+
191
+ it ( 'covert GraphQLScalarType to NonNull type' , ( ) => {
192
+ const scalarType = qlScalar ( ) ;
193
+ const result = nonNull ( scalarType ) ;
194
+ expect ( result ) . to . be . an . instanceof ( GraphQLNonNull ) ;
195
+ expect ( result . ofType ) . to . deep . equal ( scalarType ) ;
196
+ } ) ;
197
+
198
+ it ( 'covert GraphQLEnumType to NonNull type' , ( ) => {
199
+ const enumType = new GraphQLEnumType ( {
200
+ name : 'EM' ,
201
+ values : {
202
+ E : { value : 0 } ,
203
+ M : { value : 1 }
204
+ }
205
+ } ) ;
206
+ const result = nonNull ( enumType ) ;
207
+ expect ( result ) . to . be . an . instanceof ( GraphQLNonNull ) ;
208
+ expect ( result . ofType ) . to . deep . equal ( enumType ) ;
209
+ } ) ;
210
+
211
+ it ( 'covert GraphQLList to NonNull type' , ( ) => {
212
+ const listType = new GraphQLList ( GraphQLString ) ;
213
+ const result = nonNull ( listType ) ;
214
+ expect ( result ) . to . be . an . instanceof ( GraphQLNonNull ) ;
215
+ expect ( result . ofType ) . to . deep . equal ( listType ) ;
216
+ } ) ;
217
+
218
+ it ( 'does nothing to GraphQLNonNull Type' , ( ) => {
219
+ const nonNullType = new GraphQLNonNull ( GraphQLString ) ;
220
+ const result = nonNull ( nonNullType ) ;
221
+ expect ( result ) . to . deep . equal ( nonNullType ) ;
222
+ } ) ;
223
+ } ) ;
0 commit comments