Skip to content

Commit

Permalink
Properly name the root field execution functions
Browse files Browse the repository at this point in the history
The codebase should refers to functions that execute the query, mutation, and/or subscription root fields as such, rather than as functions that execute the operations themselves. Executing an query or mutation returns a map of data and errors, while executing the root fields returns the data of the root fields.
  • Loading branch information
yaacovCR committed Oct 7, 2021
1 parent 4aeea8e commit 64917bb
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions src/execution/execute.ts
Expand Up @@ -196,15 +196,8 @@ export function execute(args: ExecutionArgs): PromiseOrValue<ExecutionResult> {
return { errors: exeContext };
}

// Return a Promise that will eventually resolve to the data described by
// The "Response" section of the GraphQL specification.
//
// If errors are encountered while executing a GraphQL field, only that
// field and its descendants will be omitted, and sibling fields will still
// be executed. An execution which encounters errors will still result in a
// resolved Promise.
const data = executeOperation(exeContext, exeContext.operation, rootValue);
return buildResponse(exeContext, data);
// Execute the operation.
return executeQueryOrMutation(exeContext);
}

/**
Expand All @@ -223,6 +216,24 @@ export function executeSync(args: ExecutionArgs): ExecutionResult {
return result;
}

/**
* Implements the "Executing operations" section of the spec for queries and mutations.
*
* Return data or a Promise that will eventually resolve to the data described by
* The "Response" section of the GraphQL specification.
*
* If errors are encountered while executing a GraphQL field, only that
* field and its descendants will be omitted, and sibling fields will still
* be executed. An execution which encounters errors will still result in
* resolved data.
*/
function executeQueryOrMutation(
exeContext: ExecutionContext,
): PromiseOrValue<ExecutionResult> {
const data = executeQueryOrMutationRootFields(exeContext);
return buildResponse(exeContext, data);
}

/**
* Given a completed execution context and data, build the `{ errors, data }`
* response defined by the "Response" section of the GraphQL specification.
Expand Down Expand Up @@ -339,14 +350,13 @@ export function buildExecutionContext(
}

/**
* Implements the "Executing operations" section of the spec.
* Executes the root fields specified by query or mutation operation.
*/
function executeOperation(
function executeQueryOrMutationRootFields(
exeContext: ExecutionContext,
operation: OperationDefinitionNode,
rootValue: unknown,
): PromiseOrValue<ObjMap<unknown> | null> {
const type = getOperationRootType(exeContext.schema, operation);
const { schema, operation, rootValue } = exeContext;
const type = getOperationRootType(schema, operation);
const fields = collectFields(
exeContext.schema,
exeContext.fragments,
Expand Down

0 comments on commit 64917bb

Please sign in to comment.