1
- import { GraphQLError } from '../error/GraphQLError.js' ;
2
1
import { AccumulatorMap } from '../jsutils/AccumulatorMap.js' ;
3
- import { inspect } from '../jsutils/inspect.js' ;
4
2
import { invariant } from '../jsutils/invariant.js' ;
5
3
import type { ObjMap } from '../jsutils/ObjMap.js' ;
6
4
@@ -11,13 +9,11 @@ import type {
11
9
InlineFragmentNode ,
12
10
OperationDefinitionNode ,
13
11
SelectionSetNode ,
14
- ValueNode ,
15
12
} from '../language/ast.js' ;
16
13
import { OperationTypeNode } from '../language/ast.js' ;
17
14
import { Kind } from '../language/kinds.js' ;
18
15
19
16
import type { GraphQLObjectType } from '../type/definition.js' ;
20
- import { isInputType } from '../type/definition.js' ;
21
17
import { isAbstractType } from '../type/definition.js' ;
22
18
import {
23
19
GraphQLDeferDirective ,
@@ -27,10 +23,8 @@ import {
27
23
import type { GraphQLSchema } from '../type/schema.js' ;
28
24
29
25
import { typeFromAST } from '../utilities/typeFromAST.js' ;
30
- import { valueFromAST } from '../utilities/valueFromAST.js' ;
31
- import { valueFromASTUntyped } from '../utilities/valueFromASTUntyped.js' ;
32
26
33
- import { getDirectiveValues } from './values.js' ;
27
+ import { getDirectiveValues , getArgumentValuesFromSpread } from './values.js' ;
34
28
35
29
export interface DeferUsage {
36
30
label : string | undefined ;
@@ -224,57 +218,23 @@ function collectFieldsImpl(
224
218
// scope as that variable can still get used in spreads later on in the selectionSet.
225
219
// - when a value is passed in through the fragment-spread we need to copy over the key-value
226
220
// into our variable-values.
227
- if ( fragment . variableDefinitions ) {
228
- const rawVariables : ObjMap < unknown > = { } ;
229
-
230
- const argumentValueLookup = new Map < string , ValueNode > ( ) ;
231
- if ( selection . arguments ) {
232
- for ( const argument of selection . arguments ) {
233
- argumentValueLookup . set ( argument . name . value , argument . value ) ;
234
- }
235
- }
236
-
237
- for ( const variableDefinition of fragment . variableDefinitions ) {
238
- const variableName = variableDefinition . variable . name . value ;
239
- const value = argumentValueLookup . get ( variableName ) ;
240
- if ( value ) {
241
- const varType = typeFromAST ( context . schema , variableDefinition . type ) ;
242
- if ( varType && isInputType ( varType ) ) {
243
- const argumentValue = valueFromAST ( value , varType , { ...variableValues , ...fragmentVariableValues } ) ;
244
- if ( argumentValue !== undefined ) {
245
- rawVariables [ variableName ] = argumentValue
246
- continue ;
247
- } else {
248
- throw new GraphQLError (
249
- `Argument "${ variableName } " of required type "${ inspect ( varType ) } " ` +
250
- 'was not provided.' ,
251
- { nodes : selection } ,
252
- ) ;
253
- }
254
- }
255
- } else if ( variableDefinition . defaultValue ) {
256
- rawVariables [ variableName ] = valueFromASTUntyped ( variableDefinition . defaultValue , { ...variableValues , ...fragmentVariableValues } ) ;
257
- }
258
- }
259
-
260
- collectFieldsImpl (
261
- context ,
262
- fragment . selectionSet ,
263
- groupedFieldSet ,
264
- rawVariables ,
265
- parentDeferUsage ,
266
- newDeferUsage ?? deferUsage ,
267
- ) ;
268
- } else {
269
- collectFieldsImpl (
270
- context ,
271
- fragment . selectionSet ,
272
- groupedFieldSet ,
273
- undefined ,
274
- parentDeferUsage ,
275
- newDeferUsage ?? deferUsage ,
276
- ) ;
277
- }
221
+ const fragmentArgValues = fragment . variableDefinitions ? getArgumentValuesFromSpread (
222
+ selection ,
223
+ schema ,
224
+ fragment . variableDefinitions ,
225
+ variableValues ,
226
+ fragmentVariableValues ,
227
+ ) : undefined ;
228
+
229
+ collectFieldsImpl (
230
+ context ,
231
+ fragment . selectionSet ,
232
+ groupedFieldSet ,
233
+ fragmentArgValues ,
234
+ parentDeferUsage ,
235
+ newDeferUsage ?? deferUsage ,
236
+ ) ;
237
+
278
238
break ;
279
239
}
280
240
}
0 commit comments