payload is now optional in connection_init message (close #470) (#471)

This commit is contained in:
Vamshi Surabhi 2018-09-18 13:13:30 +05:30 committed by Shahidh K Muhammed
parent 534f23d1a6
commit 85df9ac1e8
3 changed files with 15 additions and 5 deletions

View File

@ -257,8 +257,8 @@ onStop serverEnv wsConn (StopMsg opId) = do
onConnInit
:: (MonadIO m)
=> L.Logger -> H.Manager -> WSConn -> AuthMode -> ConnParams -> m ()
onConnInit logger manager wsConn authMode connParams = do
=> L.Logger -> H.Manager -> WSConn -> AuthMode -> Maybe ConnParams -> m ()
onConnInit logger manager wsConn authMode connParamsM = do
res <- runExceptT $ getUserInfo logger manager headers authMode
case res of
Left e ->
@ -272,7 +272,7 @@ onConnInit logger manager wsConn authMode connParams = do
sendMsg wsConn SMConnKeepAlive
where
headers = [ (CI.mk $ TE.encodeUtf8 h, TE.encodeUtf8 v)
| (h, v) <- maybe [] Map.toList $ _cpHeaders connParams
| (h, v) <- maybe [] Map.toList $ connParamsM >>= _cpHeaders
]
onClose

View File

@ -44,7 +44,7 @@ data StopMsg
$(J.deriveJSON (J.aesonDrop 3 J.snakeCase) ''StopMsg)
data ClientMsg
= CMConnInit !ConnParams
= CMConnInit !(Maybe ConnParams)
| CMStart !StartMsg
| CMStop !StopMsg
| CMConnTerm
@ -60,7 +60,7 @@ instance J.FromJSON ClientMsg where
parseJSON = J.withObject "ClientMessage" $ \obj -> do
t <- obj J..: "type"
case t of
"connection_init" -> CMConnInit <$> obj J..: "payload"
"connection_init" -> CMConnInit <$> obj J..:? "payload"
"start" -> CMStart <$> J.parseJSON (J.Object obj)
"stop" -> CMStop <$> J.parseJSON (J.Object obj)
"connection_terminate" -> return CMConnTerm

View File

@ -27,6 +27,16 @@ class TestSubscriptionBasic(object):
ev = hge_ctx.get_ws_event(3)
assert ev['type'] == 'connection_ack', ev
'''
Refer: https://github.com/apollographql/subscriptions-transport-ws/blob/master/PROTOCOL.md#gql_connection_init
'''
def test_init_no_payload(self, hge_ctx):
obj = {
'type': 'connection_init'
}
hge_ctx.ws.send(json.dumps(obj))
ev = hge_ctx.get_ws_event(3)
assert ev['type'] == 'connection_ack', ev
'''
Refer: https://github.com/apollographql/subscriptions-transport-ws/blob/master/PROTOCOL.md#gql_connection_error
'''