@@ -6,6 +6,8 @@ import { expectJSON } from '../../__testUtils__/expectJSON';
6
6
import { inspect } from '../../jsutils/inspect' ;
7
7
import { invariant } from '../../jsutils/invariant' ;
8
8
9
+ import { GraphQLError } from '../../error/GraphQLError' ;
10
+
9
11
import { Kind } from '../../language/kinds' ;
10
12
import { parse } from '../../language/parser' ;
11
13
@@ -27,6 +29,25 @@ import { GraphQLSchema } from '../../type/schema';
27
29
import { executeSync } from '../execute' ;
28
30
import { getVariableValues } from '../values' ;
29
31
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
+
30
51
const TestComplexScalar = new GraphQLScalarType ( {
31
52
name : 'ComplexScalar' ,
32
53
parseValue ( value ) {
@@ -46,6 +67,7 @@ const TestInputObject = new GraphQLInputObjectType({
46
67
b : { type : new GraphQLList ( GraphQLString ) } ,
47
68
c : { type : new GraphQLNonNull ( GraphQLString ) } ,
48
69
d : { type : TestComplexScalar } ,
70
+ e : { type : TestFaultyScalar } ,
49
71
} ,
50
72
} ) ;
51
73
@@ -228,6 +250,27 @@ describe('Execute: Handles inputs', () => {
228
250
} ) ;
229
251
} ) ;
230
252
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
+
231
274
describe ( 'using variables' , ( ) => {
232
275
const doc = `
233
276
query ($input: TestInputObject) {
@@ -367,6 +410,22 @@ describe('Execute: Handles inputs', () => {
367
410
} ) ;
368
411
} ) ;
369
412
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
+
370
429
it ( 'errors on null for nested non-null' , ( ) => {
371
430
const params = { input : { a : 'foo' , b : 'bar' , c : null } } ;
372
431
const result = executeQuery ( doc , params ) ;
0 commit comments