1- import type {
2- ExecutionArgs ,
3- ExecutionResult ,
4- GraphQLError ,
5- OperationDefinitionNode ,
6- } from 'graphql' ;
1+ import type { ExecutionArgs , ExecutionResult , GraphQLError } from 'graphql' ;
72import { experimentalExecuteQueryOrMutationOrSubscriptionEvent } from 'graphql' ;
83import type {
9- FragmentDetails ,
104 GroupedFieldSet ,
115 // eslint-disable-next-line n/no-missing-import
126} from 'graphql/execution/collectFields.js' ;
@@ -103,14 +97,12 @@ export function transform(
10397 prefix ,
10498 ) ;
10599
106- const withExecutors : Array < {
107- subschemaConfig : SubschemaConfig ;
108- operation : OperationDefinitionNode ;
109- fragments : ObjMap < FragmentDetails > ;
110- executor : ( ) => PromiseOrValue <
111- ExecutionResult | ExperimentalIncrementalExecutionResults
112- > ;
113- } > = [ ] ;
100+ const mergedResult = new MergedResult ( ) ;
101+ const transformedResults : Array <
102+ PromiseOrValue < ExecutionResult | CompletedInitialResult >
103+ > = [ ] ;
104+
105+ let containsPromise = false ;
114106 for ( const subschemaConfig of Object . values (
115107 args . subschemas ?? {
116108 target : {
@@ -129,8 +121,8 @@ export function transform(
129121 ) ;
130122
131123 if ( ! ( 'operation' in transformedForSubschema ) ) {
132- // return ` data: null` to mimic non-gateway behavior
133- return { data : null , errors : transformedForSubschema } ;
124+ transformedResults . push ( { data : null , errors : transformedForSubschema } ) ;
125+ continue ;
134126 }
135127
136128 const executor : Executor =
@@ -145,56 +137,38 @@ export function transform(
145137 ( details ) => details . definition ,
146138 ) ;
147139
148- withExecutors . push ( {
149- subschemaConfig,
140+ const originalResult = executor ( {
141+ ...originalArgs ,
142+ schema : subschema ,
150143 operation : transformedOperation ,
151144 fragments : transformedFragments ,
152- executor : ( ) =>
153- executor ( {
154- ...originalArgs ,
155- schema : subschema ,
156- operation : transformedOperation ,
157- fragments : transformedFragments ,
158- fragmentDefinitions : transformedFragmentDefinitions ,
159- } ) ,
145+ fragmentDefinitions : transformedFragmentDefinitions ,
160146 } ) ;
161- }
162147
163- const mergedResult = new MergedResult ( ) ;
164- const transformedResults : Array <
165- PromiseOrValue < ExecutionResult | CompletedInitialResult >
166- > = [ ] ;
167-
168- let containsPromise = false ;
169- for ( const {
170- subschemaConfig,
171- operation,
172- fragments,
173- executor,
174- } of withExecutors ) {
175- const originalResult = executor ( ) ;
176148 const subschemaLabel = subschemaConfig . label ;
177149 if ( isPromise ( originalResult ) ) {
178150 containsPromise = true ;
179151 transformedResults . push (
180- originalResult . then ( ( resolved ) => {
181- mergedResult . add ( subschemaLabel , resolved ) ;
182- return completeInitialResult (
152+ originalResult . then ( ( resolved ) =>
153+ completeInitialResult (
183154 context ,
184- operation ,
185- fragments ,
186- mergedResult . getMergedData ( ) ,
187- ) ;
188- } ) ,
155+ transformedOperation ,
156+ transformedFragments ,
157+ subschemaConfig . label ,
158+ resolved ,
159+ mergedResult ,
160+ ) ,
161+ ) ,
189162 ) ;
190163 continue ;
191164 }
192- mergedResult . add ( subschemaLabel , originalResult ) ;
193165 const transformed = completeInitialResult (
194166 context ,
195- operation ,
196- fragments ,
197- mergedResult . getMergedData ( ) ,
167+ transformedOperation ,
168+ transformedFragments ,
169+ subschemaLabel ,
170+ originalResult ,
171+ mergedResult ,
198172 ) ;
199173 // TODO: add test case for asynchronous transform
200174 /* c8 ignore next 3 */
0 commit comments