feat: facets for issues#483
Draft
rbjornstad wants to merge 3 commits into
Draft
Conversation
Introduces facets for the team issues query, following the SQL-aggregate pattern used by the activity log. Facets provide distribution counts across four dimensions to help narrow down results: - environments - severities - resourceTypes - issueTypes A new FacetsForIssues SQL query computes counts grouped by (severity, resource_type, env, issue_type) using a FILTER WHERE clause so that all possible values are seeded (with count 0 if unmatched) and the filtered counts reflect the current active filter.
Adds IssueFacets type to IssueConnection with four fields: environments, severities, resourceTypes, issueTypes Each field returns a list of facet items with count of matching issues. Counts respect the current filter but are computed across the full (unpaginated) result set. New GraphQL types: IssueFacets, SeverityFacetItem, ResourceTypeFacetItem, IssueTypeFacetItem All Issues resolvers (team + resource-level) now return *issue.IssueConnection so the connection carries the team slug and filter needed for lazy facet computation.
Contributor
There was a problem hiding this comment.
Pull request overview
Adds facet distributions to the Issues GraphQL connection so clients can build filter UIs (counts per environment/severity/resourceType/issueType) without additional round-trips, using a SQL aggregate query and lazy computation when facets is requested.
Changes:
- Extends
IssueConnectionin the GraphQL schema with an optionalfacetsfield and introduces new facet item types. - Adds
FacetsForIssuesSQL aggregate query +issue.ComputeFacets/buildFacetsto compute per-dimension counts. - Refactors the issues connection return type from
pagination.Connection[Issue]to*issue.IssueConnectionacross resolvers and regenerates gqlgen/sqlc outputs.
Reviewed changes
Copilot reviewed 13 out of 22 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/issue/queries/issue.sql | Adds FacetsForIssues aggregate query for grouped total/filtered counts. |
| internal/issue/queries.go | Changes ListIssues to return *IssueConnection carrying teamSlug/filter. |
| internal/issue/model.go | Replaces IssueConnection type alias with a struct; adds facet DTO types. |
| internal/issue/issuesql/querier.go | Adds FacetsForIssues to the sqlc querier interface. |
| internal/issue/issuesql/issue.sql.go | sqlc-generated implementation/types for FacetsForIssues. |
| internal/issue/facets.go | Implements ComputeFacets and buildFacets assembly/sorting logic. |
| internal/issue/facets_test.go | Unit tests for buildFacets behavior (seeded zeros, empty input). |
| internal/graph/schema/issues.graphqls | Adds IssueConnection.facets and new facet GraphQL types with descriptions. |
| internal/graph/issues.resolvers.go | Adds IssueConnection resolver for facets; updates Team issues return type. |
| internal/graph/applications.resolvers.go | Updates Application.issues resolver to return *issue.IssueConnection. |
| internal/graph/jobs.resolvers.go | Updates Job.issues resolver to return *issue.IssueConnection. |
| internal/graph/opensearch.resolvers.go | Updates OpenSearch.issues resolver to return *issue.IssueConnection. |
| internal/graph/sqlinstance.resolvers.go | Updates SQLInstance.issues resolver to return *issue.IssueConnection. |
| internal/graph/valkey.resolvers.go | Updates Valkey.issues resolver to return *issue.IssueConnection. |
| internal/graph/gengql/applications.generated.go | gqlgen updates for Application.issues returning IssueConnection. |
| internal/graph/gengql/jobs.generated.go | gqlgen updates for Job.issues returning IssueConnection. |
| internal/graph/gengql/opensearch.generated.go | gqlgen updates for OpenSearch.issues returning IssueConnection. |
| internal/graph/gengql/sqlinstance.generated.go | gqlgen updates for SQLInstance.issues returning IssueConnection. |
| internal/graph/gengql/teams.generated.go | gqlgen updates for Team.issues returning IssueConnection. |
| internal/graph/gengql/valkey.generated.go | gqlgen updates for Valkey.issues returning IssueConnection. |
| internal/graph/gengql/issues.generated.go | gqlgen adds IssueConnectionResolver.Facets and marshaling for new facet types. |
| internal/graph/gengql/root_.generated.go | gqlgen registers IssueConnection resolver root + complexity entries. |
Files not reviewed (9)
- internal/graph/gengql/applications.generated.go: Generated file
- internal/graph/gengql/issues.generated.go: Generated file
- internal/graph/gengql/jobs.generated.go: Generated file
- internal/graph/gengql/opensearch.generated.go: Generated file
- internal/graph/gengql/sqlinstance.generated.go: Generated file
- internal/graph/gengql/teams.generated.go: Generated file
- internal/graph/gengql/valkey.generated.go: Generated file
- internal/issue/issuesql/issue.sql.go: Generated file
- internal/issue/issuesql/querier.go: Generated file
Address Copilot review feedback:
- FacetsForIssues SQL: split scope params (resource_type, resource_name, env)
into the outer WHERE clause so total_count reflects the actual connection
scope, matching the activitylog FacetsForActivityTypes pattern. User filter
params remain in COUNT(*) FILTER (...).
- IssueConnection now carries a separate IssueScope for resource-level
queries (application, job, opensearch, sqlinstance, valkey). Resource
resolvers build the scope from the resource object instead of embedding
it in IssueFilter.
- Normalize empty environments slice to nil in ListIssues and ComputeFacets
so that an empty []string{} does not produce an always-false ANY predicate.
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 13 out of 22 changed files in this pull request and generated no new comments.
Files not reviewed (9)
- internal/graph/gengql/applications.generated.go: Generated file
- internal/graph/gengql/issues.generated.go: Generated file
- internal/graph/gengql/jobs.generated.go: Generated file
- internal/graph/gengql/opensearch.generated.go: Generated file
- internal/graph/gengql/sqlinstance.generated.go: Generated file
- internal/graph/gengql/teams.generated.go: Generated file
- internal/graph/gengql/valkey.generated.go: Generated file
- internal/issue/issuesql/issue.sql.go: Generated file
- internal/issue/issuesql/querier.go: Generated file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds facets to
IssueConnection, following the SQL-aggregate pattern used by the activity log. Facets provide distribution counts across the current team's issues to help clients build filter UIs without additional round-trips.Changes
GraphQL schema
IssueConnectiongains an optionalfacetsfield:New supporting types:
SeverityFacetItem,ResourceTypeFacetItem,IssueTypeFacetItem.Implementation
FacetsForIssuesaggregate query groups by(severity, resource_type, env, issue_type)and returns both atotal_count(seeds all existing values) and afiltered_count(respects the current filter). This is a single extra DB query executed only whenfacetsis requested.IssueConnection– changed from a type alias to a struct (likeActivityLogEntryConnection) that carries theteamSlugandfilterneeded for lazy facet computation in the resolver.ComputeFacets– builds theIssueFacetsstruct by summingfilteredCountper dimension; values withfilteredCount = 0are still present (seeded from rows wheretotalCount > 0).Issuesresolvers (team + five resource-level) now return*issue.IssueConnection.Tests
TestBuildFacetscovers three cases:0Design choices
IssueConnectiontype for both team and resource queries — consistent with the existing schema shape. For resource-scoped queries (e.g.application.issues), env/resourceType facets will have a single item since they are fixed by the resource scope.resourceNameis not a facet dimension — it is a free-text search field, not a categorical one.