@@ -20,10 +20,8 @@ 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 {
24
- getVariableSignature ,
25
- GraphQLVariableSignature ,
26
- } from '../utilities/getVariableSignature.js' ;
23
+ import type { GraphQLVariableSignature } from '../utilities/getVariableSignature.js' ;
24
+ import { getVariableSignature } from '../utilities/getVariableSignature.js' ;
27
25
import { valueFromAST } from '../utilities/valueFromAST.js' ;
28
26
29
27
import type { FragmentVariables } from './collectFields.js' ;
@@ -90,8 +88,8 @@ function coerceVariableValues(
90
88
91
89
const { name : varName , type : varType } = varSignature ;
92
90
if ( ! Object . hasOwn ( inputs , varName ) ) {
93
- if ( varSignature . hasDefaultValue ) {
94
- coercedValues [ varName ] = varSignature . getDefaultValue ( ) ;
91
+ if ( varDefNode . defaultValue ) {
92
+ coercedValues [ varName ] = varSignature . defaultValue ;
95
93
} else if ( isNonNullType ( varType ) ) {
96
94
const varTypeStr = inspect ( varType ) ;
97
95
onError (
@@ -173,9 +171,8 @@ export function experimentalGetArgumentValues(
173
171
const argumentNode = argNodeMap . get ( name ) ;
174
172
175
173
if ( argumentNode == null ) {
176
- const defaultValue = getDefaultValue ( argDef ) ;
177
- if ( defaultValue !== undefined ) {
178
- coercedValues [ name ] = defaultValue ;
174
+ if ( argDef . defaultValue !== undefined ) {
175
+ coercedValues [ name ] = argDef . defaultValue ;
179
176
} else if ( isNonNullType ( argType ) ) {
180
177
throw new GraphQLError (
181
178
`Argument "${ name } " of required type "${ inspect ( argType ) } " ` +
@@ -193,27 +190,25 @@ export function experimentalGetArgumentValues(
193
190
const variableName = valueNode . name . value ;
194
191
if ( fragmentVariables ?. signatures [ variableName ] ) {
195
192
hasValue = fragmentVariables . values [ variableName ] != null ;
196
- const defaultValue = getDefaultValue ( argDef ) ;
197
- if ( ! hasValue && defaultValue !== undefined ) {
198
- coercedValues [ name ] = defaultValue ;
193
+ if ( ! hasValue && argDef . defaultValue !== undefined ) {
194
+ coercedValues [ name ] = argDef . defaultValue ;
199
195
continue ;
200
196
}
201
197
} else if (
202
198
variableValues != null &&
203
199
Object . hasOwn ( variableValues , variableName )
204
200
) {
205
201
hasValue = variableValues [ variableName ] != null ;
202
+ } else if ( argDef . defaultValue !== undefined ) {
203
+ coercedValues [ name ] = argDef . defaultValue ;
204
+ continue ;
205
+ } else if ( isNonNullType ( argType ) ) {
206
+ throw new GraphQLError (
207
+ `Argument "${ name } " of required type "${ inspect ( argType ) } " ` +
208
+ `was provided the variable "$${ variableName } " which was not provided a runtime value.` ,
209
+ { nodes : valueNode } ,
210
+ ) ;
206
211
} else {
207
- const defaultValue = getDefaultValue ( argDef ) ;
208
- if ( defaultValue !== undefined ) {
209
- coercedValues [ name ] = defaultValue ;
210
- } else if ( isNonNullType ( argType ) ) {
211
- throw new GraphQLError (
212
- `Argument "${ name } " of required type "${ inspect ( argType ) } " ` +
213
- `was provided the variable "$${ variableName } " which was not provided a runtime value.` ,
214
- { nodes : valueNode } ,
215
- ) ;
216
- }
217
212
continue ;
218
213
}
219
214
}
@@ -246,14 +241,6 @@ export function experimentalGetArgumentValues(
246
241
return coercedValues ;
247
242
}
248
243
249
- function getDefaultValue (
250
- arg : GraphQLArgument | GraphQLVariableSignature ,
251
- ) : unknown {
252
- return arg instanceof GraphQLVariableSignature
253
- ? arg . getDefaultValue ( )
254
- : arg . defaultValue ;
255
- }
256
-
257
244
/**
258
245
* Prepares an object map of argument values given a directive definition
259
246
* and a AST node which may contain directives. Optionally also accepts a map
0 commit comments