Skip to content
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

Updates to documents fail when graphql replication plugin is enabled #1812

Closed
gautambt opened this issue Dec 22, 2019 · 1 comment
Closed

Comments

@gautambt
Copy link

gautambt commented Dec 22, 2019

Issue

Enabling graphql plugin leads to document updates faiingl with the error below. The issue can be reproduced by applying the patch in the code section. The issue occurs because the graphql plugin creates two keys _revisions and _deleted that are not part of the schema. I can raise a pull request with a fix if someone can guide me on the right approach for fixing this. I have tried two approaches without success:

  1. adding _deleted and _revisions to the schema in rxSchema but that seemed to fail because rxDocument.ts tries to set _deleted$.

  2. Remove the keys in handleDocumentFromRemote before the event emitting but in this case deleted documents will not raise an event.

Error stack trace

rx-error.js:129 Uncaught (in promise) RxError: RxError:
object does not match schema
Given parameters: {
errors:[
  {
    "field": "data",
    "message": "has additional properties"
  },
  {
    "field": "data",
    "message": "has additional properties"
  }
]
obj:{
  "name": "Spiderman",
  "color": "Red",
  "updatedAt": 1576988945,
  "_deleted": false,
  "_revisions": {
    "start": 2,
    "ids": [
      "64ce14acf3846743rxdbreplicationgraphql",
      "5bcd1241391d47aba8a73e51af84ce63"
    ]
  },
  "_rev": "2-64ce14acf3846743rxdbreplicationgraphql",
  "id": "Spiderman"
}
schema:{
  "version": 0,
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "primary": true
    },
    "name": {
      "type": "string",
      "index": true
    },
    "color": {
      "type": "string",
      "index": true
    },
    "updatedAt": {
      "type": "number",
      "index": true
    },
    "_rev": {
      "type": "string",
      "minLength": 1
    },
    "_attachments": {
      "type": "object"
    }
  },
  "required": [
    "color",
    "id"
  ],
  "additionalProperties": false,
  "keyCompression": false,
  "compoundIndexes": []
}}
    at newRxError (webpack:///./node_modules/rxdb/dist/es/rx-error.js?:129:10)
    at RxSchema.validate (webpack:///./node_modules/rxdb/dist/es/plugins/validate.js?:49:71)
    at eval (webpack:///./node_modules/rxdb/dist/es/rx-document.js?:300:32)

Info

  • Environment: Browser
  • Adapter: IndexDB
  • Stack: Javascript

Code

The issue can be reproduced by applying this patch to the graphql example:

diff --git a/examples/graphql/client/index.js b/examples/graphql/client/index.js
index d211fe5c..d3bf99c5 100644
--- a/examples/graphql/client/index.js
+++ b/examples/graphql/client/index.js
@@ -19,6 +19,9 @@ RxDB.plugin(RxDBErrorMessagesModule);
 import RxDBValidateModule from 'rxdb/plugins/validate';
 RxDB.plugin(RxDBValidateModule);
 
+import UpdatePlugin from 'rxdb/plugins/update';
+RxDB.plugin(UpdatePlugin);
+
 import {
     GRAPHQL_PORT,
     GRAPHQL_PATH,
@@ -260,6 +263,19 @@ async function run() {
         document.querySelector('input[name="name"]').value = '';
         document.querySelector('input[name="color"]').value = '';
     };
+
+    setInterval(async () => {
+        const heros = await collection.find().exec();
+        heros.forEach((hero) => {
+            console.log(hero.toJSON())
+
+            hero.update({
+                $set: {
+                    updatedAt: Math.round(new Date().getTime() / 1000)
+                }
+              })
+        })
+    }, 5000)
 }
 run().catch(err => {
     console.log('run() threw an error:');
@pubkey pubkey closed this as completed in 5ec8cba Jan 3, 2020
@pubkey
Copy link
Owner

pubkey commented Jan 3, 2020

@gautambt thank you for the great investigation and example code.
I could reproduce and fix the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants