From 3a2fc8b10edee24343ca697ac1575ce2d61c5ddc Mon Sep 17 00:00:00 2001 From: Yaacov Rydzinski Date: Sun, 19 Jun 2022 21:51:03 +0300 Subject: [PATCH 1/2] refactor: executeOperation can take only one parameter `operation` is included within `exeContext` --- src/execution/execute.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/execution/execute.ts b/src/execution/execute.ts index be0323ca76..f017d3c867 100644 --- a/src/execution/execute.ts +++ b/src/execution/execute.ts @@ -186,8 +186,7 @@ export function execute(args: ExecutionArgs): PromiseOrValue { // 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), @@ -325,8 +324,8 @@ export function buildExecutionContext( */ function executeOperation( exeContext: ExecutionContext, - operation: OperationDefinitionNode, ): PromiseOrValue> { + const { operation } = exeContext; const rootType = exeContext.schema.getRootType(operation.operation); if (rootType == null) { throw new GraphQLError( From 4e0ed3651a19e05dc7c78de7559c3998aad7eade Mon Sep 17 00:00:00 2001 From: Yaacov Rydzinski Date: Sun, 19 Jun 2022 21:52:29 +0300 Subject: [PATCH 2/2] refactor: use spread syntax with exeContext --- src/execution/execute.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/execution/execute.ts b/src/execution/execute.ts index f017d3c867..bcebc879ff 100644 --- a/src/execution/execute.ts +++ b/src/execution/execute.ts @@ -325,8 +325,9 @@ export function buildExecutionContext( function executeOperation( exeContext: ExecutionContext, ): PromiseOrValue> { - const { operation } = exeContext; - 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.`, @@ -335,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);