Skip to content

Commit aca5711

Browse files
committed
Removed unnecessary undefined vars
1 parent cf672bc commit aca5711

File tree

2 files changed

+19
-34
lines changed

2 files changed

+19
-34
lines changed

graphql/execution/values.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from ..utils.is_valid_value import is_valid_value
1212
from ..utils.type_from_ast import type_from_ast
1313
from ..utils.value_from_ast import value_from_ast
14-
from ..utils.undefined import Undefined
1514

1615
__all__ = ['get_variable_values', 'get_argument_values']
1716

@@ -92,7 +91,7 @@ def get_argument_values(arg_defs, arg_asts, variables=None):
9291
), arg_asts)
9392
elif isinstance(value_ast.value, ast.Variable):
9493
variable_name = value_ast.value.name.value
95-
variable_value = variables.get(variable_name, Undefined)
94+
variable_value = variables.get(variable_name)
9695
if variables and variable_name in variables:
9796
result[arg_def.out_name or name] = variable_value
9897
elif arg_def.default_value is not None:
@@ -113,7 +112,7 @@ def get_argument_values(arg_defs, arg_asts, variables=None):
113112
arg_type,
114113
variables
115114
)
116-
if value is Undefined:
115+
if value is None:
117116
if arg_def.default_value is not None:
118117
value = arg_def.default_value
119118
result[arg_def.out_name or name] = value
@@ -133,9 +132,6 @@ def coerce_value(type, value):
133132
# We only call this function after calling isValidValue.
134133
return coerce_value(type.of_type, value)
135134

136-
if value is Undefined:
137-
return Undefined
138-
139135
if value is None:
140136
return None
141137

@@ -163,8 +159,4 @@ def coerce_value(type, value):
163159
assert isinstance(type, (GraphQLScalarType, GraphQLEnumType)), \
164160
'Must be input type'
165161

166-
parsed = type.parse_value(value)
167-
if parsed is None:
168-
return Undefined
169-
170-
return parsed
162+
return type.parse_value(value)

graphql/utils/value_from_ast.py

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from ..language import ast
22
from ..type import (GraphQLEnumType, GraphQLInputObjectType, GraphQLList,
33
GraphQLNonNull, GraphQLScalarType)
4-
from .undefined import Undefined
54

65

76
def value_from_ast(value_ast, type, variables=None):
@@ -12,20 +11,17 @@ def value_from_ast(value_ast, type, variables=None):
1211
# We're assuming that this query has been validated and the value used here is of the correct type.
1312
return value_from_ast(value_ast, type.of_type, variables)
1413

15-
if value_ast is Undefined:
16-
return Undefined
17-
1814
if value_ast is None:
1915
return None
2016

2117
if isinstance(value_ast, ast.Variable):
2218
variable_name = value_ast.name.value
23-
if not variables:
24-
return Undefined
19+
if not variables or variable_name not in variables:
20+
return None
2521

2622
# Note: we're not doing any checking that this variable is correct. We're assuming that this query
2723
# has been validated and the variable usage here is of the correct type.
28-
return variables.get(variable_name, Undefined)
24+
return variables.get(variable_name)
2925

3026
if isinstance(type, GraphQLList):
3127
item_type = type.of_type
@@ -39,7 +35,7 @@ def value_from_ast(value_ast, type, variables=None):
3935
if isinstance(type, GraphQLInputObjectType):
4036
fields = type.fields
4137
if not isinstance(value_ast, ast.ObjectValue):
42-
return Undefined
38+
return None
4339

4440
field_asts = {}
4541

@@ -48,30 +44,27 @@ def value_from_ast(value_ast, type, variables=None):
4844

4945
obj = {}
5046
for field_name, field in fields.items():
51-
field_ast = field_asts.get(field_name, Undefined)
52-
field_value_ast = Undefined
47+
if field_name not in field_asts:
48+
if field.default_value is not None:
49+
# We use out_name as the output name for the
50+
# dict if exists
51+
obj[field.out_name or field_name] = field.default_value
5352

54-
if field_ast:
55-
field_value_ast = field_ast.value
53+
continue
5654

55+
field_ast = field_asts.get(field_name)
56+
field_value_ast = field_ast.value
5757
field_value = value_from_ast(
5858
field_value_ast, field.type, variables
5959
)
60-
if field_value is Undefined and field.default_value is not None:
61-
field_value = field.default_value
6260

63-
if field_value is not Undefined:
64-
# We use out_name as the output name for the
65-
# dict if exists
66-
obj[field.out_name or field_name] = field_value
61+
# We use out_name as the output name for the
62+
# dict if exists
63+
obj[field.out_name or field_name] = field_value
6764

6865
return type.create_container(obj)
6966

7067
assert isinstance(type, (GraphQLScalarType, GraphQLEnumType)), \
7168
'Must be input type'
7269

73-
value = type.parse_literal(value_ast)
74-
if value is None:
75-
return Undefined
76-
77-
return value
70+
return type.parse_literal(value_ast)

0 commit comments

Comments
 (0)