Skip to content

Commit 5a80dd2

Browse files
authored
Ensure Argument::$type is initialized (#2682)
1 parent b6d5ed6 commit 5a80dd2

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ You can find and compare releases at the [GitHub release page](https://github.co
99

1010
## Unreleased
1111

12+
## v6.56.1
13+
14+
### Fixed
15+
16+
- Initialize `Argument::$type` with `null` and make it nullable https://github.com/nuwave/lighthouse/pull/2682
17+
1218
## v6.56.0
1319

1420
### Added

src/Execution/Arguments/Argument.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Argument
1717
/**
1818
* The type of the argument.
1919
*/
20-
public ListType|NamedType $type;
20+
public ListType|NamedType|null $type = null;
2121

2222
/**
2323
* A list of directives associated with that argument.
@@ -26,7 +26,7 @@ class Argument
2626
*/
2727
public Collection $directives;
2828

29-
/** An argument may have a resolver that handles its given value. */
29+
/** A resolver that handles the given value. */
3030
public ?ArgResolver $resolver = null;
3131

3232
public function __construct()

src/Execution/Arguments/ArgumentSetFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ protected function wrapInArgument(mixed $value, InputValueDefinitionNode $defini
8686
$type = $this->argumentTypeNodeConverter->convert($definition->type);
8787

8888
$argument = new Argument();
89-
$argument->directives = $this->directiveLocator->associated($definition);
90-
$argument->type = $type;
9189
$argument->value = $this->wrapWithType($value, $type);
90+
$argument->type = $type;
91+
$argument->directives = $this->directiveLocator->associated($definition);
9292

9393
return $argument;
9494
}

tests/Unit/Execution/Arguments/ArgumentSetTest.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,16 +127,30 @@ public function testAddValueAtRootLevel(): void
127127
$set = new ArgumentSet();
128128
$set->addValue('foo', 42);
129129

130-
$this->assertSame(42, $set->arguments['foo']->value);
130+
$argument = $set->arguments['foo'];
131+
$this->assertSame(42, $argument->value);
132+
$this->assertNull($argument->type);
133+
$this->assertEmpty($argument->directives);
134+
$this->assertNull($argument->resolver);
131135
}
132136

133137
public function testAddValueDeep(): void
134138
{
135139
$set = new ArgumentSet();
136140
$set->addValue('foo.bar', 42);
137141

138-
$foo = $set->arguments['foo']->value;
142+
$foo = $set->arguments['foo'];
143+
$this->assertNull($foo->type);
144+
$this->assertEmpty($foo->directives);
145+
$this->assertNull($foo->resolver);
139146

140-
$this->assertSame(42, $foo->arguments['bar']->value);
147+
$fooValue = $foo->value;
148+
$this->assertInstanceOf(ArgumentSet::class, $fooValue);
149+
150+
$bar = $fooValue->arguments['bar'];
151+
$this->assertSame(42, $bar->value);
152+
$this->assertNull($bar->type);
153+
$this->assertEmpty($bar->directives);
154+
$this->assertNull($bar->resolver);
141155
}
142156
}

0 commit comments

Comments
 (0)