@@ -5,6 +5,8 @@ import { expectJSON } from '../../__testUtils__/expectJSON.js';
55
66import { inspect } from '../../jsutils/inspect.js' ;
77
8+ import { GraphQLError } from '../../error/GraphQLError.js' ;
9+
810import { Kind } from '../../language/kinds.js' ;
911import { parse } from '../../language/parser.js' ;
1012
@@ -26,6 +28,25 @@ import { GraphQLSchema } from '../../type/schema.js';
2628import { executeSync } from '../execute.js' ;
2729import { getVariableValues } from '../values.js' ;
2830
31+ const TestFaultyScalarGraphQLError = new GraphQLError (
32+ 'FaultyScalarErrorMessage' ,
33+ {
34+ extensions : {
35+ code : 'FaultyScalarErrorExtensionCode' ,
36+ } ,
37+ } ,
38+ ) ;
39+
40+ const TestFaultyScalar = new GraphQLScalarType ( {
41+ name : 'FaultyScalar' ,
42+ parseValue ( ) {
43+ throw TestFaultyScalarGraphQLError ;
44+ } ,
45+ parseLiteral ( ) {
46+ throw TestFaultyScalarGraphQLError ;
47+ } ,
48+ } ) ;
49+
2950const TestComplexScalar = new GraphQLScalarType ( {
3051 name : 'ComplexScalar' ,
3152 parseValue ( value ) {
@@ -45,6 +66,7 @@ const TestInputObject = new GraphQLInputObjectType({
4566 b : { type : new GraphQLList ( GraphQLString ) } ,
4667 c : { type : new GraphQLNonNull ( GraphQLString ) } ,
4768 d : { type : TestComplexScalar } ,
69+ e : { type : TestFaultyScalar } ,
4870 } ,
4971} ) ;
5072
@@ -225,6 +247,28 @@ describe('Execute: Handles inputs', () => {
225247 } ,
226248 } ) ;
227249 } ) ;
250+
251+ it ( 'errors on faulty scalar type input' , ( ) => {
252+ const result = executeQuery ( `
253+ {
254+ fieldWithObjectInput(input: {c: "foo", e: "bar"})
255+ }
256+ ` ) ;
257+
258+ expectJSON ( result ) . toDeepEqual ( {
259+ data : {
260+ fieldWithObjectInput : null ,
261+ } ,
262+ errors : [
263+ {
264+ message :
265+ 'Argument "input" has invalid value { c: "foo", e: "bar" }.' ,
266+ path : [ 'fieldWithObjectInput' ] ,
267+ locations : [ { line : 3 , column : 41 } ] ,
268+ } ,
269+ ] ,
270+ } ) ;
271+ } ) ;
228272 } ) ;
229273
230274 describe ( 'using variables' , ( ) => {
@@ -366,6 +410,22 @@ describe('Execute: Handles inputs', () => {
366410 } ) ;
367411 } ) ;
368412
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 : 'FaultyScalarErrorExtensionCode' } ,
424+ } ,
425+ ] ,
426+ } ) ;
427+ } ) ;
428+
369429 it ( 'errors on null for nested non-null' , ( ) => {
370430 const params = { input : { a : 'foo' , b : 'bar' , c : null } } ;
371431 const result = executeQuery ( doc , params ) ;
0 commit comments