@@ -6,6 +6,8 @@ import { expectJSON } from '../../__testUtils__/expectJSON';
66import { inspect } from '../../jsutils/inspect' ;
77import { invariant } from '../../jsutils/invariant' ;
88
9+ import { GraphQLError } from '../../error/GraphQLError' ;
10+
911import { Kind } from '../../language/kinds' ;
1012import { parse } from '../../language/parser' ;
1113
@@ -27,6 +29,25 @@ import { GraphQLSchema } from '../../type/schema';
2729import { executeSync } from '../execute' ;
2830import { getVariableValues } from '../values' ;
2931
32+ const TestFaultyScalarGraphQLError = new GraphQLError (
33+ 'FaultyScalarErrorMessage' ,
34+ {
35+ extensions : {
36+ code : 'FaultyScalarErrorMessageExtensionCode' ,
37+ } ,
38+ } ,
39+ ) ;
40+
41+ const TestFaultyScalar = new GraphQLScalarType ( {
42+ name : 'FaultyScalar' ,
43+ parseValue ( ) {
44+ throw TestFaultyScalarGraphQLError ;
45+ } ,
46+ parseLiteral ( ) {
47+ throw TestFaultyScalarGraphQLError ;
48+ } ,
49+ } ) ;
50+
3051const TestComplexScalar = new GraphQLScalarType ( {
3152 name : 'ComplexScalar' ,
3253 parseValue ( value ) {
@@ -46,6 +67,7 @@ const TestInputObject = new GraphQLInputObjectType({
4667 b : { type : new GraphQLList ( GraphQLString ) } ,
4768 c : { type : new GraphQLNonNull ( GraphQLString ) } ,
4869 d : { type : TestComplexScalar } ,
70+ e : { type : TestFaultyScalar } ,
4971 } ,
5072} ) ;
5173
@@ -228,6 +250,27 @@ describe('Execute: Handles inputs', () => {
228250 } ) ;
229251 } ) ;
230252
253+ it ( 'errors on faulty scalar type input' , ( ) => {
254+ const result = executeQuery ( `
255+ {
256+ fieldWithObjectInput(input: {c: "foo", e: "bar"})
257+ }
258+ ` ) ;
259+
260+ expectJSON ( result ) . toDeepEqual ( {
261+ data : {
262+ fieldWithObjectInput : null ,
263+ } ,
264+ errors : [
265+ {
266+ message : 'Argument "input" has invalid value {c: "foo", e: "bar"}.' ,
267+ path : [ 'fieldWithObjectInput' ] ,
268+ locations : [ { line : 3 , column : 39 } ] ,
269+ } ,
270+ ] ,
271+ } ) ;
272+ } ) ;
273+
231274 describe ( 'using variables' , ( ) => {
232275 const doc = `
233276 query ($input: TestInputObject) {
@@ -367,6 +410,22 @@ describe('Execute: Handles inputs', () => {
367410 } ) ;
368411 } ) ;
369412
413+ it ( 'errors on faulty scalar type input' , ( ) => {
414+ const params = { input : { c : 'foo' , e : 'SerializedValue' } } ;
415+ const result = executeQuery ( doc , params ) ;
416+
417+ expectJSON ( result ) . toDeepEqual ( {
418+ errors : [
419+ {
420+ message :
421+ 'Variable "$input" got invalid value "SerializedValue" at "input.e"; FaultyScalarErrorMessage' ,
422+ locations : [ { line : 2 , column : 16 } ] ,
423+ extensions : { code : 'FaultyScalarErrorMessageExtensionCode' } ,
424+ } ,
425+ ] ,
426+ } ) ;
427+ } ) ;
428+
370429 it ( 'errors on null for nested non-null' , ( ) => {
371430 const params = { input : { a : 'foo' , b : 'bar' , c : null } } ;
372431 const result = executeQuery ( doc , params ) ;
0 commit comments