Skip to content

Commit 75286fe

Browse files
committed
refactor: remove rootValue argument from executeOperation
`executeOperation` is never called with a `rootValue` different from `exeContext.rootValue` and `rootValue` is not utilized in the calling code except to pass its value to `executeOperation`. Rather than using an additional argument to `executeOperation`, the `rootValue`, the `rootValue` can be selected from the `exeContext` within `executeOperation`
1 parent 2f91eb8 commit 75286fe

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/execution/execute.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,6 @@ export interface ExecutionArgs {
162162
* a GraphQLError will be thrown immediately explaining the invalid input.
163163
*/
164164
export function execute(args: ExecutionArgs): PromiseOrValue<ExecutionResult> {
165-
const { rootValue } = args;
166-
167165
// If a valid execution context cannot be created due to incorrect arguments,
168166
// a "Response" with only errors is returned.
169167
const exeContext = buildExecutionContext(args);
@@ -186,7 +184,7 @@ export function execute(args: ExecutionArgs): PromiseOrValue<ExecutionResult> {
186184
// in this case is the entire response.
187185
try {
188186
const { operation } = exeContext;
189-
const result = executeOperation(exeContext, operation, rootValue);
187+
const result = executeOperation(exeContext, operation);
190188
if (isPromise(result)) {
191189
return result.then(
192190
(data) => buildResponse(data, exeContext.errors),
@@ -349,7 +347,6 @@ export function buildExecutionContext(
349347
function executeOperation(
350348
exeContext: ExecutionContext,
351349
operation: OperationDefinitionNode,
352-
rootValue: unknown,
353350
): PromiseOrValue<ObjMap<unknown> | null> {
354351
const rootType = exeContext.schema.getRootType(operation.operation);
355352
if (rootType == null) {
@@ -368,6 +365,8 @@ function executeOperation(
368365
);
369366
const path = undefined;
370367

368+
const { rootValue } = exeContext;
369+
371370
switch (operation.operation) {
372371
case OperationTypeNode.QUERY:
373372
return executeFields(exeContext, rootType, rootValue, path, rootFields);

0 commit comments

Comments
 (0)