最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

.net - How to retrieve Project custom properties or field values in Octokit.GraphQL.Net - Stack Overflow

programmeradmin2浏览0评论

We have a github project with custom field such as Sprint and story points. Below is the sample query that I am trying using Octokit.GraphQL.Net

var query = new Query()
.Repository("my-repo", "my-")
.Issue(1234)
.Select(issue => new 
{
    issue.Number,
    issue.Title,
    issue.Url,
    ProjectItems = issue.ProjectItems(10, null, null, null, null).Nodes
        .Select(p => new
        {
            p.Id,
            p.Type,
            Sprint = p.FieldValueByName("Sprint") // <<------  **** Failing here *****
        }).ToList()

}).Compile();
var result = await connection.Run(query);

Error reported is

Newtonsoft.Json.JsonSerializationException: 'Unable to find a constructor to use for type Octokit.GraphQL.Model.ProjectV2ItemFieldValue. A class should either have a default constructor, one constructor with arguments or a constructor marked with the JsonConstructor attribute. Path 'data.repository.issue.projectItems.nodes[0].sprint', line 1, position 255.'

Trying to get something like this /blog/graphql-intro/#aliases which has custom project fields.

Query I ran through github client from powershell

gh api graphql -F owner='my-' -F name='my-repo' -f query='
     query($name: String!, $owner: String!) {
       repository(owner: $owner, name: $name) {
            issue(number: 1234) {
                    number
                    title
                    url
                    projectItems(first: 50) {
                        nodes {
                            id
                            type
                            project {
                                title
                            }
                            sprint: fieldValueByName(name: "Sprint") {
                                ... on ProjectV2ItemFieldIterationValue {
                                    title
                                 }
                            }
                            storypoints: fieldValueByName(name: "Story Points") {
                                ... on ProjectV2ItemFieldNumberValue
                                {
                                    number
                                }
                            }
                    }
                }
            }
    }
}'

Output I get is as below and I am looking something similar from Ocktokit.graphql

{
  "data": {
    "repository": {
      "issue": {
        "number": 1234,
        "title": "Dummy Issue",
        "url": ";,
        "projectItems": {
          "nodes": [
            {
              "id": "PVTI_lADOCiN9Zs4AkRCMzgVWLXE",
              "type": "ISSUE",
              "project": {
                "title": "my-project"
              },
              "sprint": {
                "title": "Sprint 6"
              },
              "storypoints": {
                "number": 3.0
              }
            }
          ]
        }
      }
    }
  }
}
发布评论

评论列表(0)

  1. 暂无评论