diff --git a/packages/graphql/src/api-v6/schema-generation/schema-types/EntitySchemaTypes.ts b/packages/graphql/src/api-v6/schema-generation/schema-types/EntitySchemaTypes.ts deleted file mode 100644 index d1935a8304..0000000000 --- a/packages/graphql/src/api-v6/schema-generation/schema-types/EntitySchemaTypes.ts +++ /dev/null @@ -1,105 +0,0 @@ -/* - * 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, - ListComposer, - NonNullComposer, - ObjectTypeComposer, - ScalarTypeComposer, -} from "graphql-compose"; -import { connectionOperationResolver } from "../../resolvers/connection-operation-resolver"; -import type { EntityTypeNames } from "../../schema-model/graphql-type-names/EntityTypeNames"; -import type { SchemaBuilder } from "../SchemaBuilder"; -import type { SchemaTypes } from "./SchemaTypes"; - -/** This class defines the GraphQL types for an entity */ -export abstract class EntitySchemaTypes { - protected schemaBuilder: SchemaBuilder; - protected entityTypeNames: T; - protected schemaTypes: SchemaTypes; - - constructor({ - schemaBuilder, - entityTypeNames, - schemaTypes, - }: { - schemaBuilder: SchemaBuilder; - schemaTypes: SchemaTypes; - entityTypeNames: T; - }) { - this.schemaBuilder = schemaBuilder; - this.entityTypeNames = entityTypeNames; - this.schemaTypes = schemaTypes; - } - - public get connectionOperation(): ObjectTypeComposer { - return this.schemaBuilder.getOrCreateObjectType(this.entityTypeNames.connectionOperation, () => { - const args: { - first: ScalarTypeComposer; - after: ScalarTypeComposer; - sort?: ListComposer>; - } = { - first: this.schemaBuilder.types.int, - after: this.schemaBuilder.types.string, - }; - if (this.isSortable()) { - args.sort = this.connectionSort.NonNull.List; - } - return { - fields: { - connection: { - type: this.connection, - args: args, - resolve: connectionOperationResolver, - }, - }, - }; - }); - } - - protected get connection(): ObjectTypeComposer { - return this.schemaBuilder.getOrCreateObjectType(this.entityTypeNames.connection, () => { - return { - fields: { - pageInfo: this.schemaTypes.staticTypes.pageInfo, - edges: this.edge.List, - }, - }; - }); - } - - protected get connectionSort(): InputTypeComposer { - return this.schemaBuilder.getOrCreateInputType(this.entityTypeNames.connectionSort, () => { - return { - fields: { - edges: this.edgeSort, - }, - }; - }); - } - - protected abstract get edgeSort(): InputTypeComposer; - protected abstract get edge(): ObjectTypeComposer; - - public abstract get nodeType(): ObjectTypeComposer; - public abstract get nodeSort(): InputTypeComposer; - - public abstract isSortable(): boolean; -} diff --git a/packages/graphql/src/api-v6/schema-generation/schema-types/RelatedEntitySchemaTypes.ts b/packages/graphql/src/api-v6/schema-generation/schema-types/RelatedEntitySchemaTypes.ts index 7ca07b791e..c52940d803 100644 --- a/packages/graphql/src/api-v6/schema-generation/schema-types/RelatedEntitySchemaTypes.ts +++ b/packages/graphql/src/api-v6/schema-generation/schema-types/RelatedEntitySchemaTypes.ts @@ -17,7 +17,14 @@ * limitations under the License. */ -import type { EnumTypeComposer, InputTypeComposer, ObjectTypeComposer } from "graphql-compose"; +import type { + EnumTypeComposer, + InputTypeComposer, + ListComposer, + NonNullComposer, + ObjectTypeComposer, + ScalarTypeComposer, +} from "graphql-compose"; import { Memoize } from "typescript-memoize"; import type { Attribute } from "../../../schema-model/attribute/Attribute"; import { @@ -29,16 +36,19 @@ import { AttributeAdapter } from "../../../schema-model/attribute/model-adapters import { ConcreteEntity } from "../../../schema-model/entity/ConcreteEntity"; import type { Relationship } from "../../../schema-model/relationship/Relationship"; import { attributeAdapterToComposeFields } from "../../../schema/to-compose"; +import { connectionOperationResolver } from "../../resolvers/connection-operation-resolver"; import type { RelatedEntityTypeNames } from "../../schema-model/graphql-type-names/RelatedEntityTypeNames"; import type { SchemaBuilder } from "../SchemaBuilder"; -import { EntitySchemaTypes } from "./EntitySchemaTypes"; import type { SchemaTypes } from "./SchemaTypes"; import type { TopLevelEntitySchemaTypes } from "./TopLevelEntitySchemaTypes"; import { RelatedEntityFilterSchemaTypes } from "./filter-schema-types/RelatedEntityFilterSchemaTypes"; -export class RelatedEntitySchemaTypes extends EntitySchemaTypes { - private relationship: Relationship; +export class RelatedEntitySchemaTypes { public filterSchemaTypes: RelatedEntityFilterSchemaTypes; + private relationship: Relationship; + private schemaBuilder: SchemaBuilder; + private entityTypeNames: RelatedEntityTypeNames; + private schemaTypes: SchemaTypes; constructor({ relationship, @@ -51,20 +61,64 @@ export class RelatedEntitySchemaTypes extends EntitySchemaTypes { + const args: { + first: ScalarTypeComposer; + after: ScalarTypeComposer; + sort?: ListComposer>; + } = { + first: this.schemaBuilder.types.int, + after: this.schemaBuilder.types.string, + }; + if (this.isSortable()) { + args.sort = this.connectionSort.NonNull.List; + } + return { + fields: { + connection: { + type: this.connection, + args: args, + resolve: connectionOperationResolver, + }, + }, + }; + }); + } + + private get connection(): ObjectTypeComposer { + return this.schemaBuilder.getOrCreateObjectType(this.entityTypeNames.connection, () => { + return { + fields: { + pageInfo: this.schemaTypes.staticTypes.pageInfo, + edges: this.edge.List, + }, + }; + }); + } + + private get connectionSort(): InputTypeComposer { + return this.schemaBuilder.getOrCreateInputType(this.entityTypeNames.connectionSort, () => { + return { + fields: { + edges: this.edgeSort, + }, + }; + }); } - protected get edge(): ObjectTypeComposer { + private get edge(): ObjectTypeComposer { return this.schemaBuilder.getOrCreateObjectType(this.entityTypeNames.edge, () => { const properties = this.getEdgeProperties(); const fields = { @@ -81,7 +135,7 @@ export class RelatedEntitySchemaTypes extends EntitySchemaTypes { const edgeSortFields = {}; const properties = this.getEdgeSortProperties(); diff --git a/packages/graphql/src/api-v6/schema-generation/schema-types/TopLevelEntitySchemaTypes.ts b/packages/graphql/src/api-v6/schema-generation/schema-types/TopLevelEntitySchemaTypes.ts index 3e8e2ce3be..c713b3876a 100644 --- a/packages/graphql/src/api-v6/schema-generation/schema-types/TopLevelEntitySchemaTypes.ts +++ b/packages/graphql/src/api-v6/schema-generation/schema-types/TopLevelEntitySchemaTypes.ts @@ -18,7 +18,14 @@ */ import { type GraphQLResolveInfo } from "graphql"; -import type { InputTypeComposer, InterfaceTypeComposer, ObjectTypeComposer } from "graphql-compose"; +import type { + InputTypeComposer, + InterfaceTypeComposer, + ListComposer, + NonNullComposer, + ObjectTypeComposer, + ScalarTypeComposer, +} from "graphql-compose"; import { Memoize } from "typescript-memoize"; import type { Attribute } from "../../../schema-model/attribute/Attribute"; import type { AttributeType, Neo4jGraphQLScalarType } from "../../../schema-model/attribute/AttributeType"; @@ -33,17 +40,20 @@ import type { ConcreteEntity } from "../../../schema-model/entity/ConcreteEntity import { idResolver } from "../../../schema/resolvers/field/id"; import { numericalResolver } from "../../../schema/resolvers/field/numerical"; import type { Neo4jGraphQLTranslationContext } from "../../../types/neo4j-graphql-translation-context"; +import { connectionOperationResolver } from "../../resolvers/connection-operation-resolver"; import { generateGlobalIdFieldResolver } from "../../resolvers/global-id-field-resolver"; import type { TopLevelEntityTypeNames } from "../../schema-model/graphql-type-names/TopLevelEntityTypeNames"; import type { FieldDefinition, GraphQLResolver, SchemaBuilder } from "../SchemaBuilder"; -import { EntitySchemaTypes } from "./EntitySchemaTypes"; import { RelatedEntitySchemaTypes } from "./RelatedEntitySchemaTypes"; import type { SchemaTypes } from "./SchemaTypes"; import { TopLevelFilterSchemaTypes } from "./filter-schema-types/TopLevelFilterSchemaTypes"; -export class TopLevelEntitySchemaTypes extends EntitySchemaTypes { +export class TopLevelEntitySchemaTypes { private entity: ConcreteEntity; private filterSchemaTypes: TopLevelFilterSchemaTypes; + private schemaBuilder: SchemaBuilder; + private entityTypeNames: TopLevelEntityTypeNames; + private schemaTypes: SchemaTypes; constructor({ entity, @@ -54,13 +64,11 @@ export class TopLevelEntitySchemaTypes extends EntitySchemaTypes { + const args: { + first: ScalarTypeComposer; + after: ScalarTypeComposer; + sort?: ListComposer>; + } = { + first: this.schemaBuilder.types.int, + after: this.schemaBuilder.types.string, + }; + if (this.isSortable()) { + args.sort = this.connectionSort.NonNull.List; + } + return { + fields: { + connection: { + type: this.connection, + args: args, + resolve: connectionOperationResolver, + }, + }, + }; + }); + } + + private get connection(): ObjectTypeComposer { + return this.schemaBuilder.getOrCreateObjectType(this.entityTypeNames.connection, () => { + return { + fields: { + pageInfo: this.schemaTypes.staticTypes.pageInfo, + edges: this.edge.List, + }, + }; + }); + } + + private get connectionSort(): InputTypeComposer { return this.schemaBuilder.getOrCreateInputType(this.entityTypeNames.connectionSort, () => { return { fields: { @@ -91,7 +135,7 @@ export class TopLevelEntitySchemaTypes extends EntitySchemaTypes { return { fields: { @@ -102,7 +146,7 @@ export class TopLevelEntitySchemaTypes extends EntitySchemaTypes { return { fields: {