itsmeurbi / squid-use-observable-issue

0 stars 0 forks source link

Discussion #1

Open ohsnapitscolin opened 1 month ago

ohsnapitscolin commented 1 month ago

Hey @itsmeurbi! Colin from Squid here.

After reading through the README and code, I believe the issue you're seeing occurs because Squid does not yet support subscribing to "external changes" to a database (eg. changes that are made outside of Squid mutations).

In your example, you're calling the following on an interval, which means every call triggers a new query, and fetches the most recent state of the database. This is why you see your changes.

squid.collection('my_collection', 'integration_name').query().dereference().snapshot()

However when using snapshots() with useObservable (or alternatively useQuery), you're subscribing to changes to the database, instead of re-issuing a new query every X seconds. Since we don't support sending changes from external sources, you won't receive the updates you're making inside of the Mongo UI.

The easiest way to verify this is to insert users through Squid instead of the Mongo UI. Adding something like the following to your App.js will insert a new user through Squid every 5 seconds. In this case, you should see the updates come through when using useObservable.

useEffect(() => {
  const interval = setInterval(async () => {
    await usersCollectionRef.doc().insert({ name: "Colin" });
  }, 5000);

  return () => clearInterval(interval)
}, [])

Note: You may need to use .doc({ _id: ... }) or .doc({ name: ... }) depending on how you've defined your primary keys.

We do have plans to support external changes in the future, but just want to make sure that this solves the issue on your end in the meantime.

Thanks!

itsmeurbi commented 1 month ago

I see! Thanks a lot @ohsnapitscolin for looking into my report and for the clarification! 🙌🏻 There is one more thing I notices with usePagination. In case you're interested, I created another repo for it right here This time I uploaded the evidence video to Youtube