Skip to content

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

Open
Copilot wants to merge 7 commits intomainfrom
copilot/fix-graphql-aggregation-features
Open

Fix GraphQL aggregation features disabled when runtime.graphql config section is absent#3450
Copilot wants to merge 7 commits intomainfrom
copilot/fix-graphql-aggregation-features

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 15, 2026

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 requested a review from Aniruddh25 April 15, 2026 22:22
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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.

@Aniruddh25 Aniruddh25 added the 2.0 label Apr 23, 2026
Comment thread src/Service.Tests/Configuration/RuntimeConfigLoaderTests.cs
Comment thread src/Service.Tests/Configuration/RuntimeConfigLoaderTests.cs Outdated
Comment thread src/Service.Tests/GraphQLBuilder/QueryBuilderTests.cs Outdated
Copy link
Copy Markdown
Contributor

@anushakolan anushakolan left a comment

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>
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

5 participants