Skip to content

Commit 10a3021

Browse files
authored
Merge branch 'graphql:main' into fragment-args-2023
2 parents 922839c + b5eb498 commit 10a3021

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

resources/build-docusaurus.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ fs.writeFileSync(tmpDirPath('package.json'), JSON.stringify(packageJSON));
1414

1515
copyToTmpDir('package-lock.json');
1616
copyToTmpDir('tsconfig.json');
17+
copyToTmpDir('resources/eslint-internal-rules');
1718
copyToTmpDir('src');
1819
copyToTmpDir('website');
1920

src/execution/__tests__/variables-test.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { expectJSON } from '../../__testUtils__/expectJSON.js';
55

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

8+
import { GraphQLError } from '../../error/GraphQLError.js';
9+
810
import { Kind } from '../../language/kinds.js';
911
import { parse } from '../../language/parser.js';
1012

@@ -26,6 +28,25 @@ import { GraphQLSchema } from '../../type/schema.js';
2628
import { executeSync } from '../execute.js';
2729
import { getVariableValues } from '../values.js';
2830

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+
2950
const TestComplexScalar = new GraphQLScalarType({
3051
name: 'ComplexScalar',
3152
parseValue(value) {
@@ -45,6 +66,7 @@ const TestInputObject = new GraphQLInputObjectType({
4566
b: { type: new GraphQLList(GraphQLString) },
4667
c: { type: new GraphQLNonNull(GraphQLString) },
4768
d: { type: TestComplexScalar },
69+
e: { type: TestFaultyScalar },
4870
},
4971
});
5072

@@ -236,6 +258,28 @@ describe('Execute: Handles inputs', () => {
236258
},
237259
});
238260
});
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+
});
239283
});
240284

241285
describe('using variables', () => {
@@ -377,6 +421,22 @@ describe('Execute: Handles inputs', () => {
377421
});
378422
});
379423

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+
380440
it('errors on null for nested non-null', () => {
381441
const params = { input: { a: 'foo', b: 'bar', c: null } };
382442
const result = executeQuery(doc, params);

src/execution/values.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ function coerceVariableValues(
131131
onError(
132132
new GraphQLError(prefix + '; ' + error.message, {
133133
nodes: varDefNode,
134-
originalError: error.originalError,
134+
originalError: error,
135135
}),
136136
);
137137
},

0 commit comments

Comments
 (0)