@@ -8,7 +8,6 @@ import type {
88 ObjectFieldNode ,
99 ObjectValueNode ,
1010 ValueNode ,
11- VariableDefinitionNode ,
1211} from '../../language/ast.js' ;
1312import { Kind } from '../../language/kinds.js' ;
1413import { print } from '../../language/printer.js' ;
@@ -40,17 +39,7 @@ import type { ValidationContext } from '../ValidationContext.js';
4039export function ValuesOfCorrectTypeRule (
4140 context : ValidationContext ,
4241) : ASTVisitor {
43- let variableDefinitions : { [ key : string ] : VariableDefinitionNode } = { } ;
44-
4542 return {
46- OperationDefinition : {
47- enter ( ) {
48- variableDefinitions = { } ;
49- } ,
50- } ,
51- VariableDefinition ( definition ) {
52- variableDefinitions [ definition . variable . name . value ] = definition ;
53- } ,
5443 ListValue ( node ) {
5544 // Note: TypeInfo will traverse into a list's item type, so look to the
5645 // parent input type to check if it is a list.
@@ -84,13 +73,7 @@ export function ValuesOfCorrectTypeRule(
8473 }
8574
8675 if ( type . isOneOf ) {
87- validateOneOfInputObject (
88- context ,
89- node ,
90- type ,
91- fieldNodeMap ,
92- variableDefinitions ,
93- ) ;
76+ validateOneOfInputObject ( context , node , type , fieldNodeMap ) ;
9477 }
9578 } ,
9679 ObjectField ( node ) {
@@ -189,7 +172,6 @@ function validateOneOfInputObject(
189172 node : ObjectValueNode ,
190173 type : GraphQLInputObjectType ,
191174 fieldNodeMap : Map < string , ObjectFieldNode > ,
192- variableDefinitions : { [ key : string ] : VariableDefinitionNode } ,
193175) : void {
194176 const keys = Array . from ( fieldNodeMap . keys ( ) ) ;
195177 const isNotExactlyOneField = keys . length !== 1 ;
@@ -206,29 +188,12 @@ function validateOneOfInputObject(
206188
207189 const value = fieldNodeMap . get ( keys [ 0 ] ) ?. value ;
208190 const isNullLiteral = ! value || value . kind === Kind . NULL ;
209- const isVariable = value ?. kind === Kind . VARIABLE ;
210191
211192 if ( isNullLiteral ) {
212193 context . reportError (
213194 new GraphQLError ( `Field "${ type } .${ keys [ 0 ] } " must be non-null.` , {
214195 nodes : [ node ] ,
215196 } ) ,
216197 ) ;
217- return ;
218- }
219-
220- if ( isVariable ) {
221- const variableName = value . name . value ;
222- const definition = variableDefinitions [ variableName ] ;
223- const isNullableVariable = definition . type . kind !== Kind . NON_NULL_TYPE ;
224-
225- if ( isNullableVariable ) {
226- context . reportError (
227- new GraphQLError (
228- `Variable "$${ variableName } " must be non-nullable to be used for OneOf Input Object "${ type } ".` ,
229- { nodes : [ node ] } ,
230- ) ,
231- ) ;
232- }
233198 }
234199}
0 commit comments