Skip to content

Commit

Permalink
Refactor Executor as class (#7)
Browse files Browse the repository at this point in the history
* Move non-class Executor functions to end of file

* Move memoized collectSubFields adjacent to class functions

* Add buildPerPayloadExecutionContext function

* Add main exports to executor

...in preparation for wrapping as class

* Refactor Executor as class
  • Loading branch information
yaacovCR authored Oct 14, 2021
1 parent 836a52e commit c613137
Show file tree
Hide file tree
Showing 3 changed files with 945 additions and 873 deletions.
14 changes: 3 additions & 11 deletions src/execution/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { PromiseOrValue } from '../jsutils/PromiseOrValue';
import { isPromise } from '../jsutils/isPromise';

import type { ExecutionArgs } from './executor';
import { buildExecutionContext, executeQueryOrMutation } from './executor';
import { Executor } from './executor';

/**
* Implements the "Executing requests" section of the GraphQL specification.
Expand All @@ -17,16 +17,8 @@ import { buildExecutionContext, executeQueryOrMutation } from './executor';
* a GraphQLError will be thrown immediately explaining the invalid input.
*/
export function execute(args: ExecutionArgs): PromiseOrValue<ExecutionResult> {
// If a valid execution context cannot be created due to incorrect arguments,
// a "Response" with only errors is returned.
const exeContext = buildExecutionContext(args);

// Return early errors if execution context failed.
if (!('schema' in exeContext)) {
return { errors: exeContext };
}

return executeQueryOrMutation(exeContext);
const executor = new Executor();
return executor.executeQueryOrMutation(args);
}

/**
Expand Down
Loading

0 comments on commit c613137

Please sign in to comment.