Skip to content

Commit

Permalink
fold executeQueryOrMutation into execute
Browse files Browse the repository at this point in the history
  • Loading branch information
yaacovCR committed Oct 10, 2021
1 parent 8796aa4 commit ea6b79e
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 deletions src/execution/execute.ts
Expand Up @@ -196,8 +196,17 @@ export function execute(args: ExecutionArgs): PromiseOrValue<ExecutionResult> {
return { errors: exeContext };
}

// Execute the operation.
return executeQueryOrMutation(exeContext);
// 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 a
// resolved Promise.
const data = executeQueryOrMutationRootFields(exeContext);

// Return the response.
return buildResponse(exeContext, data);
}

/**
Expand All @@ -216,24 +225,6 @@ 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

0 comments on commit ea6b79e

Please sign in to comment.