cloudant / nodejs-cloudant

Cloudant Node.js client library
Apache License 2.0
255 stars 90 forks source link

IBM Cloudant queries deprecation breaking official Cloudant JS library #422

Closed endemecio02 closed 3 years ago

endemecio02 commented 4 years ago

Bug Description

IBM's official Cloudant JavaScript library has not been updated to account for the queries deprecation change. https://cloud.ibm.com/docs/Cloudant?topic=Cloudant-deprecations#replaced-queries-parameter

The queries parameter for performing multiple view queries in a single request will no longer be accepted as a URL parameter for GET /{db}/_design/{ddoc}/_view/{view} or a request body parameter for POST /{db}/_design/{ddoc}/_view/{view}. It's replaced with the endpoint POST /{db}/_design/{ddoc}/_view/{view}/queries where it's supplied as a queries request body parameter.

1. Steps to reproduce and the simplest code sample possible to demonstrate the issue

send a multi-query request to any view

cloudant.view("campaigns", "all", {queries: [{
  include_docs: true,
  key: {with_template: false},
}]}).then(({results}) => {
  console.log(results);
}).catch(err => {
  console.error(err);
});

2. What you expected to happen

response with results

3. What actually happened

cloudant error message: "The queries parameter is no longer supported at this endpoint"

Environment details

node v12.16.3 @cloudant/cloudant@4.2.4

emlaver commented 4 years ago

@endemecio02 to make a multi-query view request you'll need to make a custom request using cloudant.request(...) against _view/{view}/queries e.g.

var Cloudant = require('@cloudant/cloudant');
var cloudant = Cloudant({url: process.env.CLOUDANT_URL});

cloudant.request({
  db: 'users',
  path: '_design/new-ddoc/_view/newview/queries',
  method: 'post',
  body: {queries: [
    {limit: 1},
    {include_docs: true}
  ]}
}, function(err, data) {
  console.log('Error:', err);
  console.log('Data:', data);
});
endemecio02 commented 4 years ago

thank you @emlaver that's what I've done to fix the issue for now. But this is more of a hack. The official Cloudant library should be able to handle this. I should be able to call cloudant.view(, , {queries}) like before and the library should translate it to the appropriate request.

ricellis commented 3 years ago

The API change for this was also in CouchDB and a fix for it should go into nano upstream. We're unlikely to consume that fix here as our request based plugin structures are not compatible with the latest versions of Nano.

However, our new cloudant-node-sdk(beta) has full compatibility for this via specific functions for single and multiple view queries.