Skip to content

Commit e6cbb48

Browse files
committed
Raise TypeError instead of ValueError in format_error
We currently don't discern between assertions with invariant, devAssert and explicitly thrown errors, but always raise errors explicitly. Maybe revisit this: graphql/graphql-js@ebcc754
1 parent aa1ce98 commit e6cbb48

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

src/graphql/error/format_error.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def format_error(error: "GraphQLError") -> Dict[str, Any]:
1414
Format, Errors" section of the GraphQL Specification.
1515
"""
1616
if not error:
17-
raise ValueError("Received null or undefined error.")
17+
raise TypeError("Received no error object.")
1818
formatted: Dict[str, Any] = dict( # noqa: E701 (pycqa/flake8#394)
1919
message=error.message or "An unknown error occurred.",
2020
locations=error.locations,

src/graphql/execution/execute.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ def complete_list_value(
794794
Complete a list value by completing each item in the list with the inner type.
795795
"""
796796
if not isinstance(result, Iterable) or isinstance(result, str):
797-
raise TypeError(
797+
raise GraphQLError(
798798
"Expected Iterable, but did not find one for field"
799799
f" {info.parent_type.name}.{info.field_name}."
800800
)

src/graphql/utilities/build_client_schema.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,21 +95,21 @@ def get_named_type(type_name: str) -> GraphQLNamedType:
9595

9696
def get_input_type(type_ref: Dict) -> GraphQLInputType:
9797
input_type = get_type(type_ref)
98-
if not is_input_type(input_type):
99-
raise TypeError(
100-
"Introspection must provide input type for arguments,"
101-
f" but received: {inspect(input_type)}."
102-
)
103-
return cast(GraphQLInputType, input_type)
98+
if is_input_type(input_type):
99+
return cast(GraphQLInputType, input_type)
100+
raise TypeError(
101+
"Introspection must provide input type for arguments,"
102+
f" but received: {inspect(input_type)}."
103+
)
104104

105105
def get_output_type(type_ref: Dict) -> GraphQLOutputType:
106106
output_type = get_type(type_ref)
107-
if not is_output_type(output_type):
108-
raise TypeError(
109-
"Introspection must provide output type for fields,"
110-
f" but received: {inspect(output_type)}."
111-
)
112-
return cast(GraphQLOutputType, output_type)
107+
if is_output_type(output_type):
108+
return cast(GraphQLOutputType, output_type)
109+
raise TypeError(
110+
"Introspection must provide output type for fields,"
111+
f" but received: {inspect(output_type)}."
112+
)
113113

114114
def get_object_type(type_ref: Dict) -> GraphQLObjectType:
115115
object_type = get_type(type_ref)

tests/error/test_format_error.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
def describe_format_error():
88
def throw_if_not_an_error():
9-
with raises(ValueError):
9+
with raises(TypeError):
1010
# noinspection PyTypeChecker
1111
format_error(None)
1212

0 commit comments

Comments
 (0)