Skip to content

Aggregate builds an invalid query when using typeorm with mssql #436

Open

Description

@abrenoch

Describe the bug
When using the aggregate functionality with typeorm connected to a mssql server, the GROUP BY and ORDER BY are not built in a valid way.

To Reproduce
Steps to reproduce the behavior:

  1. Connect using typeorm with the mssql database driver
  2. Setup a DTO to use the aggregate resolver with nestjs-query
  3. Issue a query that returns a groupBy
  4. An error stating the query had an invalid column name will be reported

Expected behavior
The query runs and returns data

Desktop (please complete the following information):

  • Node Version 24
  • Nestjs-query Version 9.3.0

Additional context
Query:

query Count($filter: CustomerAggregateFilter) {
  aggregateCustomers(filter: $filter) {
    count {
      code
    }
    groupBy {
      code
    }
  }
}

Args:

{
  "filter": {
    "status": {
      "eq": "Active"
    }
  }
}

Error: Error: Invalid column name 'GROUP_BY_code

The DB query (simplified):

SELECT 
  "CustomerEntity"."CUSTOMER_CODE" AS "GROUP_BY_code", 
  COUNT("CustomerEntity"."CUSTOMER_CODE") AS "COUNT_code" 
FROM "CUSTOMER" "CustomerEntity" 
GROUP BY "GROUP_BY_code" 
ORDER BY "GROUP_BY_code" ASC

Mssql only support actual column names in the 'GROUP BY' clause... subsequently the 'ORDER BY' would also then be invalid. The fix would seem to be using the actual column names here.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions