| Conditions | 1 |
| Paths | 1 |
| Total Lines | 29 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 22 | public function build(SchemaConfig $config) |
||
| 23 | { |
||
| 24 | $config->getQuery()->addFields([ |
||
| 25 | 'me' => [ |
||
| 26 | 'type' => new TestObjectType(), |
||
| 27 | 'resolve' => function ($value, $args, ResolveInfo $info) { |
||
| 28 | return $info->getReturnType()->getData(); |
||
|
|
|||
| 29 | } |
||
| 30 | ], |
||
| 31 | 'status' => [ |
||
| 32 | 'type' => new TestEnumType(), |
||
| 33 | 'resolve' => function () { |
||
| 34 | return $this->testStatusValue; |
||
| 35 | } |
||
| 36 | ], |
||
| 37 | ]); |
||
| 38 | $config->getMutation()->addFields([ |
||
| 39 | 'updateStatus' => [ |
||
| 40 | 'type' => new TestEnumType(), |
||
| 41 | 'resolve' => function () { |
||
| 42 | return $this->testStatusValue; |
||
| 43 | }, |
||
| 44 | 'args' => [ |
||
| 45 | 'newStatus' => new TestEnumType(), |
||
| 46 | 'list' => new ListType(new IntType()) |
||
| 47 | ] |
||
| 48 | ] |
||
| 49 | ]); |
||
| 50 | } |
||
| 51 | |||
| 54 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: