11from ..language import ast
22from ..type import (GraphQLEnumType , GraphQLInputObjectType , GraphQLList ,
33 GraphQLNonNull , GraphQLScalarType )
4- from .undefined import Undefined
54
65
76def 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