callAsync doesn't respect params

Hi, having a bit of trouble wrapping my head around the 3.0 migration. I’ve tried the following code, but it doesn’t reflect the “limit” - it’s always undefined.

CLIENT

var query = {userId:Meteor.userId()}
var limit = 5
Meteor.call('getCombinedData',query,limit,(err,res) => {
  console.log(err,res)
})

SERVER

async getBasicData(query,limit) {
  // `limit` is always undefined here, but `query` is fine
  return await Data.find(query,{limit}).fetchAsync()
}

async getCombinedData(query,limit) {
   var data = await Meteor.callAsync('getBasicData',query,limit)
   // do something else with data
   return data
}

Is there an obvious mistake at play here?

The issue in your code seems to be about the way you’re passing the limit parameter from the client to the server. I can see that you’re passing it as a separate argument in the Meteor.call method, but it doesn’t get correctly received on the server side.

To fix this, you can tryt passing the limit parameter as part of the options object within the Meteor.call method.

Can’t tell you what the solution is, but I ended up never calling any piece of the Meteor API directly given how brittle it has become. Implement your own abstraction on top of Meteor’s API, update it when Meteor breaks it. This approach scales with code base size. The cons is that it requires more experience from whoever is implementing it.

I am on Meteor 2.12 and the only method calling API function I use from the client is applyAsync, which I had to wrap with the wrapper they have added to callAsync. I also never call methods with Meteor’s API from the server, I just call the function that corresponds to the method which comes for free when you have your own implementation of “validated methods”.

I am curious as to why you are having problems though. The implementation of callAsync is trivial on the server, and the implementation of call on the client should not swallow the last parameter if it’s not a function.

What Meteor version are you running?

That’s is generally a good practice for any large scale software.

Hi @jasongrishkoff, I’ve tried your code with METEOR@3.0-alpha.15 and Meteor 2.13.3 adding your method receiving two different args and then calling from the browser console with Meteor.call and Meteor.callAsync and 100% of the time I got the correct values in the server.

Could you post a repo where we could reproduce your problem?

It would be necessary to know at least which Meteor version you are using and how exactly you are calling it.

One of my tests running Meteor 3.0-alpha.15 (I believe this is what you described above):

Server code:
image

Server log:
image

Client log & code:
image

Another option is that maybe I’m misunderstanding the problem.

As you can see, I could see the query and limit values in both cases (inside both methods).

1 Like