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

Delete using query inside transaction is missing support #68

Open
eduardo-marcolino opened this issue Dec 8, 2022 · 0 comments
Open

Comments

@eduardo-marcolino
Copy link

According to the documentation (https://www.sanity.io/docs/http-mutations#d8ebd1878516l) one should be able to pass a query to delete inside a transaction:

{
  "mutations": [
    {
      "delete": {
        "query": "*[_type == 'feature' && viewCount < $views]",
        "params": {
          "views": 5
        },
      }
    }
  ]
}

But doing the following gives an error:

    const transaction = new sanityClient.Transaction()
    transaction.delete({query: '*[_type == "apartment"]'})
    //... other operations
    accountClient.mutate(transaction)
Error: delete(): "[object Object]" is not a valid document ID
    at Object.exports.validateDocumentId (node_modules/@sanity/client/lib/validators.js:42:11)
    at Transaction._delete [as delete] (node_modules/@sanity/client/lib/data/transaction.js:47:16)
    at Object.importApartmentsTo (/app/netlify/src/provider/accounts.js:45:29)
    at module.exports (app/netlify/src/usecase/handleSingleAccountImport.js:11:18)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Object.exports.handler (app/netlify/functions/fetch-account.js:19:5)

node_modules/@sanity/client/lib/data/transaction.js:46:

  delete: function _delete(documentId) {
    validators.validateDocumentId('delete', documentId);
    return this._add({
      delete: {
        id: documentId
      }
    });
  },

I'm using @sanity/client 3.4.1.
is there a way to work around it?

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

1 participant