Variable declaration disappears inside if (Meteor.isServer) {

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?

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)
    ...
  }

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

: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?

I updated the code to be exactly as in my app

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

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

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