Skip to content

Commit 7926c61

Browse files
committed
Switch argument ordering for core.utils.value_from_ast to match reference implementation.
1 parent b32819b commit 7926c61

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

graphql/core/execution/values.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ def get_argument_values(arg_defs, arg_asts, variables):
5151
value_ast = value_ast.value
5252

5353
value = value_from_ast(
54-
arg_def.type,
5554
value_ast,
55+
arg_def.type,
5656
variables
5757
)
5858

@@ -84,7 +84,8 @@ def get_variable_value(schema, definition_ast, input):
8484
if is_nullish(input):
8585
default_value = definition_ast.default_value
8686
if default_value:
87-
return value_from_ast(type, default_value, None)
87+
return value_from_ast(default_value, type)
88+
8889
return coerce_value(type, input)
8990

9091
if is_nullish(input):

graphql/core/utils/value_from_ast.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
from .is_nullish import is_nullish
44

55

6-
def value_from_ast(type, value_ast, variables):
6+
def value_from_ast(value_ast, type, variables=None):
77
"""Given a type and a value AST node known to match this type, build a
88
runtime value."""
99
if isinstance(type, GraphQLNonNull):
1010
# Note: we're not checking that the result of coerceValueAST is non-null.
1111
# We're assuming that this query has been validated and the value used here is of the correct type.
12-
return value_from_ast(type.of_type, value_ast, variables)
12+
return value_from_ast(value_ast, type.of_type, variables)
1313

1414
if not value_ast:
1515
return None
@@ -18,37 +18,46 @@ def value_from_ast(type, value_ast, variables):
1818
variable_name = value_ast.name.value
1919
if not variables or variable_name not in variables:
2020
return None
21+
2122
# Note: we're not doing any checking that this variable is correct. We're assuming that this query
2223
# has been validated and the variable usage here is of the correct type.
2324
return variables[variable_name]
2425

2526
if isinstance(type, GraphQLList):
2627
item_type = type.of_type
2728
if isinstance(value_ast, ast.ListValue):
28-
return [value_from_ast(item_type, item_ast, variables)
29+
return [value_from_ast(item_ast, item_type, variables)
2930
for item_ast in value_ast.values]
31+
3032
else:
31-
return [value_from_ast(item_type, value_ast, variables)]
33+
return [value_from_ast(value_ast, item_type, variables)]
3234

3335
if isinstance(type, GraphQLInputObjectType):
3436
fields = type.get_fields()
3537
if not isinstance(value_ast, ast.ObjectValue):
3638
return None
39+
3740
field_asts = {}
41+
3842
for field in value_ast.fields:
3943
field_asts[field.name.value] = field
44+
4045
obj = {}
4146
for field_name, field in fields.items():
4247
field_ast = field_asts.get(field_name)
4348
field_value_ast = None
49+
4450
if field_ast:
4551
field_value_ast = field_ast.value
52+
4653
field_value = value_from_ast(
47-
field.type, field_value_ast, variables
54+
field_value_ast, field.type, variables
4855
)
4956
if field_value is None:
5057
field_value = field.default_value
58+
5159
obj[field_name] = field_value
60+
5261
return obj
5362

5463
assert isinstance(type, (GraphQLScalarType, GraphQLEnumType)), \

0 commit comments

Comments
 (0)