@@ -8,7 +8,6 @@ import type {
8
8
ObjectFieldNode ,
9
9
ObjectValueNode ,
10
10
ValueNode ,
11
- VariableDefinitionNode ,
12
11
} from '../../language/ast.js' ;
13
12
import { Kind } from '../../language/kinds.js' ;
14
13
import { print } from '../../language/printer.js' ;
@@ -38,17 +37,7 @@ import type { ValidationContext } from '../ValidationContext.js';
38
37
export function ValuesOfCorrectTypeRule (
39
38
context : ValidationContext ,
40
39
) : ASTVisitor {
41
- let variableDefinitions : { [ key : string ] : VariableDefinitionNode } = { } ;
42
-
43
40
return {
44
- OperationDefinition : {
45
- enter ( ) {
46
- variableDefinitions = { } ;
47
- } ,
48
- } ,
49
- VariableDefinition ( definition ) {
50
- variableDefinitions [ definition . variable . name . value ] = definition ;
51
- } ,
52
41
ListValue ( node ) {
53
42
// Note: TypeInfo will traverse into a list's item type, so look to the
54
43
// parent input type to check if it is a list.
@@ -82,13 +71,7 @@ export function ValuesOfCorrectTypeRule(
82
71
}
83
72
84
73
if ( type . isOneOf ) {
85
- validateOneOfInputObject (
86
- context ,
87
- node ,
88
- type ,
89
- fieldNodeMap ,
90
- variableDefinitions ,
91
- ) ;
74
+ validateOneOfInputObject ( context , node , type , fieldNodeMap ) ;
92
75
}
93
76
} ,
94
77
ObjectField ( node ) {
@@ -185,7 +168,6 @@ function validateOneOfInputObject(
185
168
node : ObjectValueNode ,
186
169
type : GraphQLInputObjectType ,
187
170
fieldNodeMap : Map < string , ObjectFieldNode > ,
188
- variableDefinitions : { [ key : string ] : VariableDefinitionNode } ,
189
171
) : void {
190
172
const keys = Array . from ( fieldNodeMap . keys ( ) ) ;
191
173
const isNotExactlyOneField = keys . length !== 1 ;
@@ -202,29 +184,12 @@ function validateOneOfInputObject(
202
184
203
185
const value = fieldNodeMap . get ( keys [ 0 ] ) ?. value ;
204
186
const isNullLiteral = ! value || value . kind === Kind . NULL ;
205
- const isVariable = value ?. kind === Kind . VARIABLE ;
206
187
207
188
if ( isNullLiteral ) {
208
189
context . reportError (
209
190
new GraphQLError ( `Field "${ type } .${ keys [ 0 ] } " must be non-null.` , {
210
191
nodes : [ node ] ,
211
192
} ) ,
212
193
) ;
213
- return ;
214
- }
215
-
216
- if ( isVariable ) {
217
- const variableName = value . name . value ;
218
- const definition = variableDefinitions [ variableName ] ;
219
- const isNullableVariable = definition . type . kind !== Kind . NON_NULL_TYPE ;
220
-
221
- if ( isNullableVariable ) {
222
- context . reportError (
223
- new GraphQLError (
224
- `Variable "$${ variableName } " must be non-nullable to be used for OneOf Input Object "${ type } ".` ,
225
- { nodes : [ node ] } ,
226
- ) ,
227
- ) ;
228
- }
229
194
}
230
195
}
0 commit comments