我在 Github 中使用 ProjectsV2,由于我们没有一些非常基本的自动化,所以我正在尝试编写自己的自动化。
我需要获取项目中所有自定义字段的列表,以便我可以使用它们的 id 使用我的脚本修改这些字段。
我已经设法获得了项目、标签、问题、prs 的列表,但自定义字段让我感到悲伤。
我正在尝试这个和各种变体(几乎适用于我需要的所有其他列表):
query {
repository(owner:"OWNER", name:"REPO") {
projectV2(number: 2) {
... on ProjectV2 {
fields(last: 20) {
nodes {
ProjectV2Field
nodes {
id
}
}
}
}
}
}}
我得到的是:
{
"errors": [
{
"path": [
"query",
"repository",
"projectV2",
"... on ProjectV2",
"fields",
"nodes",
"ProjectV2Field"
],
"extensions": {
"code": "selectionMismatch",
"nodeName": "ProjectV2FieldConfiguration"
},
"locations": [
{
"line": 6,
"column": 17
}
],
"message": "Selections can't be made directly on unions (see selections on ProjectV2FieldConfiguration)"
},
{
"path": [
"query",
"repository",
"projectV2",
"... on ProjectV2",
"fields",
"nodes",
"nodes"
],
"extensions": {
"code": "selectionMismatch",
"nodeName": "ProjectV2FieldConfiguration"
},
"locations": [
{
"line": 6,
"column": 17
}
],
"message": "Selections can't be made directly on unions (see selections on ProjectV2FieldConfiguration)"
}
]
}
我是 graphql 的新手,我正在尝试阅读 Github 上的文档,但我只是无法理解这个结构或错误消息的含义。
非常感谢任何可以为我指明正确方向的提示。谢谢!
编辑:
我取得了一些进步。以下查询为我提供了(大多数)字段的列表,但没有单个选择的字段:
query {
repository(owner:"OWNER", name:"REPO") {
projectV2(number: 2) {
... on ProjectV2 {
fields(first: 100) {
nodes {
... on ProjectV2Field {
id
name
dataType
}
}
}
}
}
}
}
响应(ID 已编辑):
{
"data": {
"repository": {
"projectV2": {
"fields": {
"nodes": [
{
"id": "ID",
"name": "Title",
"dataType": "TITLE"
},
{
"id": "ID",
"name": "Assignees",
"dataType": "ASSIGNEES"
},
{},
{
"id": "ID",
"name": "Labels",
"dataType": "LABELS"
},
{
"id": "ID",
"name": "Linked pull requests",
"dataType": "LINKED_PULL_REQUESTS"
},
{
"id": "ID",
"name": "Reviewers",
"dataType": "REVIEWERS"
},
{
"id": "ID",
"name": "Repository",
"dataType": "REPOSITORY"
},
{
"id": "ID",
"name": "Milestone",
"dataType": "MILESTONE"
},
{
"id": "ID",
"name": "Due",
"dataType": "DATE"
},
{
"id": "ID",
"name": "Days",
"dataType": "NUMBER"
},
{
"id": "ID",
"name": "Target",
"dataType": "TEXT"
},
{
"id": "ID",
"name": "Start Date",
"dataType": "DATE"
},
{
"id": "ID",
"name": "End Date",
"dataType": "DATE"
},
{},
{
"id": "ID",
"name": "PR Size",
"dataType": "NUMBER"
},
{}
]
}
}
}
}
}
快到了!
您可以通过脚本修改字段吗?我有同样的问题,你的代码帮助了我。我正在尝试通过突变进行修改,但似乎不起作用。