Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8f8102f

Browse files
committed
fix: invalid original_error propagation in custom scalars
Replicates graphql/graphql-js@76e47fc
1 parent 921d566 commit 8f8102f

File tree

2 files changed

+61
-3
lines changed

2 files changed

+61
-3
lines changed

‎src/graphql/execution/values.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def on_input_value_error(
136136
GraphQLError(
137137
prefix + "; " + error.message,
138138
var_def_node, # noqa: B023
139-
original_error=error.original_error,
139+
original_error=error,
140140
)
141141
)
142142

‎tests/execution/test_variables.py

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from math import nan
22
from typing import Any, Dict, Optional
33

4+
from graphql.error import GraphQLError
45
from graphql.execution import ExecutionResult, execute_sync
56
from graphql.execution.values import get_variable_values
67
from graphql.language import OperationDefinitionNode, StringValueNode, ValueNode, parse
@@ -21,6 +22,25 @@
2122
GraphQLString,
2223
)
2324

25+
TestFaultyScalarGraphQLError = GraphQLError(
26+
"FaultyScalarErrorMessage", extensions={"code": "FaultyScalarExtensionCode"}
27+
)
28+
29+
30+
def faulty_parse_value(value: str) -> str:
31+
raise TestFaultyScalarGraphQLError
32+
33+
34+
def faulty_parse_literal(ast: ValueNode, _variables=None) -> str:
35+
raise TestFaultyScalarGraphQLError
36+
37+
38+
TestFaultyScalar = GraphQLScalarType(
39+
name="FaultyScalar",
40+
parse_value=faulty_parse_value,
41+
parse_literal=faulty_parse_literal,
42+
)
43+
2444

2545
def parse_serialized_value(value: str) -> str:
2646
assert value == "SerializedValue"
@@ -47,6 +67,7 @@ def parse_literal_value(ast: ValueNode, _variables=None) -> str:
4767
"b": GraphQLInputField(GraphQLList(GraphQLString)),
4868
"c": GraphQLInputField(GraphQLNonNull(GraphQLString)),
4969
"d": GraphQLInputField(TestComplexScalar),
70+
"e": GraphQLInputField(TestFaultyScalar),
5071
},
5172
)
5273

@@ -253,6 +274,27 @@ def properly_runs_parse_literal_on_complex_scalar_types():
253274
None,
254275
)
255276

277+
def errors_on_faulty_scalar_type_input():
278+
result = execute_query(
279+
"""
280+
{
281+
fieldWithObjectInput(input: {c: "foo", e: "bar"})
282+
}
283+
"""
284+
)
285+
286+
assert result == (
287+
{"fieldWithObjectInput": None},
288+
[
289+
{
290+
"message": "Argument 'input' has invalid value"
291+
' { c: "foo", e: "bar" }.',
292+
"path": ["fieldWithObjectInput"],
293+
"locations": [(3, 51)],
294+
}
295+
],
296+
)
297+
256298
def describe_using_variables():
257299
doc = """
258300
query ($input: TestInputObject) {
@@ -365,6 +407,22 @@ def executes_with_complex_scalar_input():
365407
None,
366408
)
367409

410+
def errors_on_faulty_scalar_type_input():
411+
params = {"input": {"c": "foo", "e": "SerializedValue"}}
412+
result = execute_query(doc, params)
413+
414+
assert result == (
415+
None,
416+
[
417+
{
418+
"message": "Variable '$input' got invalid value"
419+
" 'SerializedValue' at 'input.e'; FaultyScalarErrorMessage",
420+
"locations": [(2, 24)],
421+
"extensions": {"code": "FaultyScalarExtensionCode"},
422+
}
423+
],
424+
)
425+
368426
def errors_on_null_for_nested_non_null():
369427
params = {"input": {"a": "foo", "b": "bar", "c": None}}
370428
result = execute_query(doc, params)
@@ -676,8 +734,8 @@ def reports_error_for_array_passed_into_string_input():
676734
)
677735

678736
errors = result.errors
679-
assert errorsisnotNone
680-
assert errors[0].original_errorisNone
737+
assert errors
738+
assert errors[0].original_error
681739

682740
def reports_error_for_non_provided_variables_for_non_nullable_inputs():
683741
# Note: this test would typically fail validation before

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /