@@ -273,6 +273,108 @@ describe('coerceInputValue', () => {
273273 } ) ;
274274 } ) ;
275275
276+ describe ( 'for GraphQLInputObject that isOneOf' , ( ) => {
277+ const TestInputObject = new GraphQLInputObjectType ( {
278+ name : 'TestInputObject' ,
279+ fields : {
280+ foo : { type : GraphQLInt } ,
281+ bar : { type : GraphQLInt } ,
282+ } ,
283+ isOneOf : true ,
284+ } ) ;
285+
286+ it ( 'returns no error for a valid input' , ( ) => {
287+ const result = coerceValue ( { foo : 123 } , TestInputObject ) ;
288+ expectValue ( result ) . to . deep . equal ( { foo : 123 } ) ;
289+ } ) ;
290+
291+ it ( 'returns an error if more than one field is specified' , ( ) => {
292+ const result = coerceValue ( { foo : 123 , bar : null } , TestInputObject ) ;
293+ expectErrors ( result ) . to . deep . equal ( [
294+ {
295+ error : 'Exactly one key must be specified.' ,
296+ path : [ ] ,
297+ value : { foo : 123 , bar : null } ,
298+ } ,
299+ ] ) ;
300+ } ) ;
301+
302+ it ( 'returns an error the one field is null' , ( ) => {
303+ const result = coerceValue ( { bar : null } , TestInputObject ) ;
304+ expectErrors ( result ) . to . deep . equal ( [
305+ {
306+ error : 'Field "bar" must be non-null.' ,
307+ path : [ 'bar' ] ,
308+ value : null ,
309+ } ,
310+ ] ) ;
311+ } ) ;
312+
313+ it ( 'returns an error for an invalid field' , ( ) => {
314+ const result = coerceValue ( { foo : NaN } , TestInputObject ) ;
315+ expectErrors ( result ) . to . deep . equal ( [
316+ {
317+ error : 'Int cannot represent non-integer value: NaN' ,
318+ path : [ 'foo' ] ,
319+ value : NaN ,
320+ } ,
321+ ] ) ;
322+ } ) ;
323+
324+ it ( 'returns multiple errors for multiple invalid fields' , ( ) => {
325+ const result = coerceValue ( { foo : 'abc' , bar : 'def' } , TestInputObject ) ;
326+ expectErrors ( result ) . to . deep . equal ( [
327+ {
328+ error : 'Int cannot represent non-integer value: "abc"' ,
329+ path : [ 'foo' ] ,
330+ value : 'abc' ,
331+ } ,
332+ {
333+ error : 'Int cannot represent non-integer value: "def"' ,
334+ path : [ 'bar' ] ,
335+ value : 'def' ,
336+ } ,
337+ {
338+ error : 'Exactly one key must be specified.' ,
339+ path : [ ] ,
340+ value : { foo : 'abc' , bar : 'def' } ,
341+ } ,
342+ ] ) ;
343+ } ) ;
344+
345+ it ( 'returns error for an unknown field' , ( ) => {
346+ const result = coerceValue (
347+ { foo : 123 , unknownField : 123 } ,
348+ TestInputObject ,
349+ ) ;
350+ expectErrors ( result ) . to . deep . equal ( [
351+ {
352+ error :
353+ 'Field "unknownField" is not defined by type "TestInputObject".' ,
354+ path : [ ] ,
355+ value : { foo : 123 , unknownField : 123 } ,
356+ } ,
357+ ] ) ;
358+ } ) ;
359+
360+ it ( 'returns error for a misspelled field' , ( ) => {
361+ const result = coerceValue ( { bart : 123 } , TestInputObject ) ;
362+ expectErrors ( result ) . to . deep . equal ( [
363+ {
364+ error :
365+ 'Field "bart" is not defined by type "TestInputObject". Did you mean "bar"?' ,
366+ path : [ ] ,
367+ value : { bart : 123 } ,
368+ } ,
369+ {
370+ error : 'Exactly one key must be specified.' ,
371+ path : [ ] ,
372+ value : { bart : 123 } ,
373+ } ,
374+ ] ) ;
375+ } ) ;
376+ } ) ;
377+
276378 describe ( 'for GraphQLInputObject with default value' , ( ) => {
277379 const makeTestInputObject = ( defaultValue : any ) =>
278380 new GraphQLInputObjectType ( {
0 commit comments