Skip to content

feat: facets for issues#483

Draft
rbjornstad wants to merge 3 commits into
mainfrom
issue-facets
Draft

feat: facets for issues#483
rbjornstad wants to merge 3 commits into
mainfrom
issue-facets

Conversation

@rbjornstad

Copy link
Copy Markdown
Contributor

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

IssueConnection gains an optional facets field:

type IssueConnection {
  pageInfo: PageInfo!
  nodes: [Issue!]!
  edges: [IssueEdge!]!
  facets: IssueFacets
}

type IssueFacets {
  environments:  [StringFacetItem!]!
  severities:    [SeverityFacetItem!]!
  resourceTypes: [ResourceTypeFacetItem!]!
  issueTypes:    [IssueTypeFacetItem!]!
}

New supporting types: SeverityFacetItem, ResourceTypeFacetItem, IssueTypeFacetItem.

Implementation

  • SQL – new FacetsForIssues aggregate query groups by (severity, resource_type, env, issue_type) and returns both a total_count (seeds all existing values) and a filtered_count (respects the current filter). This is a single extra DB query executed only when facets is requested.
  • IssueConnection – changed from a type alias to a struct (like ActivityLogEntryConnection) that carries the teamSlug and filter needed for lazy facet computation in the resolver.
  • ComputeFacets – builds the IssueFacets struct by summing filteredCount per dimension; values with filteredCount = 0 are still present (seeded from rows where totalCount > 0).
  • All six Issues resolvers (team + five resource-level) now return *issue.IssueConnection.

Tests

TestBuildFacets covers three cases:

  1. No filter — all counts equal total
  2. With filter — unmatched dimension values seeded with count 0
  3. Empty input — empty slices, no panics

Design choices

  • SQL-aggregate over in-memory — issues live in the DB; loading all rows just for facets would be wasteful for large teams. A single grouped query is more efficient.
  • Single IssueConnection type 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.
  • resourceName is not a facet dimension — it is a free-text search field, not a categorical one.

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 IssueConnection in the GraphQL schema with an optional facets field and introduces new facet item types.
  • Adds FacetsForIssues SQL aggregate query + issue.ComputeFacets/buildFacets to compute per-dimension counts.
  • Refactors the issues connection return type from pagination.Connection[Issue] to *issue.IssueConnection across 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

Comment thread internal/issue/queries/issue.sql
Comment thread internal/graph/issues.resolvers.go
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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants