How can I efficiently check membership of specific user in organization?

schema-request

#1

I want to check if a user is a member of a specified organization.

Formerly I’ve used “GET /orgs/:org/members/:username” of REST API in GraphQL API, but GraphQL API’s members field in Organization doesn’t accept :username or “login” as argument. So I needed to list up user’s organizations or organization’s members but it’s inefficient. Is there a better way to do that?


#2

It appears we don’t have a great mechanism to do that right now. The closest thing that we have is viewerIsAMember, which would only work if the token you’re using to make the request was issued by the user who you’d like to check. The query would look something like this:

query($login:String!) {
  organization(login:$login) {
    viewerIsAMember
  }
}

I’ll add this issue as a schema request and add it to our internal tracker to be prioritized. I can imagine a query that would look something like this would accomplish what you’re looking for:

query($orgLogin:String!,$memberLogin:String!) {
  organization(login:$orgLogin) {
    member(login:$memberLogin) {
      # nil or a User type
    }
  }
}

#3

The closest thing that we have is viewerIsAMember, which would only work if the token you’re using to make the request was issued by the user who you’d like to check.

Oh that’s enough for my use case if it can check a public membership of viewer even if a granted scope is public data only. I’ll try it, thank you for your response!