Skip to content

Commit 32bf766

Browse files
committed
change 'CoercedVariableValues' to disjoint union
Replicates graphql/graphql-js@168570f
1 parent cbdf495 commit 32bf766

File tree

2 files changed

+6
-16
lines changed

2 files changed

+6
-16
lines changed

src/graphql/execution/execute.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -278,20 +278,16 @@ def build(
278278
raw_variable_values or {},
279279
)
280280

281-
if coerced_variable_values.errors:
282-
return coerced_variable_values.errors
283-
284-
variable_values = coerced_variable_values.coerced
285-
if variable_values is None:
286-
raise TypeError("Has variables if no errors.")
281+
if isinstance(coerced_variable_values, list):
282+
return coerced_variable_values # errors
287283

288284
return cls(
289285
schema,
290286
fragments,
291287
root_value,
292288
context_value,
293289
operation,
294-
variable_values,
290+
coerced_variable_values, # coerced values
295291
field_resolver or default_field_resolver,
296292
type_resolver or default_type_resolver,
297293
[],

src/graphql/execution/values.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Dict, List, NamedTuple, Optional, Union, cast
1+
from typing import Any, Dict, List, Optional, Union, cast
22

33
from ..error import GraphQLError, INVALID
44
from ..language import (
@@ -28,9 +28,7 @@
2828
__all__ = ["get_variable_values", "get_argument_values", "get_directive_values"]
2929

3030

31-
class CoercedVariableValues(NamedTuple):
32-
errors: Optional[List[GraphQLError]]
33-
coerced: Optional[Dict[str, Any]]
31+
CoercedVariableValues = Union[List[GraphQLError], Dict[str, Any]]
3432

3533

3634
def get_variable_values(
@@ -105,11 +103,7 @@ def get_variable_values(
105103

106104
coerced_values[var_name] = coerced.value
107105

108-
return (
109-
CoercedVariableValues(errors, None)
110-
if errors
111-
else CoercedVariableValues(None, coerced_values)
112-
)
106+
return errors or coerced_values
113107

114108

115109
def get_argument_values(

0 commit comments

Comments
 (0)