Skip to content

refactor: use exeContext strategically #3654

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions src/execution/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,7 @@ export function execute(args: ExecutionArgs): PromiseOrValue<ExecutionResult> {
// at which point we still log the error and null the parent field, which
// in this case is the entire response.
try {
const { operation } = exeContext;
const result = executeOperation(exeContext, operation);
const result = executeOperation(exeContext);
if (isPromise(result)) {
return result.then(
(data) => buildResponse(data, exeContext.errors),
Expand Down Expand Up @@ -325,9 +324,10 @@ export function buildExecutionContext(
*/
function executeOperation(
exeContext: ExecutionContext,
operation: OperationDefinitionNode,
): PromiseOrValue<ObjMap<unknown>> {
const rootType = exeContext.schema.getRootType(operation.operation);
const { operation, schema, fragments, variableValues, rootValue } =
exeContext;
const rootType = schema.getRootType(operation.operation);
if (rootType == null) {
throw new GraphQLError(
`Schema is not configured to execute ${operation.operation} operation.`,
Expand All @@ -336,16 +336,14 @@ function executeOperation(
}

const rootFields = collectFields(
exeContext.schema,
exeContext.fragments,
exeContext.variableValues,
schema,
fragments,
variableValues,
rootType,
operation.selectionSet,
);
const path = undefined;

const { rootValue } = exeContext;

switch (operation.operation) {
case OperationTypeNode.QUERY:
return executeFields(exeContext, rootType, rootValue, path, rootFields);
Expand Down