From f582b91dc9c1a0617f70b6432b9e08087e83a715 Mon Sep 17 00:00:00 2001 From: angrykoala Date: Tue, 18 Feb 2025 10:54:08 +0000 Subject: [PATCH 1/3] Fix unit tests in aggregations 6 branch --- .../relationship/model-adapters/RelationshipAdapter.test.ts | 2 +- ...ns-types-mapper.test.ts => aggregation-types-mapper.test.ts} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename packages/graphql/src/schema/aggregations/{aggregations-types-mapper.test.ts => aggregation-types-mapper.test.ts} (100%) diff --git a/packages/graphql/src/schema-model/relationship/model-adapters/RelationshipAdapter.test.ts b/packages/graphql/src/schema-model/relationship/model-adapters/RelationshipAdapter.test.ts index ba352de775..ae619af991 100644 --- a/packages/graphql/src/schema-model/relationship/model-adapters/RelationshipAdapter.test.ts +++ b/packages/graphql/src/schema-model/relationship/model-adapters/RelationshipAdapter.test.ts @@ -142,7 +142,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(); }); }); diff --git a/packages/graphql/src/schema/aggregations/aggregations-types-mapper.test.ts b/packages/graphql/src/schema/aggregations/aggregation-types-mapper.test.ts similarity index 100% rename from packages/graphql/src/schema/aggregations/aggregations-types-mapper.test.ts rename to packages/graphql/src/schema/aggregations/aggregation-types-mapper.test.ts From b0b1d603b0e312f6375aeedf957d57c09f40de7a Mon Sep 17 00:00:00 2001 From: angrykoala Date: Tue, 18 Feb 2025 11:51:44 +0000 Subject: [PATCH 2/3] Fix e2e tests --- packages/graphql/src/classes/Neo4jGraphQL.ts | 1 + .../aggregations/aggregation-types-mapper.ts | 41 +++++++++++++++++++ .../field-aggregation-composer.ts | 3 +- .../src/schema/generation/aggregate-types.ts | 32 +-------------- 4 files changed, 44 insertions(+), 33 deletions(-) diff --git a/packages/graphql/src/classes/Neo4jGraphQL.ts b/packages/graphql/src/classes/Neo4jGraphQL.ts index 83eddd4782..a961dbc74e 100644 --- a/packages/graphql/src/classes/Neo4jGraphQL.ts +++ b/packages/graphql/src/classes/Neo4jGraphQL.ts @@ -125,6 +125,7 @@ class Neo4jGraphQL { } public async getSubgraphSchema(): Promise { + console.log("Get subgraph schema"); if (!this.subgraphSchema) { this.subgraphSchema = this.generateSubgraphSchema(); await this.subgraphSchema; diff --git a/packages/graphql/src/schema/aggregations/aggregation-types-mapper.ts b/packages/graphql/src/schema/aggregations/aggregation-types-mapper.ts index 555a373453..c8f0b12d58 100644 --- a/packages/graphql/src/schema/aggregations/aggregation-types-mapper.ts +++ b/packages/graphql/src/schema/aggregations/aggregation-types-mapper.ts @@ -17,6 +17,7 @@ * limitations under the License. */ +import { GraphQLInt, GraphQLNonNull } from "graphql"; import type { ObjectTypeComposer, SchemaComposer } from "graphql-compose"; import type { Subgraph } from "../../classes/Subgraph"; import { idResolver } from "../resolvers/field/id"; @@ -26,16 +27,56 @@ export class AggregationTypesMapper { private readonly aggregationSelectionTypes: Record>; private readonly subgraph: Subgraph | undefined; + private readonly composer: SchemaComposer; constructor(composer: SchemaComposer, subgraph?: Subgraph) { this.subgraph = subgraph; this.aggregationSelectionTypes = this.getOrCreateAggregationSelectionTypes(composer); + this.composer = composer; } public getAggregationType(typeName: string): ObjectTypeComposer | undefined { return this.aggregationSelectionTypes[typeName]; } + /** Top level count */ + public getCountType(): ObjectTypeComposer { + const countFieldName = "Count"; + const directives: string[] = this.subgraph ? [this.subgraph.getFullyQualifiedDirectiveName("shareable")] : []; + return this.composer.getOrCreateOTC(countFieldName, (countField) => { + countField.addFields({ + nodes: { + type: new GraphQLNonNull(GraphQLInt), + resolve: numericalResolver, + }, + }); + for (const directiveName of directives) { + countField.setDirectiveByName(directiveName); + } + }); + } + + /** Nested count */ + public getCountConnectionType(): ObjectTypeComposer { + const countFieldName = "CountConnection"; + const directives: string[] = this.subgraph ? [this.subgraph.getFullyQualifiedDirectiveName("shareable")] : []; + return this.composer.getOrCreateOTC(countFieldName, (countField) => { + countField.addFields({ + nodes: { + type: new GraphQLNonNull(GraphQLInt), + resolve: numericalResolver, + }, + edges: { + type: new GraphQLNonNull(GraphQLInt), + resolve: numericalResolver, + }, + }); + for (const directiveName of directives) { + countField.setDirectiveByName(directiveName); + } + }); + } + private getOrCreateAggregationSelectionTypes( composer: SchemaComposer ): Record> { diff --git a/packages/graphql/src/schema/aggregations/field-aggregation-composer.ts b/packages/graphql/src/schema/aggregations/field-aggregation-composer.ts index cfb0d2047c..b5d5b79fd5 100644 --- a/packages/graphql/src/schema/aggregations/field-aggregation-composer.ts +++ b/packages/graphql/src/schema/aggregations/field-aggregation-composer.ts @@ -27,7 +27,6 @@ import { RelationshipAdapter } from "../../schema-model/relationship/model-adapt import type { RelationshipDeclarationAdapter } from "../../schema-model/relationship/model-adapters/RelationshipDeclarationAdapter"; import type { Neo4jFeaturesSettings } from "../../types"; import { DEPRECATE_ID_AGGREGATION } from "../constants"; -import { getCountConnectionType } from "../generation/aggregate-types"; import { shouldAddDeprecatedFields } from "../generation/utils"; import { numericalResolver } from "../resolvers/field/numerical"; import { AggregationTypesMapper } from "./aggregation-types-mapper"; @@ -85,7 +84,7 @@ export class FieldAggregationComposer { this.composer.createObjectTC({ name: relationshipAdapter.operations.getAggregateFieldTypename(), fields: { - count: getCountConnectionType(this.composer).NonNull, + count: this.aggregationTypesMapper.getCountConnectionType().NonNull, ...(aggregateSelectionNode ? { node: aggregateSelectionNode } : {}), ...(aggregateSelectionEdge ? { edge: aggregateSelectionEdge } : {}), }, diff --git a/packages/graphql/src/schema/generation/aggregate-types.ts b/packages/graphql/src/schema/generation/aggregate-types.ts index e971fcde4f..ef8c34d99a 100644 --- a/packages/graphql/src/schema/generation/aggregate-types.ts +++ b/packages/graphql/src/schema/generation/aggregate-types.ts @@ -74,36 +74,6 @@ export function withAggregateSelectionType({ return aggregateSelection; } -/** Top level count */ -export function getCountType(composer: SchemaComposer): ObjectTypeComposer { - const countFieldName = "Count"; - return composer.getOrCreateOTC(countFieldName, (countField) => { - countField.addFields({ - nodes: { - type: new GraphQLNonNull(GraphQLInt), - resolve: numericalResolver, - }, - }); - }); -} - -/** Nested count */ -export function getCountConnectionType(composer: SchemaComposer): ObjectTypeComposer { - const countFieldName = "CountConnection"; - return composer.getOrCreateOTC(countFieldName, (countField) => { - countField.addFields({ - nodes: { - type: new GraphQLNonNull(GraphQLInt), - resolve: numericalResolver, - }, - edges: { - type: new GraphQLNonNull(GraphQLInt), - resolve: numericalResolver, - }, - }); - }); -} - /** Create aggregate field inside connections */ function createConnectionAggregate({ entityAdapter, @@ -133,7 +103,7 @@ function createConnectionAggregate({ const connectionAggregate = composer.createObjectTC({ name: entityAdapter.operations.aggregateTypeNames.connection, fields: { - count: getCountType(composer).NonNull, + count: aggregationTypesMapper.getCountType().NonNull, }, directives: graphqlDirectivesToCompose(propagatedDirectives), }); From 7011898b0c33e9c4c5a947caaa5195f345493f1c Mon Sep 17 00:00:00 2001 From: angrykoala Date: Tue, 18 Feb 2025 14:08:42 +0000 Subject: [PATCH 3/3] Update packages/graphql/src/classes/Neo4jGraphQL.ts Co-authored-by: MacondoExpress --- packages/graphql/src/classes/Neo4jGraphQL.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/graphql/src/classes/Neo4jGraphQL.ts b/packages/graphql/src/classes/Neo4jGraphQL.ts index a961dbc74e..83eddd4782 100644 --- a/packages/graphql/src/classes/Neo4jGraphQL.ts +++ b/packages/graphql/src/classes/Neo4jGraphQL.ts @@ -125,7 +125,6 @@ class Neo4jGraphQL { } public async getSubgraphSchema(): Promise { - console.log("Get subgraph schema"); if (!this.subgraphSchema) { this.subgraphSchema = this.generateSubgraphSchema(); await this.subgraphSchema;