__loggedInUserId in Custom Function

What’s the alternative for __loggedInUserId in a Custom Function resolver?

Hey @chanand - when you ask for an “alternative”, what are you trying to accomplish?

One thing that may help is the ability to specify is_self for any relation to a User record. For example,

await ctx.api.gqlRequest(`
query {
  usersList(filter: {
    friends: {
	some: {
	  is_self: true
      }
    }
  }) {
    count
  }
}
`) 

In this example, a list of users who the REQUESTING user is friends with would be returned.

Is this helpful?

Is there a way to get the actual user ID from the ctx?
Or is the only way getting it would be by executing a gqlRequest?

There isn’t a current user id key that you have access to on cxt. If you need the actual uuid of the user, you can either send it to the custom function as an argument (from the client-app) OR make an api call to retrieve the current user ID.

export default async (event: any, ctx: any) : Promise<LocalizeResult> => {
   // I need the user ID, asap!
   const { user: { id }  } = await ctx.api.gqlRequest('query { user { id } }');
   // I've got my id!
   sendEmail({ msg: `You're ID is: ${id}` });
   
   return {
     status: 200,
     response: "I'm so happy!"
   }
};

Also, could you let me know what you’re trying to accomplish? Maybe we should add the id :slight_smile:

@sebastian.scholl I’m hoping for a little more clarification on the use of “is_self”.

I’m trying to do a userUpdate mutation within a custom Resolver using ctx.api.gqlRequest. Is there some way I can use “is_self” to update the requesting user, or do I first need to do a query to get the id of the requesting user, and then use that to do a userUpdate mutation?

I’m hoping I can skip doing the separate query to get the id.

@sebastian.scholl Curious if you have any feedback on how to use is_self in my scenario (outlined above).