MikeBild / graphql-pouch

GraphQL runtime using PouchDB
MIT License
204 stars 13 forks source link

Upsert without revision number? #28

Open simonwjackson opened 6 years ago

simonwjackson commented 6 years ago

im new to graphql, so maybe im missing something here

mutation {
  upsertHuman(input: {id: "lskywalker", name: "L. Skywalker", homePlanet: "Tatooine"})
}

results in...

{
  "data": {
    "upsertHuman": null
  },
  "errors": [
    {
      "message": "Document update conflict",
      "locations": [
        {
          "line": 29,
          "column": 3
        }
      ],
      "stack": "Document update conflict"
    }
  ]
}

I'd like to upsert based on the ID and ignore the revision. Is this possible?

MikeBild commented 6 years ago

short answer: no, because couchdb / pouchdb needs the revision number to manage a concurrency access for updates and deletes. You can pass through the data from the query (rev-field). Is that working in your scenario?

simonwjackson commented 6 years ago

So, I would need to obtain the rev-number in one query, and use the obtained rev number in a separate mutation query?

MikeBild commented 6 years ago

Exactly thats the way to go.

simonwjackson commented 6 years ago

thats too bad, that seems like it would cause alot of overhead when updating many documents.

there is a upsert plugin that doesn't seem to require a rev id, are they doing some magic behind the scenes?