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

Filter by extension

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

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

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

Expand All @@ -27,6 +29,25 @@ import { GraphQLSchema } from '../../type/schema';
import { executeSync } from '../execute';
import { getVariableValues } from '../values';

const TestFaultyScalarGraphQLError = new GraphQLError(
'FaultyScalarErrorMessage',
{
extensions: {
code: 'FaultyScalarErrorMessageExtensionCode',
},
},
);

const TestFaultyScalar = new GraphQLScalarType({
name: 'FaultyScalar',
parseValue() {
throw TestFaultyScalarGraphQLError;
},
parseLiteral() {
throw TestFaultyScalarGraphQLError;
},
});

const TestComplexScalar = new GraphQLScalarType({
name: 'ComplexScalar',
parseValue(value) {
Expand All @@ -46,6 +67,7 @@ const TestInputObject = new GraphQLInputObjectType({
b: { type: new GraphQLList(GraphQLString) },
c: { type: new GraphQLNonNull(GraphQLString) },
d: { type: TestComplexScalar },
e: { type: TestFaultyScalar },
},
});

Expand Down Expand Up @@ -228,6 +250,27 @@ describe('Execute: Handles inputs', () => {
});
});

it('errors on faulty scalar type input', () => {
const result = executeQuery(`
{
fieldWithObjectInput(input: {c: "foo", e: "bar"})
}
`);

expectJSON(result).toDeepEqual({
data: {
fieldWithObjectInput: null,
},
errors: [
{
message: 'Argument "input" has invalid value {c: "foo", e: "bar"}.',
path: ['fieldWithObjectInput'],
locations: [{ line: 3, column: 39 }],
},
],
});
});

describe('using variables', () => {
const doc = `
query ($input: TestInputObject) {
Expand Down Expand Up @@ -367,6 +410,22 @@ describe('Execute: Handles inputs', () => {
});
});

it('errors on faulty scalar type input', () => {
const params = { input: { c: 'foo', e: 'SerializedValue' } };
const result = executeQuery(doc, params);

expectJSON(result).toDeepEqual({
errors: [
{
message:
'Variable "$input" got invalid value "SerializedValue" at "input.e"; FaultyScalarErrorMessage',
locations: [{ line: 2, column: 16 }],
extensions: { code: 'FaultyScalarErrorMessageExtensionCode' },
},
],
});
});

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