@@ -42,6 +42,7 @@ import type {
42
42
* | String | String |
43
43
* | Int / Float | Number |
44
44
* | Enum Value | Mixed |
45
+ * | NullValue | null |
45
46
*
46
47
*/
47
48
export function valueFromAST (
@@ -57,13 +58,17 @@ export function valueFromAST(
57
58
}
58
59
59
60
if ( ! valueAST ) {
61
+ return;
62
+ }
63
+
64
+ if ( valueAST . kind === Kind . NULL ) {
60
65
return null ;
61
66
}
62
67
63
68
if ( valueAST . kind === Kind . VARIABLE ) {
64
69
const variableName = ( valueAST : Variable ) . name . value ;
65
70
if ( ! variables || ! variables . hasOwnProperty ( variableName ) ) {
66
- return null ;
71
+ return;
67
72
}
68
73
// Note: we're not doing any checking that this variable is correct. We're
69
74
// assuming that this query has been validated and the variable usage here
@@ -83,7 +88,7 @@ export function valueFromAST(
83
88
84
89
if ( type instanceof GraphQLInputObjectType ) {
85
90
if ( valueAST . kind !== Kind . OBJECT ) {
86
- return null ;
91
+ return ;
87
92
}
88
93
const fields = type . getFields ( ) ;
89
94
const fieldASTs = keyMap (
@@ -93,13 +98,14 @@ export function valueFromAST(
93
98
return Object . keys ( fields ) . reduce ( ( obj , fieldName ) => {
94
99
const field = fields [ fieldName ] ;
95
100
const fieldAST = fieldASTs [ fieldName ] ;
96
- let fieldValue =
101
+ const fieldValue =
97
102
valueFromAST ( fieldAST && fieldAST . value , field . type , variables ) ;
98
- if ( isNullish ( fieldValue ) ) {
99
- fieldValue = field . defaultValue ;
100
- }
101
- if ( ! isNullish ( fieldValue ) ) {
103
+ if ( fieldValue === null ) {
104
+ obj [ fieldName ] = fieldValue ;
105
+ } else if ( ! isNullish ( fieldValue ) ) {
102
106
obj [ fieldName ] = fieldValue ;
107
+ } else if ( fieldValue !== null ) {
108
+ obj [ fieldName ] = field . defaultValue ;
103
109
}
104
110
return obj ;
105
111
} , { } ) ;
@@ -111,6 +117,7 @@ export function valueFromAST(
111
117
) ;
112
118
113
119
const parsed = type . parseLiteral ( valueAST ) ;
120
+ // TODO: Should be this condition ommited?
114
121
if ( ! isNullish ( parsed ) ) {
115
122
return parsed ;
116
123
}
0 commit comments