Star gazers not part of a Repository
g14a opened this issue · 2 comments
Hello!
I was exploring the GraphQL explorer and I'm able to list down the total count of stars on a repo with this following query
{
user(login: "g14a") {
repositories(first: 100) {
nodes {
name
stargazers {
totalCount
}
}
}
}
}
But when I use the library to list it down it gives the error Field 'starGazers' doesn't exist on type 'Repository'
I'm declaring the structs as follows:
var ForksStarsQuery struct {
User struct {
Repositories struct {
Nodes []Nodes
} `graphql:"repositories(first: $repoCount)"`
} `graphql:"user(login: $user)"`
}
type Nodes struct {
StarGazers struct {
TotalCount githubv4.Int
}
Name githubv4.String
}
Is there anything simple I'm missing here? I'm able to get values of the ForkCount and WatcherCount but not the StarGazers.
Thank you in advance.
Either rename the StarGazers
field to Stargazers
, or add an explicit name override via field tag:
StarGazers struct {
TotalCount githubv4.Int
} `graphql:"stargazers"`
There's an implicit conversion happening if you don't set an explicit GraphQL field name via the graphql
tag, and the Go field "StarGazers" is converted to "starGazers" (capital 'G'), which doesn't match the field "stargazers" (lower case 'g') in the GraphQL schema. It is case sensitive and fields must match exactly.