diff --git a/packages/graphql/src/translate/queryAST/ast/fields/aggregation-fields/CountField.ts b/packages/graphql/src/translate/queryAST/ast/fields/aggregation-fields/CountField.ts index 3d2fd32dac..3f42b74f3b 100644 --- a/packages/graphql/src/translate/queryAST/ast/fields/aggregation-fields/CountField.ts +++ b/packages/graphql/src/translate/queryAST/ast/fields/aggregation-fields/CountField.ts @@ -51,7 +51,7 @@ export class CountField extends AggregationField { } public getAggregationExpr(variable: Cypher.Variable): Cypher.Expr { - return Cypher.count(variable).distinct(); + return Cypher.count(variable); } public getAggregationProjection(target: Cypher.Variable, returnVar: Cypher.Variable): Cypher.Clause { diff --git a/packages/graphql/src/translate/queryAST/ast/operations/ConnectionReadOperation.ts b/packages/graphql/src/translate/queryAST/ast/operations/ConnectionReadOperation.ts index 14118490fb..e2d3da1fcf 100644 --- a/packages/graphql/src/translate/queryAST/ast/operations/ConnectionReadOperation.ts +++ b/packages/graphql/src/translate/queryAST/ast/operations/ConnectionReadOperation.ts @@ -139,8 +139,10 @@ export class ConnectionReadOperation extends Operation { } public transpile(context: QueryASTContext): OperationTranspileResult { - const contextTarget = context.target; - if (!contextTarget) throw new Error(); + if (!context.hasTarget()) + throw new Error( + "Error generating query: contxt has no target in ConnectionReadOperation. This is likely a bug with the @neo4j/graphql library" + ); // eslint-disable-next-line prefer-const let { selection: selectionClause, nestedContext } = this.selection.apply(context); @@ -170,7 +172,7 @@ export class ConnectionReadOperation extends Operation { const aggregationSubqueries = (this.aggregationField?.getSubqueries(context) ?? []).map((sq) => { const subquery = new Cypher.Call(sq); if (!isTopLevel) { - return subquery.importWith(contextTarget); + return subquery.importWith(context.target); } else { return subquery; } diff --git a/packages/graphql/tests/performance/graphql/aggregations.graphql b/packages/graphql/tests/performance/graphql/aggregations.graphql index 69ca9df969..8cfc60a82c 100644 --- a/packages/graphql/tests/performance/graphql/aggregations.graphql +++ b/packages/graphql/tests/performance/graphql/aggregations.graphql @@ -7,7 +7,7 @@ query TopLevelAggregate { } } -query TopLevelAggregateWithMultipleFields_only { +query TopLevelAggregateWithMultipleFields { peopleConnection { aggregate { count { @@ -25,7 +25,7 @@ query TopLevelAggregateWithMultipleFields_only { } } -query NestedAggregation_only { +query NestedAggregation { people { name moviesConnection { @@ -40,7 +40,7 @@ query NestedAggregation_only { } } -query TopLevelAggregateWithMultipleFieldsDeprecated_only { +query TopLevelAggregateWithMultipleFieldsDeprecated { peopleAggregate { count name {