shurcooL/githubv4

Query to get project planning board

Kartikey-star opened this issue · 0 comments

I am trying to follow the https://docs.github.com/en/issues/planning-and-tracking-with-projects/automating-your-project/using-the-api-to-manage-projects?tool=cli [Finding the node ID of a field](https://docs.github.com/en/issues/planning-and-tracking-with-projects/automating-your-project/using-the-api-to-manage-projects?tool=cli#finding-the-node-id-of-a-field).

The query being used here is :

gh api graphql -f query='
query{
node(id: "PROJECT_ID") {
... on ProjectV2 {
fields(first: 20) {
nodes {
... on ProjectV2Field {
id
name
}
... on ProjectV2IterationField {
id
name
configuration {
iterations {
startDate
id
}
}
}
... on ProjectV2SingleSelectField {
id
name
options {
id
name
}
}
}
}
}
}
}'

I am trying to convert this query to a golang struct and use the following:

type (
ProjectV2IterationFieldFragment struct {
id string
name string
configuration struct {
iterations struct {
startDate string
id string
}
}
}
ProjectV2SingleSelectFieldFragment struct {
id string
name string
options struct {
id string
name string
}
}
)

var projquery struct {
	Node struct {
		fields struct {
			Nodes struct {
				Id    string
				Title string
			} `graphql:"... on ProjectV2Field "`
			ProjectV2IterationFieldFragment    `graphql:"... on ProjectV2IterationField "`
			ProjectV2SingleSelectFieldFragment `graphql:"... on ProjectV2SingleSelectField "`
		} `graphql:"... on ProjectV2"`
	} `graphql:"node(id:\"my_project_id\")"`
}

The error which i get here is Fragment on ProjectV2Field can't be spread inside ProjectV2. What wrong am i doing here?

Other than that do you have a recommended resource which can help us getting familiar with converting graphql queries to structs.