|
| 1 | +// eslint-disable-next-line import/no-extraneous-dependencies |
1 | 2 | import { inspect } from 'cross-inspect';
|
2 | 3 | import {
|
3 | 4 | GraphQLArgumentConfig,
|
4 | 5 | GraphQLEnumType,
|
| 6 | + GraphQLError, |
5 | 7 | GraphQLFieldConfig,
|
6 | 8 | GraphQLInputObjectType,
|
7 | 9 | GraphQLList,
|
@@ -29,13 +31,30 @@ const TestComplexScalar = new GraphQLScalarType({
|
29 | 31 | },
|
30 | 32 | });
|
31 | 33 |
|
| 34 | +const TestFaultyScalarGraphQLError = new GraphQLError('FaultyScalarErrorMessage', { |
| 35 | + extensions: { |
| 36 | + code: 'FaultyScalarErrorMessageExtensionCode', |
| 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 | + |
32 | 50 | const TestInputObject = new GraphQLInputObjectType({
|
33 | 51 | name: 'TestInputObject',
|
34 | 52 | fields: {
|
35 | 53 | a: { type: GraphQLString },
|
36 | 54 | b: { type: new GraphQLList(GraphQLString) },
|
37 | 55 | c: { type: new GraphQLNonNull(GraphQLString) },
|
38 | 56 | d: { type: TestComplexScalar },
|
| 57 | + e: { type: TestFaultyScalar }, |
39 | 58 | },
|
40 | 59 | });
|
41 | 60 |
|
@@ -211,6 +230,27 @@ describe('Execute: Handles inputs', () => {
|
211 | 230 | });
|
212 | 231 | });
|
213 | 232 |
|
| 233 | + it('errors on faulty scalar type input', () => { |
| 234 | + const result = executeQuery(` |
| 235 | + { |
| 236 | + fieldWithObjectInput(input: {c: "foo", e: "bar"}) |
| 237 | + } |
| 238 | + `); |
| 239 | + |
| 240 | + expectJSON(result).toDeepEqual({ |
| 241 | + data: { |
| 242 | + fieldWithObjectInput: null, |
| 243 | + }, |
| 244 | + errors: [ |
| 245 | + { |
| 246 | + message: 'Argument "input" has invalid value {c: "foo", e: "bar"}.', |
| 247 | + path: ['fieldWithObjectInput'], |
| 248 | + locations: [{ line: 3, column: 39 }], |
| 249 | + }, |
| 250 | + ], |
| 251 | + }); |
| 252 | + }); |
| 253 | + |
214 | 254 | describe('using variables', () => {
|
215 | 255 | const doc = `
|
216 | 256 | query ($input: TestInputObject) {
|
@@ -350,6 +390,22 @@ describe('Execute: Handles inputs', () => {
|
350 | 390 | });
|
351 | 391 | });
|
352 | 392 |
|
| 393 | + it('errors on faulty scalar type input', () => { |
| 394 | + const params = { input: { c: 'foo', e: 'SerializedValue' } }; |
| 395 | + const result = executeQuery(doc, params); |
| 396 | + |
| 397 | + expectJSON(result).toDeepEqual({ |
| 398 | + errors: [ |
| 399 | + { |
| 400 | + message: |
| 401 | + 'Variable "$input" got invalid value "SerializedValue" at "input.e"; FaultyScalarErrorMessage', |
| 402 | + locations: [{ line: 2, column: 16 }], |
| 403 | + extensions: { code: 'FaultyScalarErrorMessageExtensionCode' }, |
| 404 | + }, |
| 405 | + ], |
| 406 | + }); |
| 407 | + }); |
| 408 | + |
353 | 409 | it('errors on null for nested non-null', () => {
|
354 | 410 | const params = { input: { a: 'foo', b: 'bar', c: null } };
|
355 | 411 | const result = executeQuery(doc, params);
|
|
0 commit comments