@@ -20,6 +20,7 @@ import type { GraphQLDirective } from '../type/directives.js';
2020import type { GraphQLSchema } from '../type/schema.js' ;
2121
2222import { coerceInputValue } from '../utilities/coerceInputValue.js' ;
23+ import { getVariableSignature } from '../utilities/getVariableSignature.js' ;
2324import { typeFromAST } from '../utilities/typeFromAST.js' ;
2425import { valueFromAST } from '../utilities/valueFromAST.js' ;
2526import { valueFromASTUntyped } from '../utilities/valueFromASTUntyped.js' ;
@@ -86,24 +87,16 @@ function coerceVariableValues(
8687) : { [ variable : string ] : unknown } {
8788 const coercedValues : { [ variable : string ] : unknown } = { } ;
8889 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 ) ;
10193 continue ;
10294 }
10395
96+ const { name : varName , type : varType } = varSignature ;
10497 if ( ! Object . hasOwn ( inputs , varName ) ) {
10598 if ( varDefNode . defaultValue ) {
106- coercedValues [ varName ] = valueFromAST ( varDefNode . defaultValue , varType ) ;
99+ coercedValues [ varName ] = varSignature . defaultValue ;
107100 } else if ( isNonNullType ( varType ) ) {
108101 const varTypeStr = inspect ( varType ) ;
109102 onError (
0 commit comments