Skip to content

Commit

Permalink
Reset cached values of arguments in BaseDirective::hydrate()
Browse files Browse the repository at this point in the history
  • Loading branch information
LastDragon-ru authored Aug 4, 2023
1 parent 690ca7b commit 41465ba
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ You can find and compare releases at the [GitHub release page](https://github.co

## Unreleased

## v6.16.1

### Fixed

- Reset cached values of arguments in `BaseDirective::hydrate()` https://github.com/nuwave/lighthouse/pull/2430

## v6.16.0

### Changed
Expand Down
2 changes: 2 additions & 0 deletions src/Schema/Directives/BaseDirective.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public function hydrate(DirectiveNode $directiveNode, ScalarTypeDefinitionNode|S
$this->directiveNode = $directiveNode;
$this->definitionNode = $definitionNode;

unset($this->directiveArgs);

return $this;
}

Expand Down
24 changes: 24 additions & 0 deletions tests/Unit/Schema/Directives/BaseDirectiveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,30 @@ public function testMutuallyExclusive(): void
$directive->validateMutuallyExclusiveArguments(['bar', 'baz', 'qux']);
}

public function testHydrateShouldResetCachedArgs(): void
{
$directive = $this->constructFieldDirective('foo: ID @dummy(arg: "value")');

$this->assertSame(
'value',
// @phpstan-ignore-next-line protected method is called via wrapper below
$directive->directiveArgValue('arg'),
);

$field = Parser::fieldDefinition('foo: ID @dummy(arg: "new value")');

$directive->hydrate(
$field->directives[0],
$field,
);

$this->assertSame(
'new value',
// @phpstan-ignore-next-line protected method is called via wrapper below
$directive->directiveArgValue('arg'),
);
}

protected function constructFieldDirective(string $definition): BaseDirective
{
$fieldDefinition = Parser::fieldDefinition($definition);
Expand Down

0 comments on commit 41465ba

Please sign in to comment.