From 85df9ac1e83828ca2543d56eff148537d65f7f58 Mon Sep 17 00:00:00 2001 From: Vamshi Surabhi <0x777@users.noreply.github.com> Date: Tue, 18 Sep 2018 13:13:30 +0530 Subject: [PATCH] payload is now optional in connection_init message (close #470) (#471) --- server/src-lib/Hasura/GraphQL/Transport/WebSocket.hs | 6 +++--- .../Hasura/GraphQL/Transport/WebSocket/Protocol.hs | 4 ++-- server/tests-py/test_subscriptions.py | 10 ++++++++++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/server/src-lib/Hasura/GraphQL/Transport/WebSocket.hs b/server/src-lib/Hasura/GraphQL/Transport/WebSocket.hs index 736dd07788f..ff9701a6a27 100644 --- a/server/src-lib/Hasura/GraphQL/Transport/WebSocket.hs +++ b/server/src-lib/Hasura/GraphQL/Transport/WebSocket.hs @@ -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 diff --git a/server/src-lib/Hasura/GraphQL/Transport/WebSocket/Protocol.hs b/server/src-lib/Hasura/GraphQL/Transport/WebSocket/Protocol.hs index 0274d65162e..914f37da98e 100644 --- a/server/src-lib/Hasura/GraphQL/Transport/WebSocket/Protocol.hs +++ b/server/src-lib/Hasura/GraphQL/Transport/WebSocket/Protocol.hs @@ -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 diff --git a/server/tests-py/test_subscriptions.py b/server/tests-py/test_subscriptions.py index ffb0317a219..1918b963323 100644 --- a/server/tests-py/test_subscriptions.py +++ b/server/tests-py/test_subscriptions.py @@ -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 '''