66
77use Jerowork \GraphqlAttributeSchema \Parser \Node \Child \ArgNode ;
88use Jerowork \GraphqlAttributeSchema \Parser \Node \Node ;
9- use Jerowork \GraphqlAttributeSchema \Parser \Node \Type ;
9+ use Jerowork \GraphqlAttributeSchema \Parser \Node \Type \ NodeType ;
1010
1111/**
1212 * @phpstan-import-type ArgNodePayload from ArgNode
13- * @phpstan-import-type TypePayload from Type
1413 *
1514 * @phpstan-type MutationNodePayload array{
1615 * className: class-string,
1716 * name: string,
1817 * description: null|string,
1918 * argNodes: list<ArgNodePayload>,
20- * outputType: TypePayload,
19+ * outputType: array{
20+ * type: class-string,
21+ * payload: array<string, mixed>
22+ * },
2123 * methodName: string,
2224 * deprecationReason: null|string
2325 * }
@@ -33,7 +35,7 @@ public function __construct(
3335 public string $ name ,
3436 public ?string $ description ,
3537 public array $ argNodes ,
36- public Type $ outputType ,
38+ public NodeType $ outputType ,
3739 public string $ methodName ,
3840 public ?string $ deprecationReason ,
3941 ) {}
@@ -48,12 +50,16 @@ public function getClassName(): string
4850 */
4951 public function toArray (): array
5052 {
53+ // @phpstan-ignore-next-line
5154 return [
5255 'className ' => $ this ->className ,
5356 'name ' => $ this ->name ,
5457 'description ' => $ this ->description ,
5558 'argNodes ' => array_map (fn ($ argNode ) => $ argNode ->toArray (), $ this ->argNodes ),
56- 'outputType ' => $ this ->outputType ->toArray (),
59+ 'outputType ' => [
60+ 'type ' => $ this ->outputType ::class,
61+ 'payload ' => $ this ->outputType ->toArray (),
62+ ],
5763 'methodName ' => $ this ->methodName ,
5864 'deprecationReason ' => $ this ->deprecationReason ,
5965 ];
@@ -64,12 +70,15 @@ public function toArray(): array
6470 */
6571 public static function fromArray (array $ payload ): MutationNode
6672 {
73+ /** @var class-string<NodeType> $type */
74+ $ type = $ payload ['outputType ' ]['type ' ];
75+
6776 return new self (
6877 $ payload ['className ' ],
6978 $ payload ['name ' ],
7079 $ payload ['description ' ],
7180 array_map (fn ($ argNodePayload ) => ArgNode::fromArray ($ argNodePayload ), $ payload ['argNodes ' ]),
72- Type ::fromArray ($ payload ['outputType ' ]),
81+ $ type ::fromArray ($ payload ['outputType ' ][ ' payload ' ]), // @phpstan-ignore-line
7382 $ payload ['methodName ' ],
7483 $ payload ['deprecationReason ' ],
7584 );
0 commit comments