From 4640c1ed456b511a62067a73e8c557a76894458c Mon Sep 17 00:00:00 2001 From: kafkiansky Date: Mon, 3 Aug 2026 16:38:08 +0300 Subject: [PATCH] Pass Grpc\RpcType into Client\Invoke --- src/Plugin/Generator/GrpcGenerator.php | 38 +++++++++++-------- .../Test/Api/V1/EchoServiceClient.php | 4 +- .../Test/Api/V1/EchoServiceServerRegistry.php | 7 ++-- .../grpc/Thesis/Auth/V1/AuthServiceClient.php | 4 +- .../Auth/V1/AuthServiceServerRegistry.php | 7 ++-- .../Thesis/Queue/V1/QueueServiceClient.php | 10 +++-- .../Queue/V1/QueueServiceServerRegistry.php | 19 +++++----- 7 files changed, 53 insertions(+), 36 deletions(-) diff --git a/src/Plugin/Generator/GrpcGenerator.php b/src/Plugin/Generator/GrpcGenerator.php index 72c4bf9..f942aac 100644 --- a/src/Plugin/Generator/GrpcGenerator.php +++ b/src/Plugin/Generator/GrpcGenerator.php @@ -52,6 +52,7 @@ public function generateClient(Parser\ServiceDescriptor $service): PhpNamespace $namespace->addUse('Amp\Cancellation'); $namespace->addUse('Amp\NullCancellation'); + $namespace->addUse('Thesis\Grpc'); $namespace->addUse('Thesis\Grpc\Client'); $namespace->addUse('Thesis\Grpc\Metadata'); @@ -116,7 +117,8 @@ public function generateClient(Parser\ServiceDescriptor $service): PhpNamespace /** @var Client\Invoke $invoke */ $invoke = new Client\Invoke( method: ?, - type: ?::class, + output: ?::class, + type: Grpc\RpcType::Unary, ); return $this->client->invoke( @@ -138,7 +140,8 @@ public function generateClient(Parser\ServiceDescriptor $service): PhpNamespace /** @var Client\Invoke $invoke */ $invoke = new Client\Invoke( method: ?, - type: ?::class, + output: ?::class, + type: Grpc\RpcType::ClientStream, ); $stream = $this->client->createStream( @@ -160,7 +163,8 @@ public function generateClient(Parser\ServiceDescriptor $service): PhpNamespace /** @var Client\Invoke $invoke */ $invoke = new Client\Invoke( method: ?, - type: ?::class, + output: ?::class, + type: Grpc\RpcType::ServerStream, ); $stream = $this->client->createStream( @@ -185,7 +189,8 @@ public function generateClient(Parser\ServiceDescriptor $service): PhpNamespace /** @var Client\Invoke $invoke */ $invoke = new Client\Invoke( method: ?, - type: ?::class, + output: ?::class, + type: Grpc\RpcType::BidirectionalStream, ); $stream = $this->client->createStream( @@ -314,6 +319,7 @@ public function generateServerRegistry(Parser\ServiceDescriptor $service): PhpNa $namespace->add($classType); + $namespace->addUse('Thesis\Grpc'); $namespace->addUse('Thesis\Grpc\Server'); $handlers = []; @@ -333,9 +339,9 @@ public function generateServerRegistry(Parser\ServiceDescriptor $service): PhpNa $handlers[] = new Literal( <<<'PHP' new Server\Rpc( - new Server\Handle(?, ?::class), - new Server\UnaryHandler($this->server->?(...)), - Server\RpcType::Unary, + handle: new Server\Handle(?, ?::class), + handler: new Server\UnaryHandler($this->server->?(...)), + type: Grpc\RpcType::Unary, ) PHP, $args, @@ -344,9 +350,9 @@ public function generateServerRegistry(Parser\ServiceDescriptor $service): PhpNa $handlers[] = new Literal( <<<'PHP' new Server\Rpc( - new Server\Handle(?, ?::class), - new Server\ClientStreamHandler($this->server->?(...)), - Server\RpcType::ClientStream, + handle: new Server\Handle(?, ?::class), + handler: new Server\ClientStreamHandler($this->server->?(...)), + type: Grpc\RpcType::ClientStream, ) PHP, $args, @@ -355,9 +361,9 @@ public function generateServerRegistry(Parser\ServiceDescriptor $service): PhpNa $handlers[] = new Literal( <<<'PHP' new Server\Rpc( - new Server\Handle(?, ?::class), - new Server\ServerStreamHandler($this->server->?(...)), - Server\RpcType::ServerStream, + handle: new Server\Handle(?, ?::class), + handler: new Server\ServerStreamHandler($this->server->?(...)), + type: Grpc\RpcType::ServerStream, ) PHP, $args, @@ -366,9 +372,9 @@ public function generateServerRegistry(Parser\ServiceDescriptor $service): PhpNa $handlers[] = new Literal( <<<'PHP' new Server\Rpc( - new Server\Handle(?, ?::class), - new Server\BidirectionalStreamHandler($this->server->?(...)), - Server\RpcType::BidirectionalStream, + handle: new Server\Handle(?, ?::class), + handler: new Server\BidirectionalStreamHandler($this->server->?(...)), + type: Grpc\RpcType::BidirectionalStream, ) PHP, $args, diff --git a/tests/snapshots/deprecated/Test/Api/V1/EchoServiceClient.php b/tests/snapshots/deprecated/Test/Api/V1/EchoServiceClient.php index 0b17193..b52dd59 100644 --- a/tests/snapshots/deprecated/Test/Api/V1/EchoServiceClient.php +++ b/tests/snapshots/deprecated/Test/Api/V1/EchoServiceClient.php @@ -15,6 +15,7 @@ use Amp\Cancellation; use Amp\NullCancellation; use Deprecated; +use Thesis\Grpc; use Thesis\Grpc\Client; use Thesis\Grpc\Exception\ClientStreamIsClosed; use Thesis\Grpc\InvokeError; @@ -46,7 +47,8 @@ public function echo( /** @var Client\Invoke<\Test\Api\V1\Request, \Test\Api\V1\Request> $invoke */ $invoke = new Client\Invoke( method: '/test.api.v1.EchoService/Echo', - type: \Test\Api\V1\Request::class, + output: \Test\Api\V1\Request::class, + type: Grpc\RpcType::Unary, ); return $this->client->invoke( diff --git a/tests/snapshots/deprecated/Test/Api/V1/EchoServiceServerRegistry.php b/tests/snapshots/deprecated/Test/Api/V1/EchoServiceServerRegistry.php index 8e1fbe5..bbffd2c 100644 --- a/tests/snapshots/deprecated/Test/Api/V1/EchoServiceServerRegistry.php +++ b/tests/snapshots/deprecated/Test/Api/V1/EchoServiceServerRegistry.php @@ -13,6 +13,7 @@ namespace Test\Api\V1; use Override; +use Thesis\Grpc; use Thesis\Grpc\Server; /** @@ -29,9 +30,9 @@ public function services(): iterable { yield new Server\Service('test.api.v1.EchoService', [ new Server\Rpc( - new Server\Handle('Echo', \Test\Api\V1\Request::class), - new Server\UnaryHandler($this->server->echo(...)), - Server\RpcType::Unary, + handle: new Server\Handle('Echo', \Test\Api\V1\Request::class), + handler: new Server\UnaryHandler($this->server->echo(...)), + type: Grpc\RpcType::Unary, ), ]); } diff --git a/tests/snapshots/grpc/Thesis/Auth/V1/AuthServiceClient.php b/tests/snapshots/grpc/Thesis/Auth/V1/AuthServiceClient.php index 67ddc31..d542934 100644 --- a/tests/snapshots/grpc/Thesis/Auth/V1/AuthServiceClient.php +++ b/tests/snapshots/grpc/Thesis/Auth/V1/AuthServiceClient.php @@ -14,6 +14,7 @@ use Amp\Cancellation; use Amp\NullCancellation; +use Thesis\Grpc; use Thesis\Grpc\Client; use Thesis\Grpc\Exception\ClientStreamIsClosed; use Thesis\Grpc\InvokeError; @@ -40,7 +41,8 @@ public function login( /** @var Client\Invoke<\Thesis\Auth\LoginRequest, \Thesis\Auth\LoginResponse> $invoke */ $invoke = new Client\Invoke( method: '/Thesis.Auth.V1.AuthService/Login', - type: \Thesis\Auth\LoginResponse::class, + output: \Thesis\Auth\LoginResponse::class, + type: Grpc\RpcType::Unary, ); return $this->client->invoke( diff --git a/tests/snapshots/grpc/Thesis/Auth/V1/AuthServiceServerRegistry.php b/tests/snapshots/grpc/Thesis/Auth/V1/AuthServiceServerRegistry.php index 1dc62d8..28ffaf7 100644 --- a/tests/snapshots/grpc/Thesis/Auth/V1/AuthServiceServerRegistry.php +++ b/tests/snapshots/grpc/Thesis/Auth/V1/AuthServiceServerRegistry.php @@ -13,6 +13,7 @@ namespace Thesis\Auth\V1; use Override; +use Thesis\Grpc; use Thesis\Grpc\Server; /** @@ -29,9 +30,9 @@ public function services(): iterable { yield new Server\Service('Thesis.Auth.V1.AuthService', [ new Server\Rpc( - new Server\Handle('Login', \Thesis\Auth\LoginRequest::class), - new Server\UnaryHandler($this->server->login(...)), - Server\RpcType::Unary, + handle: new Server\Handle('Login', \Thesis\Auth\LoginRequest::class), + handler: new Server\UnaryHandler($this->server->login(...)), + type: Grpc\RpcType::Unary, ), ]); } diff --git a/tests/snapshots/grpc/Thesis/Queue/V1/QueueServiceClient.php b/tests/snapshots/grpc/Thesis/Queue/V1/QueueServiceClient.php index b099429..1ead0a0 100644 --- a/tests/snapshots/grpc/Thesis/Queue/V1/QueueServiceClient.php +++ b/tests/snapshots/grpc/Thesis/Queue/V1/QueueServiceClient.php @@ -14,6 +14,7 @@ use Amp\Cancellation; use Amp\NullCancellation; +use Thesis\Grpc; use Thesis\Grpc\Client; use Thesis\Grpc\Metadata; @@ -36,7 +37,8 @@ public function push( /** @var Client\Invoke<\Thesis\Queue\PushRequest\Message, \Google\Protobuf\Empty_> $invoke */ $invoke = new Client\Invoke( method: '/Thesis.Queue.V1.QueueService/Push', - type: \Google\Protobuf\Empty_::class, + output: \Google\Protobuf\Empty_::class, + type: Grpc\RpcType::ClientStream, ); $stream = $this->client->createStream( @@ -59,7 +61,8 @@ public function pull( /** @var Client\Invoke<\Thesis\Queue\PullRequest, \Thesis\Queue\PullRequest\Message> $invoke */ $invoke = new Client\Invoke( method: '/Thesis.Queue.V1.QueueService/Pull', - type: \Thesis\Queue\PullRequest\Message::class, + output: \Thesis\Queue\PullRequest\Message::class, + type: Grpc\RpcType::ServerStream, ); $stream = $this->client->createStream( @@ -84,7 +87,8 @@ public function heartbeat( /** @var Client\Invoke<\Thesis\Queue\Heartbeat\FromClient\Ping, \Thesis\Queue\Heartbeat\FromServer\Ping> $invoke */ $invoke = new Client\Invoke( method: '/Thesis.Queue.V1.QueueService/Heartbeat', - type: \Thesis\Queue\Heartbeat\FromServer\Ping::class, + output: \Thesis\Queue\Heartbeat\FromServer\Ping::class, + type: Grpc\RpcType::BidirectionalStream, ); $stream = $this->client->createStream( diff --git a/tests/snapshots/grpc/Thesis/Queue/V1/QueueServiceServerRegistry.php b/tests/snapshots/grpc/Thesis/Queue/V1/QueueServiceServerRegistry.php index 4b44a33..3efdab2 100644 --- a/tests/snapshots/grpc/Thesis/Queue/V1/QueueServiceServerRegistry.php +++ b/tests/snapshots/grpc/Thesis/Queue/V1/QueueServiceServerRegistry.php @@ -13,6 +13,7 @@ namespace Thesis\Queue\V1; use Override; +use Thesis\Grpc; use Thesis\Grpc\Server; /** @@ -29,19 +30,19 @@ public function services(): iterable { yield new Server\Service('Thesis.Queue.V1.QueueService', [ new Server\Rpc( - new Server\Handle('Push', \Thesis\Queue\PushRequest\Message::class), - new Server\ClientStreamHandler($this->server->push(...)), - Server\RpcType::ClientStream, + handle: new Server\Handle('Push', \Thesis\Queue\PushRequest\Message::class), + handler: new Server\ClientStreamHandler($this->server->push(...)), + type: Grpc\RpcType::ClientStream, ), new Server\Rpc( - new Server\Handle('Pull', \Thesis\Queue\PullRequest::class), - new Server\ServerStreamHandler($this->server->pull(...)), - Server\RpcType::ServerStream, + handle: new Server\Handle('Pull', \Thesis\Queue\PullRequest::class), + handler: new Server\ServerStreamHandler($this->server->pull(...)), + type: Grpc\RpcType::ServerStream, ), new Server\Rpc( - new Server\Handle('Heartbeat', \Thesis\Queue\Heartbeat\FromClient\Ping::class), - new Server\BidirectionalStreamHandler($this->server->heartbeat(...)), - Server\RpcType::BidirectionalStream, + handle: new Server\Handle('Heartbeat', \Thesis\Queue\Heartbeat\FromClient\Ping::class), + handler: new Server\BidirectionalStreamHandler($this->server->heartbeat(...)), + type: Grpc\RpcType::BidirectionalStream, ), ]); }