1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//! gRPC service adapter
//!
//! This module provides traits for integrating gRPC services into
//! other framework components (e.g., GraphQL resolvers).
use async_trait;
/// Trait for integrating gRPC services into GraphQL resolvers
///
/// # Examples
///
/// ```rust,no_run
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// use reinhardt_grpc::adapter::GrpcServiceAdapter;
/// use async_trait::async_trait;
/// # use tonic::Status;
/// #
/// # // Mock User type for doctest
/// # struct User {
/// # id: String,
/// # name: String,
/// # }
///
/// struct UserServiceAdapter {
/// // gRPC client connection
/// }
///
/// #[async_trait]
/// impl GrpcServiceAdapter for UserServiceAdapter {
/// type Input = String; // User ID
/// type Output = User; // GraphQL User type
/// type Error = Status;
///
/// async fn call(&self, input: Self::Input) -> Result<Self::Output, Self::Error> {
/// // Example implementation: Fetch user information using gRPC client
/// // let response = self.grpc_client.get_user(input).await?;
/// // Ok(User::from_proto(response))
/// # unimplemented!("Replace with actual gRPC implementation")
/// }
/// }
/// # Ok(())
/// # }
/// ```
/// Trait for integrating gRPC Subscriptions into GraphQL Subscriptions
///
/// # Examples
///
/// ```rust,no_run
/// use reinhardt_grpc::adapter::GrpcSubscriptionAdapter;
/// # use tonic::Status;
/// #
/// # // Mock types for doctest
/// # struct User {
/// # id: String,
/// # name: String,
/// # }
/// #
/// # mod proto {
/// # pub struct UserEvent {
/// # pub user_id: String,
/// # pub name: String,
/// # }
/// # }
///
/// struct UserEventsAdapter;
///
/// impl GrpcSubscriptionAdapter for UserEventsAdapter {
/// type Proto = proto::UserEvent;
/// type GraphQL = User;
/// type Error = Status;
///
/// fn map_event(&self, proto: Self::Proto) -> Option<Self::GraphQL> {
/// // Example implementation: Convert Protobuf event to GraphQL type
/// // Some(User {
/// // id: proto.user_id,
/// // name: proto.name,
/// // })
/// # None
/// }
///
/// fn handle_error(&self, error: Self::Error) -> String {
/// error.to_string()
/// }
/// }
/// ```