-
Notifications
You must be signed in to change notification settings - Fork 11
Improve DX for Query-based sync GraphQL #39
Comments
There are performance implications of such a design. Bootstrapping a partial Realm is not a cheap operation and neither is subscribing/unsubscribing, so it would be extremely wasteful to unsubscribe every time the client disconnects. The general guideline is to design your web app in a similar fashion as the native app, where you will check the existing Realm subscriptions and confirm if the one you need is already present. If it is, then you simply create a GraphQL subscription, otherwise, you create a Realm subscription followed by a GraphQL one. While it's tempting to combine both in a single API call,
It's possible that I'm missing something because I don't see any huge benefits. The way I imagine your code should look like is: const subscriptions = await getRealmSubscriptions();
const query = "age > 18";
if (!subscriptions.find(s => s.name === "peopleScreen")) {
await createRealmSubscription(query);
}
await subscribeForChanges(query); So, yes, it adds some boilerplate, but you can easily write a helper function that does most of it and can be used in your various screens. I'll have to admin, I'm not a front-end developer, so it's possible that I'm overlooking some obvious improvement/use case and if that's the case, please let me know with some specific examples, but for the time being, it's unlikely we'll revisit this design. |
Why it is working differently for the native clients then? When you subscribe to data in native, it indicates that you want to get matching elements from the reference database AND that you get the results as they change. You can probably remove the requirement of auto subscription removal if it has negative impacts. Here in GraphQL every user will need to create subscriptions + create subscribe mutations. Is it possible as a workaround to add the functionality of :
Thanks for your feedback, Regards, Pierre |
Just an update I could make the subscription mutation work with Realm Cloud also. It is just missing from GraphiQL (probably because we open it in full mode) The 2 following points remain interesting for us :
|
You can probably add in the documentation that it is possible to nest elements as in any other GraphQL mutation, allowing (hopefully) a global subscribe of all related classes and that createXXXSubscription use the singular form of Classes name. Example :
|
GraphiQL is not showing available Query-based sync mutations (at least in Realm Cloud) and having to do a mutation in order to later get the results in a subscription is a huge pain.
Please can you create Query-based subscriptions on the fly when we start a GraphQL subscription ? You can probably for performance concerns de-duplicate them if needed and unsubscribe when the client closes ? This issue and #36 are currently my main issues to use GraphQL with a good level of maturity.
Note: you may have to mark those queries as created from GraphQL if you want to avoid edge cases when mixing with native client
The text was updated successfully, but these errors were encountered: