Skip to content

Commit

Permalink
Remove inheritance in schema types
Browse files Browse the repository at this point in the history
  • Loading branch information
angrykoala committed Jul 25, 2024
1 parent da1d798 commit 0a417db
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 127 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<RelatedEntityTypeNames> {
private relationship: Relationship;
export class RelatedEntitySchemaTypes {
public filterSchemaTypes: RelatedEntityFilterSchemaTypes;
private relationship: Relationship;
private schemaBuilder: SchemaBuilder;
private entityTypeNames: RelatedEntityTypeNames;
private schemaTypes: SchemaTypes;

constructor({
relationship,
Expand All @@ -51,20 +61,64 @@ export class RelatedEntitySchemaTypes extends EntitySchemaTypes<RelatedEntityTyp
schemaTypes: SchemaTypes;
entityTypeNames: RelatedEntityTypeNames;
}) {
super({
schemaBuilder,
entityTypeNames,
schemaTypes,
});
this.relationship = relationship;
this.filterSchemaTypes = new RelatedEntityFilterSchemaTypes({
schemaBuilder,
relationship: relationship,
schemaTypes,
});
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<NonNullComposer<InputTypeComposer>>;
} = {
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 = {
Expand All @@ -81,7 +135,7 @@ export class RelatedEntitySchemaTypes extends EntitySchemaTypes<RelatedEntityTyp
});
}

protected get edgeSort(): InputTypeComposer {
private get edgeSort(): InputTypeComposer {
return this.schemaBuilder.getOrCreateInputType(this.entityTypeNames.edgeSort, () => {
const edgeSortFields = {};
const properties = this.getEdgeSortProperties();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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<TopLevelEntityTypeNames> {
export class TopLevelEntitySchemaTypes {
private entity: ConcreteEntity;
private filterSchemaTypes: TopLevelFilterSchemaTypes;
private schemaBuilder: SchemaBuilder;
private entityTypeNames: TopLevelEntityTypeNames;
private schemaTypes: SchemaTypes;

constructor({
entity,
Expand All @@ -54,13 +64,11 @@ export class TopLevelEntitySchemaTypes extends EntitySchemaTypes<TopLevelEntityT
entity: ConcreteEntity;
schemaTypes: SchemaTypes;
}) {
super({
schemaBuilder,
entityTypeNames: entity.typeNames,
schemaTypes,
});
this.entity = entity;
this.filterSchemaTypes = new TopLevelFilterSchemaTypes({ schemaBuilder, entity, schemaTypes });
this.schemaBuilder = schemaBuilder;
this.entityTypeNames = entity.typeNames;
this.schemaTypes = schemaTypes;
}

public addTopLevelQueryField(
Expand All @@ -81,7 +89,43 @@ export class TopLevelEntitySchemaTypes extends EntitySchemaTypes<TopLevelEntityT
});
}

protected get connectionSort(): InputTypeComposer {
public get connectionOperation(): ObjectTypeComposer {
return this.schemaBuilder.getOrCreateObjectType(this.entityTypeNames.connectionOperation, () => {
const args: {
first: ScalarTypeComposer;
after: ScalarTypeComposer;
sort?: ListComposer<NonNullComposer<InputTypeComposer>>;
} = {
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: {
Expand All @@ -91,7 +135,7 @@ export class TopLevelEntitySchemaTypes extends EntitySchemaTypes<TopLevelEntityT
});
}

protected get edge(): ObjectTypeComposer {
private get edge(): ObjectTypeComposer {
return this.schemaBuilder.getOrCreateObjectType(this.entityTypeNames.edge, () => {
return {
fields: {
Expand All @@ -102,7 +146,7 @@ export class TopLevelEntitySchemaTypes extends EntitySchemaTypes<TopLevelEntityT
});
}

protected get edgeSort(): InputTypeComposer {
private get edgeSort(): InputTypeComposer {
return this.schemaBuilder.getOrCreateInputType(this.entityTypeNames.edgeSort, () => {
return {
fields: {
Expand Down

0 comments on commit 0a417db

Please sign in to comment.