Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/execution/__tests__/variables-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { expectJSON } from '../../__testUtils__/expectJSON.js';

import { inspect } from '../../jsutils/inspect.js';

import { GraphQLError } from '../../error/GraphQLError.js';

import { Kind } from '../../language/kinds.js';
import { parse } from '../../language/parser.js';

Expand All @@ -29,6 +31,11 @@ import { getVariableValues } from '../values.js';
const TestComplexScalar = new GraphQLScalarType({
name: 'ComplexScalar',
parseValue(value) {
if (value === 'ThrowAnError') {
throw new GraphQLError('parseValue throws', {
extensions: { custom: 'extension' },
});
}
expect(value).to.equal('SerializedValue');
return 'DeserializedValue';
},
Expand Down Expand Up @@ -366,6 +373,22 @@ describe('Execute: Handles inputs', () => {
});
});

it('propagates GraphQLError from parseValue', () => {
const params = { input: { c: 'foo', d: 'ThrowAnError' } };
const result = executeQuery(doc, params);

expectJSON(result).toDeepEqual({
errors: [
{
message:
'Variable "$input" got invalid value "ThrowAnError" at "input.d"; parseValue throws',
locations: [{ column: 16, line: 2 }],
extensions: { custom: 'extension' },
},
],
});
});

it('errors on null for nested non-null', () => {
const params = { input: { a: 'foo', b: 'bar', c: null } };
const result = executeQuery(doc, params);
Expand Down
2 changes: 1 addition & 1 deletion src/execution/values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ function coerceVariableValues(
onError(
new GraphQLError(prefix + '; ' + error.message, {
nodes: varDefNode,
originalError: error.originalError,
originalError: error,
}),
);
},
Expand Down