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

Nested aggregations 6 #5993

Merged
merged 7 commits into from
Feb 11, 2025
Merged

Nested aggregations 6 #5993

merged 7 commits into from
Feb 11, 2025

Conversation

angrykoala
Copy link
Member

Description

Support for nested aggregations inside connections

Copy link

changeset-bot bot commented Feb 5, 2025

⚠️ No Changeset found

Latest commit: ee18210

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

@angrykoala angrykoala marked this pull request as ready for review February 10, 2025 15:28
Copy link
Contributor

@MacondoExpress MacondoExpress left a comment

Choose a reason for hiding this comment

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

Left some comments, but LGTM otherwise!

const isTargetUnion = relationshipAdapter.target instanceof UnionEntityAdapter;
const isSourceInterface = relationshipAdapter.source instanceof InterfaceEntityAdapter;

if (relationshipAdapter.isAggregable() && !isTargetUnion && !isSourceInterface) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the method isAggregable can hold the logic for isTargetUnion and isSourceInterface so that can be used a single source of truth

fields["aggregate"] = `${relationshipAdapter.operations.getAggregationFieldTypename()}!`;
}

const connectionObjectType = composer.createObjectTC({
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: you can create the objectTC first with the shared fields and then use the composer.addFields if needed for the aggregate field.

const isSourceInterface = relationshipAdapter.source instanceof InterfaceEntityAdapter;

if (relationshipAdapter.isAggregable() && !isTargetUnion && !isSourceInterface) {
fields["aggregate"] = `${relationshipAdapter.operations.getAggregationFieldTypename()}!`;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
fields["aggregate"] = `${relationshipAdapter.operations.getAggregationFieldTypename()}!`;
fields["aggregate"] = composer.getOTC(relationshipAdapter.operations.getAggregationFieldTypename()).NonNull;

}
const relationshipObjectType = composer.createObjectTC({
name: typeName,
fields: { cursor: new GraphQLNonNull(GraphQLString), node: `${relationshipAdapter.target.name}!` },
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
fields: { cursor: new GraphQLNonNull(GraphQLString), node: `${relationshipAdapter.target.name}!` },
fields: { cursor: new GraphQLNonNull(GraphQLString), node: composer.getOTC(relationshipAdapter.target.name).NonNull },

@@ -43,6 +43,7 @@ export class ConnectionAggregationField extends Field {
}) {
super(alias);
this.operation = operation;
this.operation.isInConnectionField = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

If possible I would handle this in the factory rather than on the constructor

typeDefs = `
type ${typeMovie.name} @node {
title: String
${typeActor.plural}: [${typeActor.name}!]! @relationship(type: "ACTED_IN", direction: IN, properties:"ActedIn")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
${typeActor.plural}: [${typeActor.name}!]! @relationship(type: "ACTED_IN", direction: IN, properties:"ActedIn")
actors: [${typeActor.name}!]! @relationship(type: "ACTED_IN", direction: IN, properties:"ActedIn")

This is applicable also below

typeDefs = `
type ${typeMovie.name} @node {
title: String
${typeActor.plural}: [${typeActor.name}!]! @relationship(type: "ACTED_IN", direction: IN, properties:"ActedIn")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
${typeActor.plural}: [${typeActor.name}!]! @relationship(type: "ACTED_IN", direction: IN, properties:"ActedIn")
actors: [${typeActor.name}!]! @relationship(type: "ACTED_IN", direction: IN, properties:"ActedIn")

same below

@angrykoala angrykoala merged commit 1540f5a into aggregation-6 Feb 11, 2025
2 checks passed
@angrykoala angrykoala deleted the nested-aggregations-6 branch February 11, 2025 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants