Variable declaration disappears inside if (Meteor.isServer) {


#1

I have the following code inside a Meteor.methods

Meteor.methods({
  toggleFavorite({ graphId, postingId }) {
    console.log('both', graphId)

    if (Meteor.isServer) {
      console.log('server', graphId)
      const { graphId, postingId } = checkPosting({ graphId, postingId });
      console.log(graphId)
      const data = { postingId, tokens: graph.auth }

      const hasFavorited = posting.favoritedByGraphIds.some(id => id === graphId);
      const method       = hasFavorited ? Social.unfavorite : Social.favorite;
      method(graph.service, data);
    }
  }
});

graphId gets correctly logged the first time, but on the server, it is logged as undefined, why?


#2

My testing of this works exactly as expected (it logs everyting correctly), but I can’t see all your code around your example, so I suspect the issue lies with making a Meteor.call from the client and expecting a synchronous result. However, having said that, the syntax of your code snippet looks distinctly odd for a Meteor.method. I would expect to see this:

toggleFavorite: function(graphId, postingId) {
   ....
    console.log('both', graphId)
   ...
    if (Meteor.isServer) {
      console.log('server', graphId)
    ...
  }

#3

I am using ES6 syntax, and the method is available on both the server and client


#4

:smile: I didn’t see that coming - I’ll need to pay more attention in future - there’ll be a lot more ES6 soon!

So, how about a minimum reproduction?


#5

I updated the code to be exactly as in my app


#6

Yes - but how and where are you making the Meteor.call?


#7

I’m just making a regular client-side call inside a react component.

...
const params = { graphId, postingId };
Meteor.call('toggleFavorite', params);