import json

from clarabot_testing.client.gql_ws import AbstractGraphQlWebSocketClient

from clarabot_nano.utility.serialize import msgpack_dumps, msgpack_loads


class GraphQlWebSocketClient(AbstractGraphQlWebSocketClient):
    def _load_received_data(self, data):
        try:
            return json.loads(data)
        except Exception:
            pass
        return msgpack_loads(data)

    def _dump_data_to_be_sent(self, data):
        return msgpack_dumps(data)
