@@ -42,54 +42,51 @@ import { GraphQLID } from '../type/scalars';
42
42
*
43
43
*/
44
44
export function astFromValue ( value : mixed , type : GraphQLInputType ) : ?ValueNode {
45
- // Ensure flow knows that we treat function params as const.
46
- const _value = value ;
47
-
48
45
if ( isNonNullType ( type ) ) {
49
- const astValue = astFromValue ( _value , type . ofType ) ;
46
+ const astValue = astFromValue ( value , type . ofType ) ;
50
47
if ( astValue && astValue . kind === Kind . NULL ) {
51
48
return null ;
52
49
}
53
50
return astValue ;
54
51
}
55
52
56
53
// only explicit null, not undefined, NaN
57
- if ( _value === null ) {
54
+ if ( value === null ) {
58
55
return { kind : Kind . NULL } ;
59
56
}
60
57
61
58
// undefined, NaN
62
- if ( isInvalid ( _value ) ) {
59
+ if ( isInvalid ( value ) ) {
63
60
return null ;
64
61
}
65
62
66
63
// Convert JavaScript array to GraphQL list. If the GraphQLType is a list, but
67
64
// the value is not an array, convert the value using the list's item type.
68
65
if ( isListType ( type ) ) {
69
66
const itemType = type . ofType ;
70
- if ( isCollection ( _value ) ) {
67
+ if ( isCollection ( value ) ) {
71
68
const valuesNodes = [ ] ;
72
- forEach ( ( _value : any ) , item => {
69
+ forEach ( ( value : any ) , item => {
73
70
const itemNode = astFromValue ( item , itemType ) ;
74
71
if ( itemNode ) {
75
72
valuesNodes . push ( itemNode ) ;
76
73
}
77
74
} ) ;
78
75
return { kind : Kind . LIST , values : valuesNodes } ;
79
76
}
80
- return astFromValue ( _value , itemType ) ;
77
+ return astFromValue ( value , itemType ) ;
81
78
}
82
79
83
80
// Populate the fields of the input object by creating ASTs from each value
84
81
// in the JavaScript object according to the fields in the input type.
85
82
if ( isInputObjectType ( type ) ) {
86
- if ( _value === null || typeof _value !== 'object' ) {
83
+ if ( value === null || typeof value !== 'object' ) {
87
84
return null ;
88
85
}
89
86
const fields = objectValues ( type . getFields ( ) ) ;
90
87
const fieldNodes = [ ] ;
91
88
fields . forEach ( field => {
92
- const fieldValue = astFromValue ( _value [ field . name ] , field . type ) ;
89
+ const fieldValue = astFromValue ( value [ field . name ] , field . type ) ;
93
90
if ( fieldValue ) {
94
91
fieldNodes . push ( {
95
92
kind : Kind . OBJECT_FIELD ,
@@ -104,7 +101,7 @@ export function astFromValue(value: mixed, type: GraphQLInputType): ?ValueNode {
104
101
if ( isScalarType ( type ) || isEnumType ( type ) ) {
105
102
// Since value is an internally represented value, it must be serialized
106
103
// to an externally represented value before converting into an AST.
107
- const serialized = type . serialize ( _value ) ;
104
+ const serialized = type . serialize ( value ) ;
108
105
if ( isNullish ( serialized ) ) {
109
106
return null ;
110
107
}
0 commit comments