octokit / octokit.graphql.net

A GitHub GraphQL client library for .NET
MIT License
145 stars 50 forks source link

How to get current authorized organizations. #134

Open MartinDawson opened 6 years ago

MartinDawson commented 6 years ago

I am trying this:

var expression = query.Viewer.Organizations(2).Compile().

I authorise one of my organisations to be allowed but not the other. In this case the above code throws the exception:

"message":"GraphQL.ExecutionError: Error trying to resolve setupCallback. ---> Octokit.GraphQL.Core.Deserializers.ResponseDeserializerException: Although you appear to have the correct authorization credentials,\nthe jplayer organization has enabled OAuth App access restrictions, meaning that data\naccess to third-parties is limited.

I don't want to give jplayer organisation access but I want to give my other organisation access.

How do I get the current authorised organisations that the user has authorised instead of all of them?

grokys commented 6 years ago

@gjtorikian @d12 @nickvanw this appears to be a server-side GraphQL question more than client side, so I'm going to pass it on to you ;)

gjtorikian commented 6 years ago

I'm ashamed to say that I don't think such a filtering exists. I'll open an issue internally at GitHub for this. Sorry about that!

I do believe this issue ought to be closed in the meantime, since it's not specific to this project. We will try to reply to this issue once a fix goes in.

gjtorikian commented 6 years ago

Actually, on second glance -- I ran a similar query:

{
  viewer {
    organizations(first: 10) {
      nodes {
        repositories(first: 10) {
          nodes {
            name
          }
        }
      }
    }
  }
}

I thought that the entire query would throw an exception, but that appears not to be the case. We return data for organizations which can return data, and we pass a message to errors if an organization has the OAuth App restrictions enabled.

If the entire query is failing, then that indicates some behavior that needs to be fixed in this project, I think.

grokys commented 6 years ago

Ah thanks @gjtorikian - yes that does actually sound like a problem with octokit.graphql then!

I think we treat all errors as meaning the query failed. I guess we need a way to allow "partial" errors on a query, though I'm not sure how this should be exposed to the client?

MartinDawson commented 6 years ago

Yes, this is definitely an issue with this project.

grokys commented 6 years ago

Yes, we need a way to get around this issue. I'm not sure what a good API to represent a "partial success" would be however.

Maybe something like this?

Task<T> Run<T>(
    this IConnection connection,
    IQueryableValue<T> expression,
    out Exception errors,
    CancellationToken cancellationToken = default)

Where errors will be filled with an AggregateException if >1 errors occur?

or perhaps:

Task<(T, Exception)> RunAllowingPartialExceptions<T>(
    this IConnection connection,
    IQueryableValue<T> expression,
    CancellationToken cancellationToken = default)

But we'd need a better name than RunAllowingPartialExceptions ;)

Thoughts on this would be appreciated.

StanleyGoldman commented 6 years ago

@StanleyGoldman pokes @MartinDawson: Psst, I think he was asking you. 😅

MartinDawson commented 6 years ago

@StanleyGoldman @grokys I gave a thumbs up that either looked good.

I am not a C# expert so I can't really say more.

StanleyGoldman commented 6 years ago

Ah, no worries then. It's just the two of us making decisions so sometimes it helps to hear from someone else what looks or feels better.

ENikS commented 4 years ago

This answer may be of use

9at8 commented 1 year ago

HI @ENikS, the link no longer works can you please repost