shurcooL/githubv4

Help in structuring a query

carlqt opened this issue ยท 3 comments

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

You may be missing one struct layer that corresponds to nodes:

type Search struct {
	Nodes []struct {
		PullRequestFragment `graphql:"... on PullRequest"`
	}
}

Thanks. Tried it and it works.

Closing this issue since it's been resolved.