@@ -14,12 +14,12 @@ import { Kind } from '../language/kinds.js';
14
14
import { print } from '../language/printer.js' ;
15
15
16
16
import type { GraphQLField } from '../type/definition.js' ;
17
- import { isInputType , isNonNullType } from '../type/definition.js' ;
17
+ import { isNonNullType } from '../type/definition.js' ;
18
18
import type { GraphQLDirective } from '../type/directives.js' ;
19
19
import type { GraphQLSchema } from '../type/schema.js' ;
20
20
21
21
import { coerceInputValue } from '../utilities/coerceInputValue.js' ;
22
- import { typeFromAST } from '../utilities/typeFromAST .js' ;
22
+ import { getVariableSignature } from '../utilities/getVariableSignature .js' ;
23
23
import { valueFromAST } from '../utilities/valueFromAST.js' ;
24
24
25
25
type CoercedVariableValues =
@@ -76,24 +76,16 @@ function coerceVariableValues(
76
76
) : { [ variable : string ] : unknown } {
77
77
const coercedValues : { [ variable : string ] : unknown } = { } ;
78
78
for ( const varDefNode of varDefNodes ) {
79
- const varName = varDefNode . variable . name . value ;
80
- const varType = typeFromAST ( schema , varDefNode . type ) ;
81
- if ( ! isInputType ( varType ) ) {
82
- // Must use input types for variables. This should be caught during
83
- // validation, however is checked again here for safety.
84
- const varTypeStr = print ( varDefNode . type ) ;
85
- onError (
86
- new GraphQLError (
87
- `Variable "$${ varName } " expected value of type "${ varTypeStr } " which cannot be used as an input type.` ,
88
- { nodes : varDefNode . type } ,
89
- ) ,
90
- ) ;
79
+ const varSignature = getVariableSignature ( schema , varDefNode ) ;
80
+ if ( varSignature instanceof GraphQLError ) {
81
+ onError ( varSignature ) ;
91
82
continue ;
92
83
}
93
84
85
+ const { name : varName , type : varType } = varSignature ;
94
86
if ( ! Object . hasOwn ( inputs , varName ) ) {
95
87
if ( varDefNode . defaultValue ) {
96
- coercedValues [ varName ] = valueFromAST ( varDefNode . defaultValue , varType ) ;
88
+ coercedValues [ varName ] = varSignature . defaultValue ;
97
89
} else if ( isNonNullType ( varType ) ) {
98
90
const varTypeStr = inspect ( varType ) ;
99
91
onError (
0 commit comments