Skip to content

feat(use_case): add gRPC transport for UseCaseService#66

Open
allmonday wants to merge 1 commit into
masterfrom
feat/grpc-support
Open

feat(use_case): add gRPC transport for UseCaseService#66
allmonday wants to merge 1 commit into
masterfrom
feat/grpc-support

Conversation

@allmonday

Copy link
Copy Markdown
Collaborator

Summary

Add create_use_case_grpc_server() — a new transport dispatcher that exposes UseCaseService methods as unary gRPC RPCs over JSON.

  • JSON-over-gRPC: No protobuf code generation needed. Request/response bodies are JSON-encoded bytes.
  • Service mapping: Each UseCaseService becomes a gRPC service, each @query/@mutation method becomes a unary RPC
  • FromContext: Injected from gRPC metadata
  • Error mapping: Python exceptions → gRPC status codes (NOT_FOUND, INVALID_ARGUMENT, PERMISSION_DENIED, INTERNAL)
  • Optional dep: pip install nexusx[grpc] (only grpcio>=1.60.0)

Usage

from nexusx import UseCaseAppConfig, create_use_case_grpc_server

server = create_use_case_grpc_server(
    UseCaseAppConfig(name="project", services=[UserService]),
    port=50051,
)
await server.start()

Client calls /UserService/list_users with JSON body {}, gets back {"result": [...]}.

Test plan

  • 14 tests covering basic invocation, errors, FromContext, server lifecycle
  • Full test suite passes (933 passed)
  • Demo runs end-to-end (demo/use_case/grpc_demo.py)
  • Lint passes

🤖 Generated with Claude Code

New `create_use_case_grpc_server()` exposes UseCaseService methods as
unary gRPC RPCs using JSON-over-gRPC (no protobuf code generation).
Each UseCaseService becomes a gRPC service, each @query/@mutation
method becomes a unary RPC.

FromContext params are injected from gRPC metadata. Error codes map
to gRPC status codes (NOT_FOUND, INVALID_ARGUMENT, PERMISSION_DENIED, etc).

Optional dependency: `pip install nexusx[grpc]`

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant