Skip to content

Commit d652e11

Browse files
committed
polish: rename executeImpl to executeOperation (#4045)
inline much of the original executeOperation leave out executeRootGroupedFieldSet, will help reduce the diff for
1 parent 8c80008 commit d652e11

1 file changed

Lines changed: 53 additions & 42 deletions

File tree

src/execution/execute.ts

Lines changed: 53 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -218,25 +218,54 @@ export function execute(args: ExecutionArgs): PromiseOrValue<ExecutionResult> {
218218
return { errors: exeContext };
219219
}
220220

221-
return executeImpl(exeContext);
221+
return executeOperation(exeContext);
222222
}
223223

224-
function executeImpl(
224+
/**
225+
* Implements the "Executing operations" section of the spec.
226+
*
227+
* Returns a Promise that will eventually resolve to the data described by
228+
* The "Response" section of the GraphQL specification.
229+
*
230+
* If errors are encountered while executing a GraphQL field, only that
231+
* field and its descendants will be omitted, and sibling fields will still
232+
* be executed. An execution which encounters errors will still result in a
233+
* resolved Promise.
234+
*
235+
* Errors from sub-fields of a NonNull type may propagate to the top level,
236+
* at which point we still log the error and null the parent field, which
237+
* in this case is the entire response.
238+
*/
239+
function executeOperation(
225240
exeContext: ExecutionContext,
226241
): PromiseOrValue<ExecutionResult> {
227-
// Return a Promise that will eventually resolve to the data described by
228-
// The "Response" section of the GraphQL specification.
229-
//
230-
// If errors are encountered while executing a GraphQL field, only that
231-
// field and its descendants will be omitted, and sibling fields will still
232-
// be executed. An execution which encounters errors will still result in a
233-
// resolved Promise.
234-
//
235-
// Errors from sub-fields of a NonNull type may propagate to the top level,
236-
// at which point we still log the error and null the parent field, which
237-
// in this case is the entire response.
238242
try {
239-
const result = executeOperation(exeContext);
243+
const { operation, schema, fragments, variableValues, rootValue } =
244+
exeContext;
245+
const rootType = schema.getRootType(operation.operation);
246+
if (rootType == null) {
247+
throw new GraphQLError(
248+
`Schema is not configured to execute ${operation.operation} operation.`,
249+
{ nodes: operation },
250+
);
251+
}
252+
253+
const groupedFieldSet = collectFields(
254+
schema,
255+
fragments,
256+
variableValues,
257+
rootType,
258+
operation.selectionSet,
259+
);
260+
261+
const result = executeRootGroupedFieldSet(
262+
exeContext,
263+
operation.operation,
264+
rootType,
265+
rootValue,
266+
groupedFieldSet,
267+
);
268+
240269
if (isPromise(result)) {
241270
return result.then(
242271
(data) => buildResponse(data, exeContext.collectedErrors.errors),
@@ -381,46 +410,28 @@ function buildPerEventExecutionContext(
381410
};
382411
}
383412

384-
/**
385-
* Implements the "Executing operations" section of the spec.
386-
*/
387-
function executeOperation(
413+
function executeRootGroupedFieldSet(
388414
exeContext: ExecutionContext,
415+
operation: OperationTypeNode,
416+
rootType: GraphQLObjectType,
417+
rootValue: unknown,
418+
groupedFieldSet: GroupedFieldSet,
389419
): PromiseOrValue<ObjMap<unknown>> {
390-
const { operation, schema, fragments, variableValues, rootValue } =
391-
exeContext;
392-
const rootType = schema.getRootType(operation.operation);
393-
if (rootType == null) {
394-
throw new GraphQLError(
395-
`Schema is not configured to execute ${operation.operation} operation.`,
396-
{ nodes: operation },
397-
);
398-
}
399-
400-
const groupedFieldSet = collectFields(
401-
schema,
402-
fragments,
403-
variableValues,
404-
rootType,
405-
operation.selectionSet,
406-
);
407-
const path = undefined;
408-
409-
switch (operation.operation) {
420+
switch (operation) {
410421
case OperationTypeNode.QUERY:
411422
return executeFields(
412423
exeContext,
413424
rootType,
414425
rootValue,
415-
path,
426+
undefined,
416427
groupedFieldSet,
417428
);
418429
case OperationTypeNode.MUTATION:
419430
return executeFieldsSerially(
420431
exeContext,
421432
rootType,
422433
rootValue,
423-
path,
434+
undefined,
424435
groupedFieldSet,
425436
);
426437
case OperationTypeNode.SUBSCRIPTION:
@@ -430,7 +441,7 @@ function executeOperation(
430441
exeContext,
431442
rootType,
432443
rootValue,
433-
path,
444+
undefined,
434445
groupedFieldSet,
435446
);
436447
}
@@ -1308,7 +1319,7 @@ function mapSourceToResponse(
13081319
// "ExecuteSubscriptionEvent" algorithm, as it is nearly identical to the
13091320
// "ExecuteQuery" algorithm, for which `execute` is also used.
13101321
return mapAsyncIterable(resultOrStream, (payload: unknown) =>
1311-
executeImpl(buildPerEventExecutionContext(exeContext, payload)),
1322+
executeOperation(buildPerEventExecutionContext(exeContext, payload)),
13121323
);
13131324
}
13141325

0 commit comments

Comments
 (0)