Setting this.userId inside Meteor methods called from Apollo Resolvers

Has anyone here used Meteor methods inside of their Apollo GraphQL resolvers? I have a situation where I have a meteor server also running an Apollo server (per the Apollo docs), and I can access the logged in user via context.userId, or by calling meteor methods on the client, but when I try to call a meteor method inside the Apollo resolver, this.userId returns as null.

Directly updating the Mongo.Collection from my resolvers appear to work fine, but I have some denormalizing hooks attached to one of my collections that call other Meteor methods, and I would prefer to keep those functioning properly, but they require this.userId. This seems odd that I am seeing partial functionality of Meteor’s server side environment, but don’t have access to all of it. Any help would be greatly appreciated. Thanks

1 Like

Add userId from context.userId to method call. I don’t have any ideas more (-: It’s server-to-server call, must be secure enough…

Check these out:

which offer two different ways to solve the same problem.

Using DDP and DDPCommon like the suggestion in your second link worked, though I haven’t tested it completely yet. I had a hard time following your discussion regarding context, but it made me think using these methods might lead to the possibility of userId’s being crossed/assigned to the wrong user. Is that a possibility?

1 Like

I actually tried that suggestion right before posting here, and Meteor throws an error saying you can’t set userId from a server call. I assume it’s a security feature.

Why do you need to call a method? I suggest to abstract your methods to services and keep them act as proxies.
I’ve documented the concepts here: http://www.meteor-tuts.com/chapters/3/methods.html