Skip to content

feat: import pg-aggregates plugin with Constructive adaptations#1067

Merged
pyramation merged 188 commits intomainfrom
feat/pg-aggregates-plugin
May 9, 2026
Merged

feat: import pg-aggregates plugin with Constructive adaptations#1067
pyramation merged 188 commits intomainfrom
feat/pg-aggregates-plugin

Conversation

@pyramation
Copy link
Copy Markdown
Contributor

@pyramation pyramation commented May 7, 2026

Summary

Import pg-aggregates v5 into the Constructive monorepo with full upstream git history preserved (181 commits), adapted to Constructive conventions (pnpm/makage, single quotes, our connection-filter fork).

Disabled by defaultPgAggregatesPreset is NOT included in ConstructivePreset. Users opt in by adding it to their own preset's extends array. This supports future per-database feature toggling (e.g. pro tier).

Commit structure:

  1. Merge commitgit subtree add (no --squash) preserving all upstream history
  2. Adaptation commit — removes upstream tooling (yarn, eslint, prettier, jest), adapts source to Constructive conventions
  3. Test commit — 35 tests written from scratch using our graphile-test framework
  4. Merge from main — brings in latest changes
  5. Disable by default — removes PgAggregatesPreset from ConstructivePreset, updates snapshots

Key adaptation: FilterRelationalAggregatesPlugin rewritten to use $where._manyRelation (our fork) instead of upstream's $where.extensions.pgFilterRelation.

Review & Testing Checklist for Human

  • Verify FilterRelationalAggregatesPlugin adaptation — this is the riskiest change. Check src/FilterRelationalAggregatesPlugin.ts lines 40-53 against your connection-filter fork's ConnectionFilterBackwardRelationsPlugin.ts to confirm the _manyRelation shape matches.
  • Test relational aggregate filtering on a real schema — run a query like allTeams(where: { playersByTeamId: { aggregates: { sum: { goals: { greaterThan: "20" } } } } }) against a production-like schema after opting in.
  • Verify git history preserved — run git log --follow graphile/graphile-pg-aggregates/src/index.ts and confirm all 181 upstream commits are visible.
  • Schema snapshot diff — verify the snapshot deletions only removed aggregate-related types (since the preset is now disabled by default).

Notes

  • To enable aggregates for a database, add PgAggregatesPreset to the preset extends: import { PgAggregatesPreset } from 'graphile-pg-aggregates'
  • 35 tests cover: basic aggregates, groupBy, having, relational aggregates, schema introspection, edge cases (NULL handling, pagination), where pre-filter, multi-key groupBy, and behavior opt-out
  • sum(int) returns bigint in PostgreSQL, which GraphQL represents as a string — filter values must be strings (e.g., greaterThan: "20")
  • Per-table opt-out is supported via @behavior -aggregates smart tag

Link to Devin session: https://app.devin.ai/sessions/a233256611174c5fa1e38e35807cd661
Requested by: @pyramation

benjie and others added 30 commits March 10, 2019 10:16
RFC: Add support for aggregating over computed columns
Bumps [ini](https://github.com/isaacs/ini) from 1.3.5 to 1.3.7.
- [Release notes](https://github.com/isaacs/ini/releases)
- [Commits](npm/ini@v1.3.5...v1.3.7)

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [ws](https://github.com/websockets/ws) from 5.2.2 to 5.2.3.
- [Release notes](https://github.com/websockets/ws/releases)
- [Commits](websockets/ws@5.2.2...5.2.3)

---
updated-dependencies:
- dependency-name: ws
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [path-parse](https://github.com/jbgutierrez/path-parse) from 1.0.6 to 1.0.7.
- [Release notes](https://github.com/jbgutierrez/path-parse/releases)
- [Commits](https://github.com/jbgutierrez/path-parse/commits/v1.0.7)

---
updated-dependencies:
- dependency-name: path-parse
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [minimist](https://github.com/substack/minimist) from 1.2.5 to 1.2.6.
- [Release notes](https://github.com/substack/minimist/releases)
- [Commits](https://github.com/substack/minimist/compare/1.2.5...1.2.6)

---
updated-dependencies:
- dependency-name: minimist
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [ansi-regex](https://github.com/chalk/ansi-regex) from 4.1.0 to 4.1.1.
- [Release notes](https://github.com/chalk/ansi-regex/releases)
- [Commits](chalk/ansi-regex@v4.1.0...v4.1.1)

---
updated-dependencies:
- dependency-name: ansi-regex
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
@devin-ai-integration
Copy link
Copy Markdown
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

pyramation added 2 commits May 7, 2026 22:42
…1586b8c3d423ac2d6424bde'

git-subtree-dir: graphile/graphile-pg-aggregates
git-subtree-mainline: a5ae7a6
git-subtree-split: 3975026
Adapt the imported @graphile/pg-aggregates v5 sources for Constructive's
codebase conventions and custom connection-filter fork.

Changes from upstream:
- Build system: yarn/tsc → pnpm/makage with CJS+ESM outputs
- Remove upstream config files (.yarn, .yarnrc.yml, .eslintignore,
  .prettierrc.js, .jest-babel-transform.js, jest.config.js, etc.)
- Remove upstream test files (depend on yarn/jest infrastructure)
- Imports: Replace subpath exports (postgraphile/grafast,
  graphile-build-pg/@dataplan/pg) with direct package imports
  for moduleResolution: node compatibility
- FilterRelationalAggregatesPlugin: Read from $where._manyRelation
  (our ConnectionFilterBackwardRelationsPlugin) instead of upstream's
  $where.extensions.pgFilterRelation
- Plugin ordering: before ConnectionFilterArgPlugin (our fork's name)
- Field naming: Aggregate sub-filter field renamed from 'filter' to 'where'
- Version: Inline const version instead of require('../package.json')
- Remove .js extensions from local imports
- Add PgConditionExtensions augmentation for pgFilterAttribute
- Add graphile-connection-filter and grafast as peer dependencies
- Wire PgAggregatesPreset into ConstructivePreset in graphile-settings
- Update schema snapshots in graphql/test and graphql/server-test

Provides: aggregates field on connections (sum, avg, min, max, stddev,
variance, distinctCount), groupedAggregates with groupBy + having,
orderBy relational aggregates, filter by relational aggregates.
Per-table opt-out via @behavior -aggregates smart tag.
@devin-ai-integration devin-ai-integration Bot force-pushed the feat/pg-aggregates-plugin branch from f0bfbff to c0fd7f7 Compare May 7, 2026 22:44
pyramation and others added 5 commits May 7, 2026 23:03
Tests cover:
- Basic aggregates (sum, average, min, max, distinctCount, stddev, variance)
- Grouped aggregates (groupBy position, team, season)
- Having clause (filter groups by sum, average thresholds)
- Relational aggregates (orderBy child sum/average, filter parents by child aggregates)
- Schema introspection (connection fields, aggregate types, GroupBy enum, Having input, orderBy enum)
Add tests following patterns from connection-filter and other plugins:
- Edge cases: NULL handling, pagination+aggregates, multiple agg functions,
  empty having results, orderBy aggregate with LIMIT
- Aggregates with where pre-filter: filtered rows, filtered groups, season
- Multi-key groupBy: two-key grouping, multi-key having
- Behavior opt-out: verify -resource:aggregates hides fields per-table
- Schema introspection: MatchAggregates, HavingInput stddev/variance fields
Remove PgAggregatesPreset from the default extends array so aggregates
are opt-in. Users can enable by adding PgAggregatesPreset to their own
preset extends (import from graphile-pg-aggregates).

Update schema snapshots to remove aggregate types from default schema.
@pyramation pyramation merged commit 72de811 into main May 9, 2026
54 checks passed
@pyramation pyramation deleted the feat/pg-aggregates-plugin branch May 9, 2026 00:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants