Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Branch] Aggregation 7 #6011

Draft
wants to merge 116 commits into
base: 7.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
116 commits
Select commit Hold shift + click to select a range
c340f32
Add aggregation fields inside connection
angrykoala Jan 17, 2025
484c061
Fix aggregation aliases
angrykoala Jan 20, 2025
6cc7a09
update top level aggregation tests
angrykoala Jan 20, 2025
ef2d979
Add interface aggregations on top level
angrykoala Jan 21, 2025
c3e3416
Update tck tests with aggregate
angrykoala Jan 21, 2025
4e8ab68
Deprecate top level aggregation
angrykoala Jan 21, 2025
233dc74
Fix unit tests
angrykoala Jan 21, 2025
a6e9486
Add deprecation flag
angrykoala Jan 22, 2025
f0cc167
Cleanup of aggregations inside connections code
angrykoala Jan 22, 2025
5d36415
Test multiple aliased aggregations in the same connection
angrykoala Jan 22, 2025
2cb4148
Merge pull request #5944 from neo4j/aggregation-connections
angrykoala Jan 23, 2025
922f788
Merge branch 'dev' into aggregation-6
angrykoala Jan 24, 2025
f32e374
Merge branch 'dev' into aggregation-6
angrykoala Jan 27, 2025
b5510f0
Merge remote-tracking branch 'upstream/aggregation-6' into aggregation-7
MacondoExpress Jan 28, 2025
d234105
Merge branch 'dev' into aggregation-6
angrykoala Jan 29, 2025
07ee3d1
Add nested aggregations inside connections in schema
angrykoala Jan 30, 2025
1fb4b68
Update schema tests with nested aggregate types
angrykoala Jan 30, 2025
00e3293
initial implementation
MacondoExpress Jan 30, 2025
6a5498d
wip, remove union from be generated as aggregation filters, update sc…
MacondoExpress Jan 30, 2025
953fd65
wip add first integration test
MacondoExpress Jan 30, 2025
a22b8f7
update aggregation/node tests to use aggregation filters inside conne…
MacondoExpress Jan 31, 2025
11fbf54
update aggregation/where/edge tests to use aggregation filters inside…
MacondoExpress Jan 31, 2025
13ec601
update tests to use new aggregate/generic operator syntax
MacondoExpress Jan 31, 2025
9ca08fc
refactor test count.int.test.ts and separate count-interface suite to…
MacondoExpress Feb 3, 2025
5e448e1
nested aggregations in connection
angrykoala Jan 31, 2025
034b1fa
improve aggregation/top-level tests batch(1)
MacondoExpress Feb 5, 2025
5c898e6
Fix aggregation on empty relationships
angrykoala Feb 5, 2025
1f2e47a
improve aggregation/top-level tests batch(2)
MacondoExpress Feb 5, 2025
af5b66e
add authorization filter test, for new aggregation
MacondoExpress Feb 5, 2025
3362063
add test coverage for authorization with aggregation rules and nested…
MacondoExpress Feb 6, 2025
dc8be5a
Merge pull request #5994 from MacondoExpress/aggregation-filters-insi…
MacondoExpress Feb 6, 2025
953ba63
Fix subqueries with interface aggregations
angrykoala Feb 10, 2025
74f727e
Fix projection of aggregations in interfaces
angrykoala Feb 10, 2025
e382d3b
added schema changes for aggregation count filters
MacondoExpress Feb 11, 2025
47f915e
Deprecate field aggregate fields in favor of nested connection aggreg…
angrykoala Feb 11, 2025
ee18210
Apply PR suggestions
angrykoala Feb 11, 2025
1540f5a
Merge pull request #5993 from neo4j/nested-aggregations-6
angrykoala Feb 11, 2025
932bfa7
Merge pull request #5999 from neo4j/nested-aggregations-deprecation
angrykoala Feb 11, 2025
31fe533
Merge branch 'dev' into aggregation-6
angrykoala Feb 11, 2025
271a0a3
merge aggregation-6-into-aggregation-7
MacondoExpress Feb 11, 2025
9047101
Fix changelog messages
angrykoala Feb 11, 2025
3470dea
fix relationship adapter unit test
MacondoExpress Feb 11, 2025
09fe679
Merge pull request #6000 from MacondoExpress/merge-aggregation-6-into…
MacondoExpress Feb 11, 2025
d672232
disable-eslint on skipped tests in aggregations
angrykoala Feb 11, 2025
9551284
update tests to support count nodes syntax
MacondoExpress Feb 11, 2025
40759a5
WIP count aggregation
angrykoala Feb 12, 2025
d3fb0a9
update aggregation/tests to use the new count syntax
MacondoExpress Feb 12, 2025
e6bb032
fix old aggregate filtering syntax, add tests for it
MacondoExpress Feb 13, 2025
613c665
Fix top level count with nested nodes fields
angrykoala Feb 13, 2025
de4c7be
Fix nested node count
angrykoala Feb 13, 2025
16e471d
implement and test aggregation count for edges, fixed count for nodes…
MacondoExpress Feb 14, 2025
4b1fbee
add .int suffix to count-edges.test.ts
MacondoExpress Feb 14, 2025
2952820
Count in nested aggregation with edges and nodes
angrykoala Feb 14, 2025
7f067a4
Update schema tests
angrykoala Feb 14, 2025
1a56515
add count-edges tck test
MacondoExpress Feb 14, 2025
55c897f
improve coverage over edges and distinct count
MacondoExpress Feb 14, 2025
833d911
Fix auth on aggregations
angrykoala Feb 14, 2025
6def30d
Fix performance tests
angrykoala Feb 17, 2025
587ffbb
Add code review changes
angrykoala Feb 17, 2025
7a68d7a
Remove arrow function on numerical resolvers
angrykoala Feb 17, 2025
128051d
Merge pull request #6003 from neo4j/count-aggregation
angrykoala Feb 17, 2025
2243a37
Merge branch 'dev' into aggregation-6
angrykoala Feb 17, 2025
25f3169
Merge branch 'dev' into aggregation-6
angrykoala Feb 17, 2025
9600435
Fix performance issue with new aggregations
angrykoala Feb 17, 2025
da68f2b
Code review changes
angrykoala Feb 18, 2025
3ff5dd9
Add distinct to new count in aggregation
angrykoala Feb 18, 2025
b105601
Update tck tests
angrykoala Feb 18, 2025
d9d8300
Merge branch 'dev' into aggregation-6
angrykoala Feb 18, 2025
d84f56c
Merge pull request #6006 from neo4j/fix-performance
angrykoala Feb 18, 2025
f582b91
Fix unit tests in aggregations 6 branch
angrykoala Feb 18, 2025
5667e6c
decouple count distinct fix
MacondoExpress Feb 18, 2025
de3ef63
update schema tests
MacondoExpress Feb 18, 2025
704ac20
Merge branch 'aggregation-7' into aggregation-filters-count
MacondoExpress Feb 18, 2025
b0b1d60
Fix e2e tests
angrykoala Feb 18, 2025
7011898
Update packages/graphql/src/classes/Neo4jGraphQL.ts
angrykoala Feb 18, 2025
27f6492
Merge pull request #6010 from neo4j/fix-tests-aggregation-6
angrykoala Feb 18, 2025
69ff2c9
Update schema tests
angrykoala Feb 18, 2025
b741047
Add distinct to aggregation subqueries
angrykoala Feb 18, 2025
7a40949
Merge pull request #6004 from MacondoExpress/aggregation-filters-count
MacondoExpress Feb 18, 2025
9eb22d3
Merge pull request #6009 from neo4j/fix-count-distinct
angrykoala Feb 18, 2025
5a3afbc
Update tck test
angrykoala Feb 18, 2025
de7eae4
test difference between aggregation filters (legacy vs Connection) on…
MacondoExpress Feb 18, 2025
2aed967
add test coverage for aggregation rule on authorization
MacondoExpress Feb 19, 2025
02a09f0
fix count distinct
MacondoExpress Feb 20, 2025
3309bec
temporary fix localdatetime, types tests require some refactor.
MacondoExpress Feb 19, 2025
90005eb
extend temporary fix on localdatetime to deprecated tests
MacondoExpress Feb 20, 2025
03ee6e4
reintroduce wrongly removed skipped test
MacondoExpress Feb 20, 2025
0957fea
revert the aggregatio->node distinct, and added test for the differen…
MacondoExpress Feb 21, 2025
5a30d66
Merge pull request #6014 from MacondoExpress/extend-authorization-agg…
MacondoExpress Feb 24, 2025
f9bcae5
apply PR suggestions
MacondoExpress Feb 24, 2025
d146c97
Merge remote-tracking branch 'origin/dev' into aggregation-6
angrykoala Feb 24, 2025
d99e63f
separate test files for 6005
MacondoExpress Feb 24, 2025
30f4960
Merge pull request #6018 from MacondoExpress/aggregation-filter-count…
MacondoExpress Feb 24, 2025
2318336
add required changeset for aggregation filters changes in 7.x
MacondoExpress Feb 24, 2025
bf8bfc3
add deprecation for aggregation filter outside connection input
MacondoExpress Feb 24, 2025
eae6147
Merge remote-tracking branch 'origin/aggregation-6' into aggregation-7
angrykoala Feb 25, 2025
b9f493a
Fix subscription schema test
angrykoala Feb 25, 2025
65a995e
Merge pull request #6022 from neo4j/sync-aggregation
angrykoala Feb 25, 2025
7e18b7d
Merge remote-tracking branch 'origin/7.x' into aggregation-7
angrykoala Feb 25, 2025
c5651ec
Update tck test
angrykoala Feb 25, 2025
7af0fb2
fix authorization aggregation filter test
MacondoExpress Feb 25, 2025
1e9eaf1
Merge branch 'aggregation-7' of github.com:neo4j/graphql into aggrega…
MacondoExpress Feb 25, 2025
240365a
Remove distinct from non-count aggregations
angrykoala Feb 25, 2025
667e75c
add changeset and excludeDeprecatedFields option for aggregationFilte…
MacondoExpress Feb 25, 2025
5838f84
fix typo in the changeset summary
MacondoExpress Feb 25, 2025
aaf8938
fix typo
MacondoExpress Feb 25, 2025
da37476
Merge pull request #6023 from neo4j/remove-distinct-from-non-count-ag…
angrykoala Feb 26, 2025
01fb6b8
Merge remote-tracking branch 'origin/aggregation-6' into aggregation-7
angrykoala Feb 26, 2025
a9509f5
Update .changeset/silent-phones-sort.md
MacondoExpress Feb 26, 2025
da0d5f6
Fix 4615 with new aggregations
angrykoala Feb 27, 2025
270f5ef
Merge pull request #6028 from neo4j/fix-4615
angrykoala Feb 27, 2025
2a28035
Merge remote-tracking branch 'origin/aggregation-6' into aggregation-7
angrykoala Feb 27, 2025
f74374c
apply PR suggestion
MacondoExpress Feb 28, 2025
2b8a63c
Merge branch 'aggregation-7' into add-deprecations-and-changesets
MacondoExpress Feb 28, 2025
67375eb
update schema tests
MacondoExpress Feb 28, 2025
9e01391
Merge pull request #6024 from MacondoExpress/add-deprecations-and-cha…
MacondoExpress Feb 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .changeset/funny-tools-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
"@neo4j/graphql": patch
---

Following the changes of moving aggregations inside the connection fields,
the previous aggregations filters outside the connection filters are now deprecated.

The flag `aggregationFiltersOutsideConnection` has been added to the excludeDeprecatedFields setting.

```ts
const neoSchema = new Neo4jGraphQL({
typeDefs,
features: { excludeDeprecatedFields: { aggregationFiltersOutsideConnection: true } },
});
```
25 changes: 25 additions & 0 deletions .changeset/gorgeous-goats-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
"@neo4j/graphql": minor
---

Aggregations filters are moved to the connection input field.

**Current aggregation filters:**

```graphql
{
posts(where: { likesConnection: { aggregate: { node: { someInt: { average: { eq: 10 } } } } } }) {
content
}
}
```

**Deprecated aggregation filters:**

```graphql
{
posts(where: { likesAggregate: { node: { someInt: { average: { eq: 10 } } } } }) {
content
}
}
```
32 changes: 32 additions & 0 deletions .changeset/hot-bikes-complain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
"@neo4j/graphql": patch
---

Add count fields in aggregations with support for nodes and edges count:

```graphql
query {
moviesConnection {
aggregate {
count {
nodes
}
}
}
}
```

```graphql
query {
movies {
actorsConnection {
aggregate {
count {
nodes
edges
}
}
}
}
}
```
20 changes: 20 additions & 0 deletions .changeset/hot-windows-whisper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
"@neo4j/graphql": minor
---

Add aggregate field in connection:

```graphql
query {
moviesConnection {
aggregate {
node {
count
int {
longest
}
}
}
}
}
```
31 changes: 31 additions & 0 deletions .changeset/silent-phones-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
"@neo4j/graphql": minor
---

The aggregation filter `count` now supports both, nodes and relationships.

**Count filter on nodes:**

```graphql
{
posts(where: { likesConnection: { aggregate: { count: { nodes: { eq: 2 } } } } }) {
title
likes {
name
}
}
}
```

**Count filter on edges:**

```graphql
{
posts(where: { likesConnection: { aggregate: { count: { edges: { eq: 2 } } } } }) {
title
likes {
name
}
}
}
```
5 changes: 5 additions & 0 deletions .changeset/sixty-steaks-reflect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@neo4j/graphql": patch
---

Deprecate aggregation fields (e.g `actedInAggregate`) in favor of the field `aggregate` inside the connection (e.g `actedInConnection -> aggregate`)
22 changes: 22 additions & 0 deletions .changeset/soft-socks-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
"@neo4j/graphql": patch
---

Add `addVersionPrefix` to `cypherQueryOptions` in context to add a Cypher version with `CYPHER` before each query:

```js
{
cypherQueryOptions: {
addVersionPrefix: true,
},
}
```

This prepends all Cypher queries with a `CYPHER [version]` statement:

```cypher
CYPHER 5
MATCH (this:Movie)
WHERE this.title = $param0
RETURN this { .title } AS this
```
25 changes: 25 additions & 0 deletions .changeset/thin-goats-begin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
"@neo4j/graphql": patch
---

Deprecated old aggregate operations:

```graphql
query {
moviesAggregate {
count
rating {
min
}
}
}
```

These fields can be completely removed from the schema with the new flag `deprecatedAggregateOperations`:

```js
const neoSchema = new Neo4jGraphQL({
typeDefs,
features: { excludeDeprecatedFields: { deprecatedAggregateOperations: true } },
});
```
2 changes: 1 addition & 1 deletion packages/graphql/src/classes/Neo4jDatabaseInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class Neo4jDatabaseInfo {
public edition: Neo4jEdition | undefined;

constructor(version: string, edition?: Neo4jEdition) {
// Quick hack to support CalVar
// Quick hack to support CalVer
version = version.replace(/\.0([0-9]+)/, ".$1");
this.version = this.toSemVer(version);
this.rawVersion = version;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { GraphQLInputObjectType } from "graphql";
import { IntScalarFilters } from "../generic-operators/IntScalarFilters";

export const ConnectionAggregationCountFilterInput = new GraphQLInputObjectType({
name: "ConnectionAggregationCountFilterInput",
fields: {
nodes: { type: IntScalarFilters },
edges: { type: IntScalarFilters },
},
});
2 changes: 1 addition & 1 deletion packages/graphql/src/graphql/objects/CartesianPoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const CartesianPoint = new GraphQLObjectType({
},
srid: {
type: new GraphQLNonNull(GraphQLInt),
resolve: (source, args, context, info) => numericalResolver(source, args, context, info),
resolve: numericalResolver,
},
},
});
2 changes: 1 addition & 1 deletion packages/graphql/src/graphql/objects/Point.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const Point = new GraphQLObjectType({
},
srid: {
type: new GraphQLNonNull(GraphQLInt),
resolve: (source, args, context, info) => numericalResolver(source, args, context, info),
resolve: numericalResolver,
},
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export type RootTypeFieldNames = {
type AggregateTypeNames = {
selection: string;
input: string;
connection: string;
node: string;
};

type MutationResponseTypeNames = {
Expand Down Expand Up @@ -129,10 +131,15 @@ export class ImplementingEntityOperations<T extends InterfaceEntityAdapter | Con
return `${this.entityAdapter.name}ImplementationsSubscriptionWhere`;
}

/** @deprecated use `getAggregateFieldTypename` instead */
public getAggregationFieldTypename(): string {
return this.aggregateTypeNames.selection;
}

public getAggregateFieldTypename(): string {
return this.aggregateTypeNames.selection;
}

public get rootTypeFieldNames(): RootTypeFieldNames {
return {
connection: `${this.entityAdapter.plural}Connection`,
Expand All @@ -148,6 +155,8 @@ export class ImplementingEntityOperations<T extends InterfaceEntityAdapter | Con
return {
selection: `${this.entityAdapter.name}AggregateSelection`,
input: `${this.entityAdapter.name}AggregateSelectionInput`,
connection: `${this.entityAdapter.name}Aggregate`,
node: `${this.entityAdapter.name}AggregateNode`,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ describe("RelationshipAdapter", () => {

test("should parse selectable", () => {
const relationshipAdapter = userAdapter.relationships.get("accounts");
expect(relationshipAdapter?.isAggregable()).toBeTrue();
expect(relationshipAdapter?.isAggregable()).toBeFalse();
expect(relationshipAdapter?.isReadable()).toBeFalse();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,14 @@ export class RelationshipAdapter {
}

public isAggregable(): boolean {
if (!this.aggregate) {
return false;
}

if (this.target instanceof UnionEntityAdapter || this.source instanceof InterfaceEntityAdapter) {
return false;
}

return this.annotations.selectable?.onAggregate !== false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ export abstract class RelationshipBaseOperations<T extends RelationshipAdapter |

protected abstract get edgePrefix(): string;

/**Note: Required for now to infer the types without ResolveTree */
/**Note: Required for now to infer the types without ResolveTree
* @deprecated use getAggregateFieldTypename
*
*/
public getAggregationFieldTypename(nestedField?: "node" | "edge"): string {
const nestedFieldStr = upperFirst(nestedField || "");
const aggregationStr = nestedField ? "Aggregate" : "Aggregation";
Expand All @@ -47,6 +50,13 @@ export abstract class RelationshipBaseOperations<T extends RelationshipAdapter |
)}${nestedFieldStr}${aggregationStr}Selection`;
}

public getAggregateFieldTypename(nestedField?: "node" | "edge"): string {
const nestedFieldStr = upperFirst(nestedField || "");
return `${this.relationship.source.name}${this.relationship.target.name}${upperFirst(
this.relationship.name
)}${nestedFieldStr}AggregateSelection`;
}

public getTargetTypePrettyName(): string {
if (this.relationship.isList) {
return `[${this.relationship.target.name}!]${!this.relationship.isNullable ? "!" : ""}`;
Expand Down Expand Up @@ -115,12 +125,16 @@ export abstract class RelationshipBaseOperations<T extends RelationshipAdapter |
public getUpdateConnectionInputTypename(ifUnionRelationshipTargetEntity?: ConcreteEntityAdapter): string {
return `${this.prefixForTypename}${ifUnionRelationshipTargetEntity?.name || ""}UpdateConnectionInput`;
}

// Legacy typename superseded by getUpdateConnectionInputTypename, which is slightly different type - contains nodes for edges/nodes
public get aggregateInputTypeName(): string {
return `${this.prefixForTypename}AggregateInput`;
}

public get aggregateTypeName(): string {
public get connectionAggregateInputTypeName(): string {
return `${this.prefixForTypename}ConnectionAggregateInput`;
}

public get aggregateFieldName(): string {
return `${this.relationship.name}Aggregate`;
}

Expand Down
Loading
Loading