Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider AutoPaging Optionally Returning Edges #197

Open
jamisonhyatt opened this issue Jun 16, 2019 · 3 comments
Open

Consider AutoPaging Optionally Returning Edges #197

jamisonhyatt opened this issue Jun 16, 2019 · 3 comments
Labels
hacktoberfest Issues for participation in Hacktoberfest Status: Pinned A way to keep old or long lived issues around Status: Up for grabs Issues that are ready to be worked on by anyone

Comments

@jamisonhyatt
Copy link

jamisonhyatt commented Jun 16, 2019

A lot of times there is important information on the Edge (E.g., LanguageEdge has size in bytes, CollaboratorEdge has RepositoryPermisson) and the implementation of autopaging only returns the underlying node. Unless I'm missing something, this means anytime you need information from the edge you are required to fall back to manual paging.

It looks like AllPages could be modified to optionally return an IQueryableList of Edges rather than Nodes. Is that modification something that you would be in favor of? Was this considered and discarded?

@terrajobst
Copy link

terrajobst commented Nov 19, 2019

Totally agree! It seems GraphQL has much better performance (compared to Octokit) but things like this make it pretty hard to migrate 😢

@jeffhandley
Copy link
Contributor

I just hit this scenario too, also on the RepositoryCollaboratorEdge scenario. I was trying find the collaborator edge associated with a pull request's author. Here was my workaround:

var collaboratorQuery = new Query()
    .Repository(Var("repo"), Var("owner"))
    .Collaborators(query: Var("author"))
    .Select(c => new
    {
        c.PageInfo.HasNextPage,
        c.PageInfo.EndCursor,
        Users = c.Edges.Select(e => new
        {
            e.Node.Login,
            e.Permission
        }).ToList()
    })
    .Compile();

while (true)
{
    string? afterCursor = null;

    var collaborators = await connection.Run(collaboratorQuery, new Dictionary<string, object?>
    {
        { "owner", owner },
        { "repo", repo },
        { "author", data.PullRequest.Author },
        { "after_cursor", afterCursor }
    });

    var author = collaborators.Users.SingleOrDefault(user => string.Equals(user.Login, data.PullRequest.Author, StringComparison.InvariantCultureIgnoreCase));

    if (author is not null)
    {
        Console.WriteLine($"Collaborator:");
        Console.WriteLine($"  Login:      {author.Login}");
        Console.WriteLine($"  Permission: {author.Permission}");
        break;
    }

    if (collaborators.HasNextPage)
    {
        afterCursor = collaborators.EndCursor;
    }
    else
    {
        Console.WriteLine($"Author '{data.PullRequest.Author}' is not a collaborator in this repository.");
        break;
    }
}

@nickfloyd nickfloyd added Status: Up for grabs Issues that are ready to be worked on by anyone Status: Pinned A way to keep old or long lived issues around and removed up-for-grabs labels Oct 26, 2022
@jMarkP
Copy link
Contributor

jMarkP commented Jul 11, 2023

I'm also comping up against this. Would be keen to pick this up if that's OK (I see it's 'up for grabs')?

In my head the solution I was going to suggest was to add an optional argument to AllPages to specify whether to paginate over edges or nodes (.AllPages(paginationTarget: PaginationTarget.Edges)?) and then in the QueryBuilder.CreateNodeQuery (when the AllPages expression gets converted into a .Nodes().Cast<>().... expression tree - https://github.com/octokit/octokit.graphql.net/blob/main/Octokit.GraphQL.Core/Core/Builders/QueryBuilder.cs#L1069) to examine that argument and emit an Edges() call instead.

@nickfloyd nickfloyd added the hacktoberfest Issues for participation in Hacktoberfest label Sep 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest Issues for participation in Hacktoberfest Status: Pinned A way to keep old or long lived issues around Status: Up for grabs Issues that are ready to be worked on by anyone
Projects
Status: 🔥 Backlog
Development

No branches or pull requests

5 participants