@@ -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 : '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
+
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
@@ -236,6 +258,28 @@ describe('Execute: Handles inputs', () => {
236
258
} ,
237
259
} ) ;
238
260
} ) ;
261
+
262
+ it ( 'errors on faulty scalar type input' , ( ) => {
263
+ const result = executeQuery ( `
264
+ {
265
+ fieldWithObjectInput(input: {c: "foo", e: "bar"})
266
+ }
267
+ ` ) ;
268
+
269
+ expectJSON ( result ) . toDeepEqual ( {
270
+ data : {
271
+ fieldWithObjectInput : null ,
272
+ } ,
273
+ errors : [
274
+ {
275
+ message :
276
+ 'Argument "input" has invalid value { c: "foo", e: "bar" }.' ,
277
+ path : [ 'fieldWithObjectInput' ] ,
278
+ locations : [ { line : 3 , column : 41 } ] ,
279
+ } ,
280
+ ] ,
281
+ } ) ;
282
+ } ) ;
239
283
} ) ;
240
284
241
285
describe ( 'using variables' , ( ) => {
@@ -377,6 +421,22 @@ describe('Execute: Handles inputs', () => {
377
421
} ) ;
378
422
} ) ;
379
423
424
+ it ( 'errors on faulty scalar type input' , ( ) => {
425
+ const params = { input : { c : 'foo' , e : 'SerializedValue' } } ;
426
+ const result = executeQuery ( doc , params ) ;
427
+
428
+ expectJSON ( result ) . toDeepEqual ( {
429
+ errors : [
430
+ {
431
+ message :
432
+ 'Variable "$input" got invalid value "SerializedValue" at "input.e"; FaultyScalarErrorMessage' ,
433
+ locations : [ { line : 2 , column : 16 } ] ,
434
+ extensions : { code : 'FaultyScalarErrorExtensionCode' } ,
435
+ } ,
436
+ ] ,
437
+ } ) ;
438
+ } ) ;
439
+
380
440
it ( 'errors on null for nested non-null' , ( ) => {
381
441
const params = { input : { a : 'foo' , b : 'bar' , c : null } } ;
382
442
const result = executeQuery ( doc , params ) ;
0 commit comments