Check if repository is accessible by viewer?


I’m having some trouble figuring out how to get this one piece of information that instinctively feels like it should be easy, but I may still be thinking about GraphQL wrong.

Basically, for a given repository (found by owner and name), I’d like to know if the viewer is able to access it. I know I could look up all the viewer’s repositories with “affiliations: [OWNER, COLLABORATOR, ORGANIZATION_MEMBER]”, but then I’d have to collect them all and loop through them to see if the target one is there. Similarly, I could look up all the collaborators or organization members on the repository itself to see if the user is in there. Both of those feel like I’m pulling in a lot of excess data.

I’ve found generic GraphQL documents referring to the “filter” parameter for searches, but it seems like it’s not enabled for the viewer { repositories } query.

I’m probably just going about this all wrong, so would appreciate any corrections.


Hi @sjml :wave:

So that I can better understand your use case, by “able to access” are you referring to whether or not the viewer can read the repository?


Hi @LizzHale! Thanks for checking in.

I’m most directly interested in whether a user has push access to a repository, but reading is indirectly useful as well. Basically I’d like to have some way of finding out if a repository is in the list that would be returned by querying the user’s “repositories” connection. (I know the docs say that’s only for repos the user owns, but with the affiliations parameter you can basically get everything that a user can work with, so far as I can tell.)

Right now this is possible by either fetching the whole list (possibly paging multiple times) and looking for a given repo, OR by fetching the owner/collaborators/members of a repo and looking for the user, but that’s a lot of extra data/processing.

Does that make sense?