@@ -20,7 +20,7 @@ and protocol.
20
20
-}
21
21
module Mu.Rpc (
22
22
Package' , Package (.. )
23
- , Service' , Service (.. ), Object
23
+ , Service' , Service (.. ), Object , Union
24
24
, Method' , Method (.. ), ObjectField
25
25
, LookupService , LookupMethod
26
26
, TypeRef (.. ), Argument' , Argument (.. ), Return (.. )
@@ -56,6 +56,7 @@ data Package serviceName methodName argName tyRef
56
56
data Service serviceName methodName argName tyRef
57
57
= Service serviceName
58
58
[Method serviceName methodName argName tyRef ]
59
+ | OneOf serviceName [serviceName ]
59
60
60
61
-- | A method is defined by its name, arguments, and return type.
61
62
data Method serviceName methodName argName tyRef
@@ -66,6 +67,8 @@ data Method serviceName methodName argName tyRef
66
67
-- Synonyms for GraphQL
67
68
-- | An object is a set of fields, in GraphQL lingo.
68
69
type Object = 'Service
70
+ -- | A union is one of the objects.
71
+ type Union = 'OneOf
69
72
-- | A field in an object takes some input objects,
70
73
-- and returns a value or some other object,
71
74
-- in GraphQL lingo.
@@ -76,6 +79,7 @@ type family LookupService (ss :: [Service snm mnm anm tr]) (s :: snm)
76
79
:: Service snm mnm anm tr where
77
80
LookupService '[] s = TypeError ('Text " could not find method " ':<>: 'ShowType s )
78
81
LookupService ('Service s ms ': ss ) s = 'Service s ms
82
+ LookupService ('OneOf s ms ': ss ) s = 'OneOf s ms
79
83
LookupService (other ': ss ) s = LookupService ss s
80
84
81
85
-- | Look up a method in a service definition using its name.
@@ -136,7 +140,7 @@ data RpcInfo i
136
140
= NoRpcInfo
137
141
| RpcInfo { packageInfo :: Package Text Text Text TyInfo
138
142
, serviceInfo :: Service Text Text Text TyInfo
139
- , methodInfo :: Method Text Text Text TyInfo
143
+ , methodInfo :: Maybe ( Method Text Text Text TyInfo )
140
144
, headers :: RequestHeaders
141
145
, extraInfo :: i
142
146
}
@@ -150,10 +154,15 @@ data TyInfo
150
154
instance Show (RpcInfo i ) where
151
155
show NoRpcInfo
152
156
= " <no info>"
153
- show (RpcInfo (Package Nothing _) (Service s _) (Method m _ _) _ _)
154
- = T. unpack (s <> " :" <> m)
155
- show (RpcInfo (Package (Just p) _) (Service s _) (Method m _ _) _ _)
156
- = T. unpack (p <> " :" <> s <> " :" <> m)
157
+ show (RpcInfo (Package p _) s m _ _)
158
+ = T. unpack $ showPkg p (showMth m (showSvc s))
159
+ where
160
+ showPkg Nothing = id
161
+ showPkg (Just pkg) = ((pkg <> " :" ) <> )
162
+ showMth Nothing = id
163
+ showMth (Just (Method mt _ _)) = (<> (" :" <> mt))
164
+ showSvc (Service sv _) = sv
165
+ showSvc (OneOf sv _) = sv
157
166
158
167
class ReflectRpcInfo (p :: Package' ) (s :: Service' ) (m :: Method' ) where
159
168
reflectRpcInfo :: Proxy p -> Proxy s -> Proxy m -> RequestHeaders -> i -> RpcInfo i
@@ -175,6 +184,13 @@ instance KnownMaySymbol 'Nothing where
175
184
instance (KnownSymbol s ) => KnownMaySymbol ('Just s ) where
176
185
maySymbolVal _ = Just $ T. pack $ symbolVal (Proxy @ s )
177
186
187
+ class KnownSymbols (m :: [Symbol ]) where
188
+ symbolsVal :: Proxy m -> [Text ]
189
+ instance KnownSymbols '[] where
190
+ symbolsVal _ = []
191
+ instance (KnownSymbol s , KnownSymbols ss ) => KnownSymbols (s ': ss ) where
192
+ symbolsVal _ = T. pack (symbolVal (Proxy @ s )) : symbolsVal (Proxy @ ss )
193
+
178
194
class ReflectServices (ss :: [Service' ]) where
179
195
reflectServices :: Proxy ss -> [Service Text Text Text TyInfo ]
180
196
instance ReflectServices '[] where
@@ -204,14 +220,20 @@ instance (KnownMaySymbol pname, ReflectServices ss, ReflectService s, ReflectMet
204
220
reflectRpcInfo _ ps pm req extra
205
221
= RpcInfo (Package (maySymbolVal (Proxy @ pname ))
206
222
(reflectServices (Proxy @ ss )))
207
- (reflectService ps) (reflectMethod pm) req extra
223
+ (reflectService ps) (Just ( reflectMethod pm) ) req extra
208
224
209
225
instance (KnownSymbol sname , ReflectMethods ms )
210
226
=> ReflectService ('Service sname ms ) where
211
227
reflectService _
212
228
= Service (T. pack $ symbolVal (Proxy @ sname ))
213
229
(reflectMethods (Proxy @ ms ))
214
230
231
+ instance (KnownSymbol sname , KnownSymbols elts )
232
+ => ReflectService ('OneOf sname elts ) where
233
+ reflectService _
234
+ = OneOf (T. pack $ symbolVal (Proxy @ sname ))
235
+ (symbolsVal (Proxy @ elts ))
236
+
215
237
instance (KnownSymbol mname , ReflectArgs args , ReflectReturn r )
216
238
=> ReflectMethod ('Method mname args r ) where
217
239
reflectMethod _
0 commit comments