@@ -5,6 +5,8 @@ import { expectJSON } from '../../__testUtils__/expectJSON.js';
5
5
6
6
import { inspect } from '../../jsutils/inspect.js' ;
7
7
8
+ import { GraphQLError } from '../../error/GraphQLError.js' ;
9
+
8
10
import { Kind } from '../../language/kinds.js' ;
9
11
import { parse } from '../../language/parser.js' ;
10
12
@@ -26,6 +28,25 @@ import { GraphQLSchema } from '../../type/schema.js';
26
28
import { executeSync } from '../execute.js' ;
27
29
import { getVariableValues } from '../values.js' ;
28
30
31
+ const TestFaultyScalarGraphQLError = new GraphQLError (
32
+ 'FaultyScalarErrorMessage' ,
33
+ {
34
+ extensions : {
35
+ code : 'FaultyScalarErrorMessageExtensionCode'
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
+
29
50
const TestComplexScalar = new GraphQLScalarType ( {
30
51
name : 'ComplexScalar' ,
31
52
parseValue ( value ) {
@@ -45,6 +66,7 @@ const TestInputObject = new GraphQLInputObjectType({
45
66
b : { type : new GraphQLList ( GraphQLString ) } ,
46
67
c : { type : new GraphQLNonNull ( GraphQLString ) } ,
47
68
d : { type : TestComplexScalar } ,
69
+ e : { type : TestFaultyScalar }
48
70
} ,
49
71
} ) ;
50
72
@@ -225,6 +247,29 @@ describe('Execute: Handles inputs', () => {
225
247
} ,
226
248
} ) ;
227
249
} ) ;
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
+
272
+ } ) ;
228
273
} ) ;
229
274
230
275
describe ( 'using variables' , ( ) => {
@@ -366,6 +411,22 @@ describe('Execute: Handles inputs', () => {
366
411
} ) ;
367
412
} ) ;
368
413
414
+ it ( 'errors on faulty scalar type input' , ( ) => {
415
+ const params = { input : { c : 'foo' , e : 'SerializedValue' } } ;
416
+ const result = executeQuery ( doc , params ) ;
417
+
418
+ expect ( result . errors ?. at ( 0 ) ?. originalError ) . to . equal ( TestFaultyScalarGraphQLError ) ;
419
+ expectJSON ( result ) . toDeepEqual ( {
420
+ errors : [
421
+ {
422
+ message : 'Variable "$input" got invalid value "SerializedValue" at "input.e"; FaultyScalarErrorMessage' ,
423
+ locations : [ { line : 2 , column : 16 } ] ,
424
+ extensions : { code : 'FaultyScalarErrorMessageExtensionCode' }
425
+ }
426
+ ]
427
+ } ) ;
428
+ } ) ;
429
+
369
430
it ( 'errors on null for nested non-null' , ( ) => {
370
431
const params = { input : { a : 'foo' , b : 'bar' , c : null } } ;
371
432
const result = executeQuery ( doc , params ) ;
0 commit comments