Skip to content

Commit 3e62c28

Browse files
committed
only pass reference of contextValue to field resolvers
1 parent 61adcde commit 3e62c28

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/Execution/ExecutionContext.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function __construct(
1919
Schema $schema,
2020
array $fragments,
2121
$rootValue,
22-
$contextValue,
22+
array $contextValue,
2323
$operation,
2424
$variableValues,
2525
$fieldResolver,
@@ -104,7 +104,7 @@ public function setRootValue($rootValue)
104104
/**
105105
* @return mixed
106106
*/
107-
public function getContextValue()
107+
public function &getContextValue()
108108
{
109109
return $this->contextValue;
110110
}

src/Execution/Executor.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ public function resolveField(ExecutionContext $executionContext, GraphQLObjectTy
211211
try {
212212
$args = Values::getArgumentValues($fieldDef, $fieldNodes[0], $executionContext->getVariableValues());
213213

214-
$contextValue = $executionContext->getContextValue();
214+
$contextValue = &$executionContext->getContextValue();
215215

216216
$result = $resolveFn($source, $args, $contextValue, $info);
217217

@@ -520,6 +520,9 @@ public function buildExecutionContext(Schema $schema, array $document, $rootValu
520520
$variableDefinitions = $operation["variableDefinitions"] ?? [];
521521
$coercedVariableValues = Values::getVariableValues($schema, $variableDefinitions, $rawVariableValues ?? []);
522522

523+
// default $contextValue to an empty array
524+
$contextValue = $contextValue ?? [];
525+
523526
return new ExecutionContext(
524527
$schema,
525528
$fragments,

0 commit comments

Comments
 (0)