Skip to content

Group by#7061

Open
angrykoala wants to merge 22 commits intodevfrom
group-by
Open

Group by#7061
angrykoala wants to merge 22 commits intodevfrom
group-by

Conversation

@angrykoala
Copy link
Member

Description

This is a WIP branch for the groupBy feature, allowing queries to return elements grouped by a certain field.

E.g.:

type Movie @node {
    title: String! 
    released: Int! @groupBy
}
query {
  movies(groupBy: {released: true}) {
    edges {
        title # All movies per released year
    }
  }
}

@changeset-bot
Copy link

changeset-bot bot commented Feb 12, 2026

⚠️ No Changeset found

Latest commit: f620369

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@neo4j-team-graphql
Copy link
Collaborator

neo4j-team-graphql commented Mar 4, 2026

Performance Report

No Performance Changes

Show Full Table
name dbHits old dbHits time (ms) old time (ms) maxRows
aggregations.TopLevelAggregateWithMultipleFields 7936 7936 55 74 1134
aggregations.NestedAggregation 15407 15407 57 92 2174
aggregations.AggregationWithWhere 10833 10833 40 53 2174
aggregations.AggregationWhereWithinNestedRelationships 20097917 20097917 2125 2053 2008534
aggregations.AggregationWhereWithinNestedConnections 20097917 20097917 2048 2010 2008534
aggregations.InterfacesAggregations 8324 8324 84 118 2080
aggregations.InterfacesAggregationsWithTwoFields 13526 13526 173 133 2080
connections.Connection 12951 12951 82 87 2174
connections.NestedConnection 37705 37705 116 199 4516
connections.totalCount 1 1 16 24 1
cypher-directive-mutation.TopLevelMutationDirective 1135 1135 23 34 1134
cypher-directive.TopLevelSortWithCypher 12961 12961 36 53 2174
cypher-directive.TopLevelConnectionSortWithCypher 12961 12961 54 62 2174
cypher-directive.TopLevelSortWithCypherWithNested 13096 13096 56 61 2174
cypher-directive.TopLevelConnectionSortWithCypherWithNested 13096 13096 72 106 2174
cypher-directive.TopLevelSortWithExpensiveCypher 13725 13725 92 137 2174
cypher-directive.TopLevelConnectionSortWithExpensiveCypher 13266 13266 80 117 2174
fulltext.Fulltext 80 80 35 47 16
fulltext.FulltextWithNestedQuery 516 516 53 61 84
fulltext.FulltextWithSort 259 259 39 49 37
1262.NestedConnectionWhere 8703 8703 52 70 2174
187.QueryWhere 8564 8564 31 42 2154
2871.NestedRelationshipFilter 19632 19632 50 77 4395
batch-create.BatchCreate 3600 3600 86 109 600
connect.createAndConnect 4410 4410 47 57 1134
create.SimpleMutation 6 6 63 29 1
delete.SimpleDelete 19401 19401 634 691 1040
delete.NestedDeleteInUpdate 14688 14688 98 177 1179
update.NestedUpdate 10129 10129 63 75 2002
query.SimpleQuery 3121 3121 20 30 1040
query.SimpleQueryWithRelationship 15031 15031 58 58 2174
query.SimpleQueryWithNestedWhere 8713 8713 61 73 2154
query.Nested 3988 3988 65 93 1040
query.OrFilterOnRelationshipsAndNestedFilters 26947 26759 184 241 2031
query.QueryWithNestedIn 14480 14480 49 66 1960
query.DeeplyNestedConnectionWhere 8702 8702 63 85 2174
query.DeeplyNestedWithRelationshipFilters 17357 17357 120 145 1552
query.NestedWithRelationshipSingleFilters 3808 3808 138 183 1134
sorting.SortMultipleTypes 3436 3436 70 77 1040
sorting.SortMultipleTypesWithCypherWithCypher 13321 13321 92 92 2174
sorting.SortOnNestedFields 12951 12951 44 54 2174
sorting.SortDeeplyNestedFields 39785 39785 82 101 4516
sorting.ConnectionWithSort 3271 3271 58 65 1040
unions.SimpleUnionQuery 321 321 47 61 35
unions.SimpleUnionQueryWithMissingFields 293 293 46 71 35
unions.NestedUnion 309975 309975 249 299 33033

Old Schema Generation: 21.964s
Schema Generation: 22.254s
Old Subgraph Schema Generation: 25.717s
Subgraph Schema Generation: 25.780s

@angrykoala angrykoala marked this pull request as ready for review March 17, 2026 15:22
@angrykoala angrykoala changed the title WIP Group by Group by Mar 18, 2026
Copy link
Contributor

@a-alle a-alle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed we should test all directive combinations involving groupBy and add it to the invalid directive combination matrix if any is not supported. The matrix should anyway include the groupBy directive, with an empty array if all are supported.

Also, add tests for groupBy on fields of non-primitive types.
On this, does it work with ENUM?

composer: SchemaComposer;
}): { type: ObjectTypeComposer; args: ObjectTypeComposerArgumentConfigMapDefinition } | undefined {
const typeName = entityAdapter.operations.getConnectionGroupByTypename();
const groupByFields = entityAdapter.groupByFields;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems unnecessary as it's only used once

}

return fieldIsInNodeType(directiveLocationData);
// || fieldIsInRelationshipPropertiesType(directiveLocationData)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

/** Defines if the query should project edges */
protected shouldProjectEdges(): boolean {
const hasFields = this.nodeFields.length + this.edgeFields.length > 0;
const hasFields = this.nodeFields.length + this.edgeFields.length + this.fields.length > 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this "fields" thing is a bit ambiguous - is there a better way to name it?

import { Neo4jGraphQL } from "../../../../src";
import { formatCypher, formatParams, translateQuery } from "../../utils/tck-test-utils";

describe("Group By Directive - Top Level", () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want a tck test for any directive combination, eg groupBy + relationship?

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.

3 participants