Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 22 additions & 16 deletions src/Plugin/Generator/GrpcGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -314,6 +319,7 @@ public function generateServerRegistry(Parser\ServiceDescriptor $service): PhpNa

$namespace->add($classType);

$namespace->addUse('Thesis\Grpc');
$namespace->addUse('Thesis\Grpc\Server');

$handlers = [];
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion tests/snapshots/deprecated/Test/Api/V1/EchoServiceClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
namespace Test\Api\V1;

use Override;
use Thesis\Grpc;
use Thesis\Grpc\Server;

/**
Expand All @@ -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,
),
]);
}
Expand Down
4 changes: 3 additions & 1 deletion tests/snapshots/grpc/Thesis/Auth/V1/AuthServiceClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
namespace Thesis\Auth\V1;

use Override;
use Thesis\Grpc;
use Thesis\Grpc\Server;

/**
Expand All @@ -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,
),
]);
}
Expand Down
10 changes: 7 additions & 3 deletions tests/snapshots/grpc/Thesis/Queue/V1/QueueServiceClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use Amp\Cancellation;
use Amp\NullCancellation;
use Thesis\Grpc;
use Thesis\Grpc\Client;
use Thesis\Grpc\Metadata;

Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
namespace Thesis\Queue\V1;

use Override;
use Thesis\Grpc;
use Thesis\Grpc\Server;

/**
Expand All @@ -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,
),
]);
}
Expand Down
Loading