githubv4
githubv4 copied to clipboard
How to check if the result is null?
query:
{
repositoryOwner(login: "_dnxv__") {
... on ProfileOwner {
pinnedItemsRemaining
itemShowcase {
hasPinnedItems
}
}
}
}
result:
{
"data": {
"repositoryOwner": null
}
}
but the variable query in golang is a struct, so how to check if it's null? any workaround or tricks?
You can use a pointer to a struct, and check if the pointer value is nil. For example:
var q struct {
RepositoryOwner *struct {
ProfileOwner struct {
PinnedItemsRemaining int
// ...
} `graphql:"... on ProfileOwner"`
} `graphql:"repositoryOwner(login: \"_dnxv__\")"`
}
// call client.Query(...)
if q.RepositoryOwner == nil {
// handle this case
}
// ...