From bdd24b788912812aee382515ab3b521ce7e82909 Mon Sep 17 00:00:00 2001 From: Sten Reijers Date: Sun, 29 Jan 2023 15:45:03 +0100 Subject: [PATCH 1/3] fix: fixed invalid originalError propagation on parseValue() errors in custom scalars --- src/execution/__tests__/variables-test.ts | 61 +++++++++++++++++++++++ src/execution/values.ts | 2 +- 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/src/execution/__tests__/variables-test.ts b/src/execution/__tests__/variables-test.ts index 7c74d8ee92..c0cda21997 100644 --- a/src/execution/__tests__/variables-test.ts +++ b/src/execution/__tests__/variables-test.ts @@ -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'; @@ -26,6 +28,25 @@ import { GraphQLSchema } from '../../type/schema.js'; import { executeSync } from '../execute.js'; import { getVariableValues } from '../values.js'; +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) { @@ -45,6 +66,7 @@ const TestInputObject = new GraphQLInputObjectType({ b: { type: new GraphQLList(GraphQLString) }, c: { type: new GraphQLNonNull(GraphQLString) }, d: { type: TestComplexScalar }, + e: { type: TestFaultyScalar } }, }); @@ -225,6 +247,29 @@ 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: 41 }], + }, + ], + }); + + }); }); describe('using variables', () => { @@ -366,6 +411,22 @@ describe('Execute: Handles inputs', () => { }); }); + it('errors on faulty scalar type input', () => { + const params = { input: { c: 'foo', e: 'SerializedValue' } }; + const result = executeQuery(doc, params); + + expect(result.errors?.at(0)?.originalError).to.equal(TestFaultyScalarGraphQLError); + 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); diff --git a/src/execution/values.ts b/src/execution/values.ts index bbe3c99c8e..3ebe1be58e 100644 --- a/src/execution/values.ts +++ b/src/execution/values.ts @@ -131,7 +131,7 @@ function coerceVariableValues( onError( new GraphQLError(prefix + '; ' + error.message, { nodes: varDefNode, - originalError: error.originalError, + originalError: error, }), ); }, From 1219dec2c370039ad93e21bee62fecc48552075b Mon Sep 17 00:00:00 2001 From: Sten Reijers Date: Tue, 31 Jan 2023 09:11:21 +0100 Subject: [PATCH 2/3] chore: retrigger the CI pipeline of github for easyCLA --- src/execution/__tests__/variables-test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/execution/__tests__/variables-test.ts b/src/execution/__tests__/variables-test.ts index c0cda21997..28d3f06c49 100644 --- a/src/execution/__tests__/variables-test.ts +++ b/src/execution/__tests__/variables-test.ts @@ -32,7 +32,7 @@ const TestFaultyScalarGraphQLError = new GraphQLError( 'FaultyScalarErrorMessage', { extensions: { - code: 'FaultyScalarErrorMessageExtensionCode' + code: 'FaultyScalarErrorExtensionCode' } } ); @@ -421,7 +421,7 @@ describe('Execute: Handles inputs', () => { { message: 'Variable "$input" got invalid value "SerializedValue" at "input.e"; FaultyScalarErrorMessage', locations: [{ line: 2, column: 16 }], - extensions: { code: 'FaultyScalarErrorMessageExtensionCode' } + extensions: { code: 'FaultyScalarErrorExtensionCode' } } ] }); From a9823304b7440041e5af23ea0f94dab15fd1f72f Mon Sep 17 00:00:00 2001 From: Sten Reijers Date: Tue, 31 Jan 2023 12:43:52 +0100 Subject: [PATCH 3/3] fix: fixed test-case to run in older node versions and ran prettier --- src/execution/__tests__/variables-test.ts | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/execution/__tests__/variables-test.ts b/src/execution/__tests__/variables-test.ts index 28d3f06c49..6e4b39e810 100644 --- a/src/execution/__tests__/variables-test.ts +++ b/src/execution/__tests__/variables-test.ts @@ -32,9 +32,9 @@ const TestFaultyScalarGraphQLError = new GraphQLError( 'FaultyScalarErrorMessage', { extensions: { - code: 'FaultyScalarErrorExtensionCode' - } - } + code: 'FaultyScalarErrorExtensionCode', + }, + }, ); const TestFaultyScalar = new GraphQLScalarType({ @@ -66,7 +66,7 @@ const TestInputObject = new GraphQLInputObjectType({ b: { type: new GraphQLList(GraphQLString) }, c: { type: new GraphQLNonNull(GraphQLString) }, d: { type: TestComplexScalar }, - e: { type: TestFaultyScalar } + e: { type: TestFaultyScalar }, }, }); @@ -268,7 +268,6 @@ describe('Execute: Handles inputs', () => { }, ], }); - }); }); @@ -415,15 +414,15 @@ describe('Execute: Handles inputs', () => { const params = { input: { c: 'foo', e: 'SerializedValue' } }; const result = executeQuery(doc, params); - expect(result.errors?.at(0)?.originalError).to.equal(TestFaultyScalarGraphQLError); expectJSON(result).toDeepEqual({ errors: [ { - message: 'Variable "$input" got invalid value "SerializedValue" at "input.e"; FaultyScalarErrorMessage', + message: + 'Variable "$input" got invalid value "SerializedValue" at "input.e"; FaultyScalarErrorMessage', locations: [{ line: 2, column: 16 }], - extensions: { code: 'FaultyScalarErrorExtensionCode' } - } - ] + extensions: { code: 'FaultyScalarErrorExtensionCode' }, + }, + ], }); });