-
Notifications
You must be signed in to change notification settings - Fork 163
Group by #7061
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
Open
angrykoala
wants to merge
22
commits into
dev
Choose a base branch
from
group-by
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Group by #7061
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
fedf86a
WIP groupBy schema
angrykoala 7511982
group by root input
angrykoala fad3038
Merge branch 'dev' into group-by
angrykoala 7a53b77
root connection types for groupBy
angrykoala 583c7ac
add new types for groupByEdge
angrykoala f507ff0
fix top level group by cypher
angrykoala d1b1c47
fix groupBy queries without projection
angrykoala 612aa24
add nested relationships in groupBy
angrykoala 1d4771b
disable nested groupBy
angrykoala d505e1c
remove nested group by schema
angrykoala 98cac6a
small code cleanup in groupBy
angrykoala 72ad129
fix groupBy with aggregations
angrykoala 404fc07
add tests on group by
angrykoala 0a17d10
tests for group by with aggregations and cypher
angrykoala aa35f47
validate group by in node type
angrykoala 75a98f3
Merge branch 'dev' into group-by
angrykoala 4c7d477
Merge branch 'dev' into group-by
angrykoala 717b839
update cypher builder version
angrykoala 199bae3
fix unit tests
angrykoala c31a5a7
add missing license header
angrykoala 040f22f
Merge remote-tracking branch 'origin/dev' into group-by
angrykoala f620369
add test for multiple group by fields
angrykoala File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| /* | ||
| * 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 { DirectiveLocation, GraphQLDirective } from "graphql"; | ||
|
|
||
| export const groupByDirective = new GraphQLDirective({ | ||
| name: "groupBy", | ||
| description: "Enables groupBy operations for this field", | ||
| locations: [DirectiveLocation.FIELD_DEFINITION], | ||
| args: {}, | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
packages/graphql/src/schema-model/annotation/GroupByAnnotation.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| /* | ||
| * 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 type { Annotation } from "./Annotation"; | ||
|
|
||
| export class GroupByAnnotation implements Annotation { | ||
| readonly name = "groupBy"; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
packages/graphql/src/schema-model/parser/annotations-parser/group-by-annotation.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| /* | ||
| * 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 type { DirectiveNode } from "graphql"; | ||
| import { GroupByAnnotation } from "../../annotation/GroupByAnnotation"; | ||
|
|
||
| export function parseGroupByAnnotation(_directive: DirectiveNode): GroupByAnnotation { | ||
| return new GroupByAnnotation(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
packages/graphql/src/schema/generation/connection-group-by.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| /* | ||
| * 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 type { | ||
| InputTypeComposer, | ||
| ObjectTypeComposer, | ||
| ObjectTypeComposerArgumentConfigMapDefinition, | ||
| SchemaComposer, | ||
| } from "graphql-compose"; | ||
| import type { ConcreteEntityAdapter } from "../../schema-model/entity/model-adapters/ConcreteEntityAdapter"; | ||
| import type { RelationshipAdapter } from "../../schema-model/relationship/model-adapters/RelationshipAdapter"; | ||
|
|
||
| /** Returns the type and args for groupBy field in connections */ | ||
| export function makeConnectionGroupByType({ | ||
| entityAdapter, | ||
| composer, | ||
| }: { | ||
| entityAdapter: ConcreteEntityAdapter; | ||
| composer: SchemaComposer; | ||
| }): { type: ObjectTypeComposer; args: ObjectTypeComposerArgumentConfigMapDefinition } | undefined { | ||
| const typeName = entityAdapter.operations.getConnectionGroupByTypename(); | ||
| const groupByFields = entityAdapter.groupByFields; | ||
|
|
||
| if (groupByFields.length === 0) { | ||
| return undefined; | ||
| } | ||
|
|
||
| return getOrCreateConnectionGroupBy({ | ||
| typeName, | ||
| composer, | ||
| edgeType: getGroupByEdgeType({ composer, entityAdapter }), | ||
| entityAdapter, | ||
| }); | ||
| } | ||
|
|
||
| function getOrCreateConnectionGroupBy({ | ||
| typeName, | ||
| composer, | ||
| edgeType, | ||
| entityAdapter, | ||
| }: { | ||
| typeName: string; | ||
| composer: SchemaComposer; | ||
| edgeType: ObjectTypeComposer; | ||
| entityAdapter: ConcreteEntityAdapter; | ||
| }): { | ||
| type: ObjectTypeComposer; | ||
| args: ObjectTypeComposerArgumentConfigMapDefinition; | ||
| } { | ||
| const inputArgs = getInputArgs({ entityAdapter, composer }); | ||
|
|
||
| if (composer.has(typeName)) { | ||
| return { type: composer.getOTC(typeName), args: inputArgs }; | ||
| } | ||
|
|
||
| const connectionGroupByOTC = composer.createObjectTC(typeName); | ||
| connectionGroupByOTC.addFields({ | ||
| edges: edgeType.NonNull.List.NonNull, | ||
| }); | ||
|
|
||
| return { type: connectionGroupByOTC, args: inputArgs }; | ||
| } | ||
|
|
||
| function getGroupByEdgeType({ | ||
| entityAdapter, | ||
| composer, | ||
| }: { | ||
| entityAdapter: ConcreteEntityAdapter | RelationshipAdapter; | ||
| composer: SchemaComposer; | ||
| }): ObjectTypeComposer { | ||
| const edgeTypeName = entityAdapter.operations.getConnectionGroupByEdgeTypename(); | ||
| return composer.getOrCreateOTC(edgeTypeName, (oc) => { | ||
| const nodeType = composer.getOTC(entityAdapter.name); | ||
| oc.addFields({ | ||
| node: nodeType.NonNull, | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| function getInputArgs({ entityAdapter, composer }: { entityAdapter: ConcreteEntityAdapter; composer: SchemaComposer }) { | ||
| const inputType = getOrCreateConnectionGroupByInputType({ entityAdapter, composer }); | ||
| return { | ||
| fields: inputType.NonNull, | ||
| }; | ||
| } | ||
|
|
||
| function getOrCreateConnectionGroupByInputType({ | ||
| entityAdapter, | ||
| composer, | ||
| }: { | ||
| entityAdapter: ConcreteEntityAdapter; | ||
| composer: SchemaComposer; | ||
| }): InputTypeComposer { | ||
| const typeName = entityAdapter.operations.getConnectionGroupByInputTypename(); | ||
| if (composer.has(typeName)) { | ||
| return composer.getITC(typeName); | ||
| } | ||
|
|
||
| const connectionGroupByITC = composer.createInputTC(typeName); | ||
| for (const attribute of entityAdapter.groupByFields) { | ||
| connectionGroupByITC.addFields({ | ||
| [attribute.name]: "Boolean", | ||
| }); | ||
| } | ||
|
|
||
| return connectionGroupByITC; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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