Skip to content

Fix GraphQL aggregation features disabled when runtime.graphql config section is absent - #3450

Merged
Aniruddh Munde (Aniruddh25) merged 8 commits into
mainfrom
copilot/fix-graphql-aggregation-features
Apr 30, 2026
Merged

Fix GraphQL aggregation features disabled when runtime.graphql config section is absent#3450
Aniruddh Munde (Aniruddh25) merged 8 commits into
mainfrom
copilot/fix-graphql-aggregation-features

Conversation

Copilot AI commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

Why make this change?

GraphQL aggregation features (groupBy, sum, avg, min, max, count) were silently disabled for users whose config lacked an explicit runtime.graphql section, even though EnableAggregation defaults to true.

What is this change?

Bug fix: RuntimeConfig.EnableAggregation logic inversion

The property used && logic, returning false when Runtime or Runtime.GraphQL was null. This is inconsistent with every analogous property (e.g. IsGraphQLEnabled) which use || logic to treat absence as "use default (enabled)":

// Before (broken): returns false when runtime.graphql section is absent
public bool EnableAggregation =>
    Runtime is not null &&
    Runtime.GraphQL is not null &&
    Runtime.GraphQL.EnableAggregation;

// After (fixed): returns true when section is absent, consistent with IsGraphQLEnabled
public bool EnableAggregation =>
    Runtime is null ||
    Runtime.GraphQL is null ||
    Runtime.GraphQL.EnableAggregation;

Additional fixes:

  • GraphQLSchemaCreator.OnConfigChanged now updates _isAggregationEnabled on hot-reload (was omitted, causing stale state)
  • schemas/dab.draft.schema.json: added enable-aggregation to runtime.graphql properties — it was missing despite additionalProperties: false, meaning any config explicitly setting the flag would fail schema validation

Test refactoring (per code review feedback):

  • Extracted a LoadConfig private helper in RuntimeConfigLoaderTests to eliminate repeated mock-filesystem setup across all EnableAggregation tests
  • Merged EnableAggregation_WhenExplicitlyDisabled_ReturnsFalse and EnableAggregation_WhenExplicitlyEnabled_ReturnsTrue into a single parameterized [DataTestMethod] (EnableAggregation_WhenExplicitlySet_ReturnsConfiguredValue) using [DataRow(true)] and [DataRow(false)]
  • Merged Build_WithMssqlAndAggregationEnabled_AddsGroupByToConnectionType and Build_WithPostgreSqlAndAggregationEnabled_DoesNotAddGroupByToConnectionType into a single parameterized [DataTestMethod] (Build_WithAggregationEnabled_GroupByPresenceMatchesDatabaseSupport) covering MSSQL, DWSQL (groupBy present), PostgreSQL, and MySQL (groupBy absent)

How was this tested?

  • Integration Tests
  • Unit Tests
    • RuntimeConfigLoaderTests: EnableAggregation defaults to true when runtime or runtime.graphql sections are absent; a single parameterized test (EnableAggregation_WhenExplicitlySet_ReturnsConfiguredValue) covers both true and false explicit values using [DataRow]. A shared LoadConfig helper eliminates repeated mock-filesystem setup.
    • QueryBuilderTests: a single parameterized test (Build_WithAggregationEnabled_GroupByPresenceMatchesDatabaseSupport) covers MSSQL and DWSQL (groupBy present) and PostgreSQL and MySQL (groupBy absent), plus a test confirming groupBy is omitted when aggregation is disabled.

Sample Request(s)

With a config that has no explicit runtime.graphql section, the following now works as expected for MSSQL/DWSQL entities:

{
  books {
    groupBy(fields: [price]) {
      fields { price }
      aggregations {
        count
        sum(field: price)
        avg(field: price)
        max(field: price)
        min(field: price)
      }
    }
  }
}

Copilot AI and others added 2 commits April 15, 2026 22:16
…n is absent

- Fix RuntimeConfig.EnableAggregation to use consistent OR logic (returns true
  when Runtime is null or Runtime.GraphQL is null, matching IsGraphQLEnabled pattern)
- Fix GraphQLSchemaCreator.OnConfigChanged to update _isAggregationEnabled on hot-reload
- Add enable-aggregation to dab.draft.schema.json (runtime.graphql section)
- Add unit tests: EnableAggregation defaults to true when graphql/runtime section absent,
  can be explicitly disabled; QueryBuilder adds groupBy to MSSQL connection type but not PostgreSQL

Agent-Logs-Url: https://github.com/Azure/data-api-builder/sessions/b4c70fb5-8795-4c8a-a904-d54344395c93

Co-authored-by: Aniruddh25 <3513779+Aniruddh25@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix missing GraphQL aggregation features in DAB 2.0.0-rc schema Fix GraphQL aggregation features disabled when runtime.graphql config section is absent Apr 15, 2026

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

Fixes a regression where GraphQL aggregation features were incorrectly disabled when the runtime.graphql config section was omitted, despite aggregation defaulting to enabled.

Changes:

  • Corrected RuntimeConfig.EnableAggregation defaulting behavior to treat missing runtime / runtime.graphql as “enabled”.
  • Updated GraphQLSchemaCreator hot-reload handling to refresh the aggregation-enabled flag.
  • Extended dab.draft.schema.json to allow runtime.graphql.enable-aggregation, and added unit tests covering defaults and schema surface area (groupBy presence).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/Service.Tests/GraphQLBuilder/QueryBuilderTests.cs Adds unit tests verifying groupBy is present/absent based on aggregation enablement and supported DB types.
src/Service.Tests/Configuration/RuntimeConfigLoaderTests.cs Adds unit tests validating EnableAggregation defaults and honoring explicit enable-aggregation.
src/Core/Services/GraphQLSchemaCreator.cs Updates hot-reload path to refresh _isAggregationEnabled from latest runtime config.
src/Config/ObjectModel/RuntimeConfig.cs Fixes EnableAggregation logic to default to true when config sections are absent; updates doc comment accordingly.
schemas/dab.draft.schema.json Adds runtime.graphql.enable-aggregation to schema properties so configs can validate when explicitly set.

Comment thread src/Service.Tests/Configuration/RuntimeConfigLoaderTests.cs Outdated
Comment thread src/Service.Tests/GraphQLBuilder/QueryBuilderTests.cs Outdated

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.

The PR needs refactoring to reduce unnecessary repetition. Apart from this looks good.

…rized tests

- Add LoadConfig helper in RuntimeConfigLoaderTests to eliminate repeated mock
  filesystem setup
- Merge EnableAggregation_WhenExplicitlyDisabled/Enabled into a single
  DataTestMethod with DataRow(true) and DataRow(false)
- Merge Build_WithMssql/PostgreSqlAndAggregationEnabled into a single
  DataTestMethod covering MSSQL, DWSQL, PostgreSQL, and MySQL

Agent-Logs-Url: https://github.com/Azure/data-api-builder/sessions/7c3dcc98-f816-4bc1-b5cd-2228bf05e5cb

Co-authored-by: Aniruddh25 <3513779+Aniruddh25@users.noreply.github.com>

@RubenCerna2079 RubenCerna2079 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.

LGTM

@Aniruddh25
Aniruddh Munde (Aniruddh25) merged commit 9391685 into main Apr 30, 2026
13 checks passed
@Aniruddh25
Aniruddh Munde (Aniruddh25) deleted the copilot/fix-graphql-aggregation-features branch April 30, 2026 22:42
naxing123 pushed a commit that referenced this pull request Aug 12, 2026
… section is absent (#3450)

## Why make this change?

GraphQL aggregation features (`groupBy`, `sum`, `avg`, `min`, `max`,
`count`) were silently disabled for users whose config lacked an
explicit `runtime.graphql` section, even though `EnableAggregation`
defaults to `true`.

## What is this change?

**Bug fix: `RuntimeConfig.EnableAggregation` logic inversion**

The property used `&&` logic, returning `false` when `Runtime` or
`Runtime.GraphQL` was `null`. This is inconsistent with every analogous
property (e.g. `IsGraphQLEnabled`) which use `||` logic to treat absence
as "use default (enabled)":

```csharp
// Before (broken): returns false when runtime.graphql section is absent
public bool EnableAggregation =>
    Runtime is not null &&
    Runtime.GraphQL is not null &&
    Runtime.GraphQL.EnableAggregation;

// After (fixed): returns true when section is absent, consistent with IsGraphQLEnabled
public bool EnableAggregation =>
    Runtime is null ||
    Runtime.GraphQL is null ||
    Runtime.GraphQL.EnableAggregation;
```

**Additional fixes:**
- `GraphQLSchemaCreator.OnConfigChanged` now updates
`_isAggregationEnabled` on hot-reload (was omitted, causing stale state)
- `schemas/dab.draft.schema.json`: added `enable-aggregation` to
`runtime.graphql` properties — it was missing despite
`additionalProperties: false`, meaning any config explicitly setting the
flag would fail schema validation

**Test refactoring (per code review feedback):**
- Extracted a `LoadConfig` private helper in `RuntimeConfigLoaderTests`
to eliminate repeated mock-filesystem setup across all
`EnableAggregation` tests
- Merged `EnableAggregation_WhenExplicitlyDisabled_ReturnsFalse` and
`EnableAggregation_WhenExplicitlyEnabled_ReturnsTrue` into a single
parameterized `[DataTestMethod]`
(`EnableAggregation_WhenExplicitlySet_ReturnsConfiguredValue`) using
`[DataRow(true)]` and `[DataRow(false)]`
- Merged
`Build_WithMssqlAndAggregationEnabled_AddsGroupByToConnectionType` and
`Build_WithPostgreSqlAndAggregationEnabled_DoesNotAddGroupByToConnectionType`
into a single parameterized `[DataTestMethod]`
(`Build_WithAggregationEnabled_GroupByPresenceMatchesDatabaseSupport`)
covering MSSQL, DWSQL (groupBy present), PostgreSQL, and MySQL (groupBy
absent)

## How was this tested?

- [ ] Integration Tests
- [x] Unit Tests
- `RuntimeConfigLoaderTests`: `EnableAggregation` defaults to `true`
when `runtime` or `runtime.graphql` sections are absent; a single
parameterized test
(`EnableAggregation_WhenExplicitlySet_ReturnsConfiguredValue`) covers
both `true` and `false` explicit values using `[DataRow]`. A shared
`LoadConfig` helper eliminates repeated mock-filesystem setup.
- `QueryBuilderTests`: a single parameterized test
(`Build_WithAggregationEnabled_GroupByPresenceMatchesDatabaseSupport`)
covers MSSQL and DWSQL (groupBy present) and PostgreSQL and MySQL
(groupBy absent), plus a test confirming groupBy is omitted when
aggregation is disabled.

## Sample Request(s)

With a config that has no explicit `runtime.graphql` section, the
following now works as expected for MSSQL/DWSQL entities:

```graphql
{
  books {
    groupBy(fields: [price]) {
      fields { price }
      aggregations {
        count
        sum(field: price)
        avg(field: price)
        max(field: price)
        min(field: price)
      }
    }
  }
}
```

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Aniruddh25 <3513779+Aniruddh25@users.noreply.github.com>
Co-authored-by: Aniruddh Munde <anmunde@microsoft.com>
Co-authored-by: Souvik Ghosh <souvikofficial04@gmail.com>
(cherry picked from commit 9391685)
naxing123 added a commit that referenced this pull request Aug 12, 2026
…ease/2.0 (#3767)

Ports the PostgreSQL GraphQL groupby/aggregation and related feature
commits from `main` (released in v2.1.0-rc) to `release/2.0` via
cherry-pick.

## Commits ported (chronological)
| PR | Title |
|----|-------|
| #3450 | Fix GraphQL aggregation features disabled when runtime.graphql
config section is absent |
| #3694 | Database policy support for PUT/PATCH operations - PostgreSQL
|
| #3728 | Add support for DateTime filters in PostgreSQL |
| #3750 | Fix column mapping in GroupBy and aggregation queries |
| #3741 | Add groupby/aggregation support for PostgreSQL in GraphQL |
| #3753 | Enhance test coverage for GraphQL queries by adding orderBy
clause |

## Notes
- All six cherry-picks applied cleanly.
- One manual adjustment in `SqlMutationEngine.cs` (part of #3694 port):
the original referenced `effectiveOperationType` (a local introduced by
the unrelated refactor #3287, which is not in `release/2.0`).
Substituted `context.OperationType`, which is functionally equivalent in
that non-upsert branch and matches the `release/2.0` convention. Folded
into the #3694 commit.
- Solution builds clean (0 warnings, 0 errors).
- Integration tests (PostgreSql/MsSql) require live databases and were
not run locally.

---------

Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Aniruddh25 <3513779+Aniruddh25@users.noreply.github.com>
Co-authored-by: Aniruddh Munde <anmunde@microsoft.com>
Co-authored-by: Souvik Ghosh <souvikofficial04@gmail.com>
Co-authored-by: Arjun Narendra <arjunnarendra1@gmail.com>
Co-authored-by: RubenCerna2079 <32799214+RubenCerna2079@users.noreply.github.com>
Co-authored-by: Arpit Gupta <106474712+ar-guptaar@users.noreply.github.com>
Co-authored-by: ARPIT GUPTA <guptaar@microsoft.com>
Co-authored-by: Anusha Kolan <anushakolan10@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: GraphQL Aggregation features do not exist in DAB 2.0.0-rc schema

6 participants