1- import { GraphQLError } from '../error/GraphQLError.js' ;
21import { AccumulatorMap } from '../jsutils/AccumulatorMap.js' ;
3- import { inspect } from '../jsutils/inspect.js' ;
42import { invariant } from '../jsutils/invariant.js' ;
53import type { ObjMap } from '../jsutils/ObjMap.js' ;
64
@@ -11,13 +9,11 @@ import type {
119 InlineFragmentNode ,
1210 OperationDefinitionNode ,
1311 SelectionSetNode ,
14- ValueNode ,
1512} from '../language/ast.js' ;
1613import { OperationTypeNode } from '../language/ast.js' ;
1714import { Kind } from '../language/kinds.js' ;
1815
1916import type { GraphQLObjectType } from '../type/definition.js' ;
20- import { isInputType } from '../type/definition.js' ;
2117import { isAbstractType } from '../type/definition.js' ;
2218import {
2319 GraphQLDeferDirective ,
@@ -27,10 +23,8 @@ import {
2723import type { GraphQLSchema } from '../type/schema.js' ;
2824
2925import { typeFromAST } from '../utilities/typeFromAST.js' ;
30- import { valueFromAST } from '../utilities/valueFromAST.js' ;
31- import { valueFromASTUntyped } from '../utilities/valueFromASTUntyped.js' ;
3226
33- import { getDirectiveValues } from './values.js' ;
27+ import { getDirectiveValues , getArgumentValuesFromSpread } from './values.js' ;
3428
3529export interface DeferUsage {
3630 label : string | undefined ;
@@ -224,57 +218,23 @@ function collectFieldsImpl(
224218 // scope as that variable can still get used in spreads later on in the selectionSet.
225219 // - when a value is passed in through the fragment-spread we need to copy over the key-value
226220 // 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+
278238 break ;
279239 }
280240 }
0 commit comments