@@ -29,6 +29,7 @@ import {
29
29
GraphQLList ,
30
30
GraphQLNonNull ,
31
31
} from '../type/definition' ;
32
+ import type { ObjMap } from '../jsutils/ObjMap' ;
32
33
import type {
33
34
GraphQLInputType ,
34
35
GraphQLField
@@ -47,13 +48,17 @@ import type {
47
48
* Prepares an object map of variableValues of the correct type based on the
48
49
* provided variable definitions and arbitrary input. If the input cannot be
49
50
* parsed to match the variable definitions, a GraphQLError will be thrown.
51
+ *
52
+ * Note: The returned value is a plain Object with a prototype, since it is
53
+ * exposed to user code. Care should be taken to not pull values from the
54
+ * Object prototype.
50
55
*/
51
56
export function getVariableValues (
52
57
schema : GraphQLSchema ,
53
58
varDefNodes : Array < VariableDefinitionNode > ,
54
- inputs : { [ key : string ] : mixed , __proto__ : null }
55
- ) : { [ key : string ] : mixed , __proto__ : null } {
56
- const coercedValues = Object . create ( null ) ;
59
+ inputs : ObjMap < mixed >
60
+ ) : { [ variable : string ] : mixed } {
61
+ const coercedValues = { } ;
57
62
for ( let i = 0 ; i < varDefNodes . length ; i ++ ) {
58
63
const varDefNode = varDefNodes [ i ] ;
59
64
const varName = varDefNode . variable . name . value ;
@@ -101,18 +106,22 @@ export function getVariableValues(
101
106
/**
102
107
* Prepares an object map of argument values given a list of argument
103
108
* definitions and list of argument AST nodes.
109
+ *
110
+ * Note: The returned value is a plain Object with a prototype, since it is
111
+ * exposed to user code. Care should be taken to not pull values from the
112
+ * Object prototype.
104
113
*/
105
114
export function getArgumentValues (
106
115
def : GraphQLField < * , * > | GraphQLDirective ,
107
116
node : FieldNode | DirectiveNode ,
108
- variableValues ?: ?{ [ key : string ] : mixed , __proto__ : null }
109
- ) : { [ key : string ] : mixed , __proto__ : null } {
117
+ variableValues ?: ?ObjMap < mixed >
118
+ ) : { [ argument : string ] : mixed } {
119
+ const coercedValues = { } ;
110
120
const argDefs = def . args ;
111
121
const argNodes = node . arguments ;
112
122
if ( ! argDefs || ! argNodes ) {
113
- return { } ;
123
+ return coercedValues ;
114
124
}
115
- const coercedValues = Object . create ( null ) ;
116
125
const argNodeMap = keyMap ( argNodes , arg => arg . name . value ) ;
117
126
for ( let i = 0 ; i < argDefs . length ; i ++ ) {
118
127
const argDef = argDefs [ i ] ;
@@ -132,7 +141,11 @@ export function getArgumentValues(
132
141
}
133
142
} else if ( argumentNode . value . kind === Kind . VARIABLE ) {
134
143
const variableName = ( argumentNode . value : VariableNode ) . name . value ;
135
- if ( variableValues && ! isInvalid ( variableValues [ variableName ] ) ) {
144
+ if (
145
+ variableValues &&
146
+ Object . prototype . hasOwnProperty . call ( variableValues , variableName ) &&
147
+ ! isInvalid ( variableValues [ variableName ] )
148
+ ) {
136
149
// Note: this does not check that this variable value is correct.
137
150
// This assumes that this query has been validated and the variable
138
151
// usage here is of the correct type.
@@ -170,12 +183,16 @@ export function getArgumentValues(
170
183
* of variable values.
171
184
*
172
185
* If the directive does not exist on the node, returns undefined.
186
+ *
187
+ * Note: The returned value is a plain Object with a prototype, since it is
188
+ * exposed to user code. Care should be taken to not pull values from the
189
+ * Object prototype.
173
190
*/
174
191
export function getDirectiveValues (
175
192
directiveDef : GraphQLDirective ,
176
193
node : { directives ?: ?Array < DirectiveNode > } ,
177
- variableValues ?: ?{ [ key : string ] : mixed , __proto__ : null }
178
- ) : void | { [ key : string ] : mixed , __proto__ : null } {
194
+ variableValues ?: ?ObjMap < mixed >
195
+ ) : void | { [ argument : string ] : mixed } {
179
196
const directiveNode = node . directives && find (
180
197
node . directives ,
181
198
directive => directive . name . value === directiveDef . name
0 commit comments