Help in structuring a query
carlqt opened this issue ยท 3 comments
carlqt commented
I need help/example on how to structure this query
query rootQuery {
search(query: "repo:cli/cli is:open type:pr", type: ISSUE, first: 10) {
nodes {
... on PullRequest {
id
url
title
author {
login
}
}
}
}
}
My structure looks like:
type SearchQuery struct {
Search Search `graphql:"search(query: $q, type: $type, first: $first)"`
}
type Search struct {
Nodes []PullRequestFragment `graphql:"... on PullRequest"`
}
type PullRequestFragment struct {
ID string
Title string
Url string
CreatedAt time.Time
UpdatedAt time.Time
Author struct {
Login string `json:"login"`
}
}
And the errors that I got is Fragment on PullRequest can't be spread inside SearchResultItemConnection
dmitshur commented
You may be missing one struct layer that corresponds to nodes
:
type Search struct {
Nodes []struct {
PullRequestFragment `graphql:"... on PullRequest"`
}
}
carlqt commented
Thanks. Tried it and it works.
carlqt commented
Closing this issue since it's been resolved.