1
1
from ..language import ast
2
2
from ..type import (GraphQLEnumType , GraphQLInputObjectType , GraphQLList ,
3
3
GraphQLNonNull , GraphQLScalarType )
4
- from .undefined import Undefined
5
4
6
5
7
6
def value_from_ast (value_ast , type , variables = None ):
@@ -12,20 +11,17 @@ def value_from_ast(value_ast, type, variables=None):
12
11
# We're assuming that this query has been validated and the value used here is of the correct type.
13
12
return value_from_ast (value_ast , type .of_type , variables )
14
13
15
- if value_ast is Undefined :
16
- return Undefined
17
-
18
14
if value_ast is None :
19
15
return None
20
16
21
17
if isinstance (value_ast , ast .Variable ):
22
18
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
25
21
26
22
# Note: we're not doing any checking that this variable is correct. We're assuming that this query
27
23
# 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 )
29
25
30
26
if isinstance (type , GraphQLList ):
31
27
item_type = type .of_type
@@ -39,7 +35,7 @@ def value_from_ast(value_ast, type, variables=None):
39
35
if isinstance (type , GraphQLInputObjectType ):
40
36
fields = type .fields
41
37
if not isinstance (value_ast , ast .ObjectValue ):
42
- return Undefined
38
+ return None
43
39
44
40
field_asts = {}
45
41
@@ -48,30 +44,27 @@ def value_from_ast(value_ast, type, variables=None):
48
44
49
45
obj = {}
50
46
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
53
52
54
- if field_ast :
55
- field_value_ast = field_ast .value
53
+ continue
56
54
55
+ field_ast = field_asts .get (field_name )
56
+ field_value_ast = field_ast .value
57
57
field_value = value_from_ast (
58
58
field_value_ast , field .type , variables
59
59
)
60
- if field_value is Undefined and field .default_value is not None :
61
- field_value = field .default_value
62
60
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
67
64
68
65
return type .create_container (obj )
69
66
70
67
assert isinstance (type , (GraphQLScalarType , GraphQLEnumType )), \
71
68
'Must be input type'
72
69
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