-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow truthy values for the GraphQL replication deletedFlag
field.
#3644
Allow truthy values for the GraphQL replication deletedFlag
field.
#3644
Conversation
For me it looks like this would create a burden for every future implementation of RxStorage. CouchDB does only allow boolean values for _deleted, see here Gitbook is not maintained, this is why I run it in an old node.js version in the CI. Related |
I'm not sure what the burden is. Could you please elaborate? The change I made is in the GraphQL replication layer, so as far as I can tell, it doesn't matter what the underlying storage mechanism is. There's already an implicit requirement in the replication layer that the |
Okay. I took another look and it's rx-storage-loki that is enforcing a Boolean value on the |
Hi @nirvdrum Merged, thank you for your work. |
@pubkey No worries. Thanks for taking a look. I'm still building a mental model of RxDB, so I appreciate you taking a critical look at what I've been proposing. I try to ensure backwards-compatibility in everything, but there are invariably cases I'm unaware of. Thanks for the merge. If you're looking to release just for me, you don't need to rush. I'm running a fork at the moment until I can finish up the work on #3630. |
To follow-up on this part, I was mistaken about what PouchDB was doing. I forgot that I had run into an issue where adding a sort option to a query in PouchDB added in deleted documents. To deal with that, I had wrapped all of my queries with |
This PR contains:
Describe the problem you have without this PR
I'm replicating from a GraphQL store in front of a PostgreSQL database. Handling soft deletion in relational databases by storing a
deletedAt
|deleted_at
timestamp column rather than a boolean flag is a common practice. While I could wrap the whole thing with a view to expose a boolean flag, it would be handy if I could use this timestamp directly.I thought maybe RxDB handled truthy values for the
deletedFlag
by default. This seemed to work fine with PouchDB, but when I tried LokiJS, I ran into a confusing problem. When data was pulled from the GraphQL service, it would show in the web app immediately. But, when the web app was reloaded, the data wouldn't show. I tracked that down to queries having thewhere('_deleted').eq(false)
selector appended by default. In my case, the_deleted
value was a nullable timestamp, so either there was a string present with an ISO 8601 datetime string or the JavaScript valuenull
. Neither of those value isfalse
, so Loki would fail to find any documents.I think supporting truthy values here would allow RxDB to work with a more diverse set of GraphQL servers. If someone needs more advanced rules (e.g., maybe they use an enum and values are always "true" in JavaScript) then a more comprehensive solution would be needed, maybe in the
modifier
callback. But, allowing truthy values here supports real world cases that were not well-supported before.Moreover, I think this PR closes a usability gap with RxDB. By allowing non-Boolean values to be stored in the
_deleted
property of the store document, there's a confusing situation where freshly pulled documents show up in query results because they already exist in memory but fail to load from persisted storage because of the malformed_deleted
value.Todos
I added documentation for this change, but I was unable to run GitBook locally. I tried all of the NPM scripts in package.json and each time I got the following:
I'll try to figure out what is going on there. But, the point is I wrote the docs with a local Markdown editor plugin but was not able to verify the build documentation looks good.