import json

from clarabot_nano_common.utility.serialize import msgpack_dumps, msgpack_loads
from clarabot_testing.client.gql_ws import AbstractGraphQlWebSocketClient


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)
