MoralisWeb3/unity-web3-game-kit

AddSubscription is broken by WhereEqualTo

christopher-r-brech opened this issue · 7 comments

Summary

When feeding a query with .WhereEqualTo("key", value) to MoralisLiveQueryController.AddSubscription, there seems to be a breakdown somewhere between the SDK and the Moralis server. The subscription fails and errors are returned.

Background

In our JavaScript version of our code, we use .equalTo in our subscription. While I am not completely confident this has been doing what I expected, I do know that the subscription is still successful.

Being able to only receive updates when specific entries in a Class are updated allows us to maintain only a single subscription per user.

Code

var query = MoralisInterface.GetClient().Query<MyMoralisClass>().WhereEqualTo("roomId", roomId);
MoralisLiveQueryController.AddSubscription("MyMoralisClass", query, callbacks);

Expected

Either

  1. (preferable) The subscription is successful and we get updates based on the query.
  2. A warning stating that the WhereEqualTo is not compatible with AddSubscription and was ignored.

Result

OnGeneralMessageEvent reports "Received message $error"
OnErrorEvent returns:

em.code 1
em.error Invalid type: string (expected object)
em.requestId

And the Moralis Dashboard Logs show:

2022-03-02T17:26:48.413Z - Connect message error %s

Miscellaneous Info

  • Using just MoralisInterface.GetClient().Query<MyMoralisClass>() works, but is not ideal.
  • All of our regular queries using .WhereEqualTo work as expected.
  • This issue is in reference to a Windows build as we use JavaScript-based code for our WebGL builds. I will update this issue if I see the same problem when using MoralisInterface with UNITY_WEBGL defined.

I will need to research this ...

My initial test succeeded with a WhereEqualTo condition. I created the query and then created, updated an deleted records. I used Callbacks set to debug the results and saw the expected messages.

I will try this some more, however are you using MoralisObject straight as you indicated above?

Thank you.

I'm not sure what you mean by "straight as [I] indicated above", but here's more of our actual code. It all works until I put the WhereEqualTo("roomId", roomId) on there.

We are using SDK version 1.0.5 and our server version is 0.0.349

namespace MoralisObjectClass
{
    public class Battle : MoralisObject
    {
        public PlayerBattleData owner;
        public PlayerBattleData opponent;
        public BattleStepResult[] result;
        public string roomId;
    }
}
private async void SubscribeToRoom(string roomId)
{
    var callbacks = new MoralisLiveQueryCallbacks<MoralisObjectClass.Battle>();
    callbacks.OnConnectedEvent    += (() =>          Debug.Log("Connection Established for upcoming Battle Subscription."));
    callbacks.OnSubscribedEvent   += ((requestId) => Debug.Log($"Subscribed to Battles."));
    callbacks.OnUnsubscribedEvent += ((requestId) => Debug.Log($"Unsubscribed from Battles."));
    callbacks.OnErrorEvent  += ((ErrorMessage em) => Debug.LogError($"Moralis Live Query ERROR | code: {em.code}, msg: {em.error}, requestId: {em.requestId}."));
    callbacks.OnCreateEvent += ((item, requestId) => Debug.Log($"A new Battle was Created in room {item.roomId} between PID_{item.owner.playerId} and PID_{item.opponent.playerId}."));
    callbacks.OnUpdateEvent += ((item, requestId) => OnBattlesUpdated(item));
    callbacks.OnDeleteEvent += ((item, requestId) => Debug.Log($"A battle between PID_{item.owner.playerId} and PID_{item.opponent.playerId} was removed from room {item.roomId}."));
    callbacks.OnGeneralMessageEvent += ((text) =>    Debug.Log($"BattleManager Subscription Event: {text}"));

    var query = MoralisInterface.GetClient().Query<MoralisObjectClass.Battle>().WhereEqualTo("roomId", roomId);
    MoralisLiveQueryController.AddSubscription("Battle", query, callbacks);
}

private void OnBattlesUpdated(MoralisObjectClass.Battle battleUpdate)
{
    // do stuff with the battle update
}

I will look some more. Are you building to WebGL or something else?

Also at v1.0.5 your project is missing a few critical updates, though these probably would not impact LiveQueries.

This issue occurs in Windows standalone builds.

When we build in WebGL we do not depend on this repo yet.

I will pass the suggestion to update on to my team.

My team and I appreciate your taking the time to look into this issue.

Have not heard back from the user. Closing.

Hi there,
Any fix to WhereEqualTo ?
Thanks