@@ -50,12 +50,13 @@ interface CoerceError {
5050function coerceValue (
5151 inputValue : unknown ,
5252 type : GraphQLInputType ,
53+ shouldProvideSuggestions : boolean = true ,
5354) : CoerceResult {
5455 const errors : Array < CoerceError > = [ ] ;
5556 const value = coerceInputValue (
5657 inputValue ,
5758 type ,
58- true ,
59+ shouldProvideSuggestions ,
5960 ( path , invalidValue , error ) => {
6061 errors . push ( { path, value : invalidValue , error : error . message } ) ;
6162 } ,
@@ -184,6 +185,18 @@ describe('coerceInputValue', () => {
184185 ] ) ;
185186 } ) ;
186187
188+ it ( 'returns an error for misspelled enum value (no suggestions)' , ( ) => {
189+ const result = coerceValue ( 'foo' , TestEnum , false ) ;
190+ expectErrors ( result ) . to . deep . equal ( [
191+ {
192+ error :
193+ 'Value "foo" does not exist in "TestEnum" enum.' ,
194+ path : [ ] ,
195+ value : 'foo' ,
196+ } ,
197+ ] ) ;
198+ } ) ;
199+
187200 it ( 'returns an error for incorrect value type' , ( ) => {
188201 const result1 = coerceValue ( 123 , TestEnum ) ;
189202 expectErrors ( result1 ) . to . deep . equal ( [
@@ -204,6 +217,27 @@ describe('coerceInputValue', () => {
204217 } ,
205218 ] ) ;
206219 } ) ;
220+
221+ it ( 'returns an error for incorrect value type (no suggestions)' , ( ) => {
222+ const result1 = coerceValue ( 123 , TestEnum , false ) ;
223+ expectErrors ( result1 ) . to . deep . equal ( [
224+ {
225+ error : 'Enum "TestEnum" cannot represent non-string value: 123.' ,
226+ path : [ ] ,
227+ value : 123 ,
228+ } ,
229+ ] ) ;
230+
231+ const result2 = coerceValue ( { field : 'value' } , TestEnum , false ) ;
232+ expectErrors ( result2 ) . to . deep . equal ( [
233+ {
234+ error :
235+ 'Enum "TestEnum" cannot represent non-string value: { field: "value" }.' ,
236+ path : [ ] ,
237+ value : { field : 'value' } ,
238+ } ,
239+ ] ) ;
240+ } ) ;
207241 } ) ;
208242
209243 describe ( 'for GraphQLInputObject' , ( ) => {
@@ -401,6 +435,23 @@ describe('coerceInputValue', () => {
401435 } ,
402436 ] ) ;
403437 } ) ;
438+
439+ it ( 'returns error for a misspelled field without suggestions' , ( ) => {
440+ const result = coerceValue ( { bart : 123 } , TestInputObject , false ) ;
441+ expectErrors ( result ) . to . deep . equal ( [
442+ {
443+ error : 'Field "bart" is not defined by type "TestInputObject".' ,
444+ path : [ ] ,
445+ value : { bart : 123 } ,
446+ } ,
447+ {
448+ error :
449+ 'Exactly one key must be specified for OneOf type "TestInputObject".' ,
450+ path : [ ] ,
451+ value : { bart : 123 } ,
452+ } ,
453+ ] ) ;
454+ } ) ;
404455 } ) ;
405456
406457 describe ( 'for GraphQLInputObject with default value' , ( ) => {
0 commit comments