@@ -15,11 +15,17 @@ import {
1515 GraphQLObjectType ,
1616 GraphQLSchema ,
1717 GraphQLString ,
18+ GraphQLInputObjectType ,
19+ GraphQLScalarType ,
20+ GraphQLEnumType ,
21+ GraphQLList ,
22+ GraphQLNonNull ,
1823 graphql
1924} from 'graphql' ;
2025
2126import {
22- pluralIdentifyingRootField
27+ pluralIdentifyingRootField ,
28+ nonNull
2329} from '../plural' ;
2430
2531var userType = new GraphQLObjectType ( {
@@ -42,6 +48,7 @@ var queryType = new GraphQLObjectType({
4248 description : 'Map from a username to the user' ,
4349 inputType : GraphQLString ,
4450 outputType : userType ,
51+ // $FlowFixMe : rootValue Graphql(mixed) -> relay(object)
4552 resolveSingleInput : ( username , context , { rootValue : { lang} } ) => ( {
4653 username : username ,
4754 url : 'www.facebook.com/' + username + '?lang=' + lang
@@ -157,3 +164,60 @@ describe('pluralIdentifyingRootField()', () => {
157164 return expect ( graphql ( schema , query ) ) . to . become ( { data : expected } ) ;
158165 } ) ;
159166} ) ;
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