octokit / octokit.graphql.net

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

Dynamically build a query based on collection of values #200

Open hisuwh opened 5 years ago

hisuwh commented 5 years ago

I have a list of pull request numbers, and I want to build a Graph QL query so that I can get information back for all of them.

So the output being something like this:

query {
  repository(owner:"Owner", name:"Repo") {
    pr1: pullRequest(number: 36592) {
      title
    }

    pr2: pullRequest(number: 36593) {
      title
    }

    ....

    prN: pullRequest(number: 99999) {
      title
    }
  }
}

Is this possible with the octokit library?


Edit: For example I can do it this way with a raw GraphQL string:

var prQueries = prNumberList.Select((number, index) => $@"
    pr{index}: pullRequest(number: {number}) {{
        number,
        body
    }}
");

var query = $@"
    query {{
        repository(owner:""{this.repoSettings.Owner}"", name:""{this.repoSettings.Name}"") {{
            {string.Join("", prQueries)}
        }}
    }}
";
github-actions[bot] commented 1 year ago

👋 Hey Friends, this issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Please add the Status: Pinned label if you feel that this issue needs to remain open/active. Thank you for your contributions and help in keeping things tidy!

rseanhall commented 1 year ago

I am also having to generate a raw GraphQL string for this kind of query.