GitHub GraphQL API list all custom fields in ProjectV2

15 views Asked by At

I'm using ProjectsV2 in Github, and since we don't have some pretty basic automations, I'm trying to write my own.

I need to get a list of all my custom fields in the project, so I can then use their ids to modify those fields using my script.

I already managed to get a list of projects, labels, issues, prs, but the custom fields are giving me grief.

I'm trying this and all sorts of variants (which worked for almost every other list I needed):

query { 
  repository(owner:"OWNER", name:"REPO") { 
    projectV2(number: 2) {
        ... on ProjectV2 {
          fields(last: 20) {
            nodes {
              ProjectV2Field
                nodes {
                id
                } 
            }
          }
        }
    }
  }}

What I get is:

{
"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)"
    }
]

}

I am new to graphql and I am trying to read Github's docs on it but I just can't figure this structure or what the error message means.

Any tips that can point me on the right direction are very much appreciated. Thanks!

EDIT:

I made some progress. The following query gives me a list of (most of the) fields, but no single select ones:

query {
      repository(owner:"OWNER", name:"REPO") {
        projectV2(number: 2) {
            ... on ProjectV2 {
                fields(first: 100) {
                    nodes {
                        ... on ProjectV2Field {
                            id
                            name
                            dataType
                        }
                    }
                }
            }
        }
      }
}

Response (with ids redacted):

{
"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"
                    },
                    {}
                ]
            }
        }
    }
}

}

Almost there!

0

There are 0 answers