@@ -20,6 +20,7 @@ import type { GraphQLDirective } from '../type/directives.js';
20
20
import type { GraphQLSchema } from '../type/schema.js' ;
21
21
22
22
import { coerceInputValue } from '../utilities/coerceInputValue.js' ;
23
+ import { getVariableSignature } from '../utilities/getVariableSignature.js' ;
23
24
import { typeFromAST } from '../utilities/typeFromAST.js' ;
24
25
import { valueFromAST } from '../utilities/valueFromAST.js' ;
25
26
import { valueFromASTUntyped } from '../utilities/valueFromASTUntyped.js' ;
@@ -86,24 +87,16 @@ function coerceVariableValues(
86
87
) : { [ variable : string ] : unknown } {
87
88
const coercedValues : { [ variable : string ] : unknown } = { } ;
88
89
for ( const varDefNode of varDefNodes ) {
89
- const varName = varDefNode . variable . name . value ;
90
- const varType = typeFromAST ( schema , varDefNode . type ) ;
91
- if ( ! isInputType ( varType ) ) {
92
- // Must use input types for variables. This should be caught during
93
- // validation, however is checked again here for safety.
94
- const varTypeStr = print ( varDefNode . type ) ;
95
- onError (
96
- new GraphQLError (
97
- `Variable "$${ varName } " expected value of type "${ varTypeStr } " which cannot be used as an input type.` ,
98
- { nodes : varDefNode . type } ,
99
- ) ,
100
- ) ;
90
+ const varSignature = getVariableSignature ( schema , varDefNode ) ;
91
+ if ( varSignature instanceof GraphQLError ) {
92
+ onError ( varSignature ) ;
101
93
continue ;
102
94
}
103
95
96
+ const { name : varName , type : varType } = varSignature ;
104
97
if ( ! Object . hasOwn ( inputs , varName ) ) {
105
98
if ( varDefNode . defaultValue ) {
106
- coercedValues [ varName ] = valueFromAST ( varDefNode . defaultValue , varType ) ;
99
+ coercedValues [ varName ] = varSignature . defaultValue ;
107
100
} else if ( isNonNullType ( varType ) ) {
108
101
const varTypeStr = inspect ( varType ) ;
109
102
onError (
0 commit comments