From ad7f10ebcf9ca1704abe16a5a0ea83d4d7e31ada Mon Sep 17 00:00:00 2001 From: angrykoala Date: Fri, 10 May 2024 14:57:37 +0100 Subject: [PATCH] Fix scalar fields in relationships --- .../api-v6/schema/schema-types/NestedEntityTypes.ts | 12 ++++++++---- .../integration/directives/alias/query.int.test.ts | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/graphql/src/api-v6/schema/schema-types/NestedEntityTypes.ts b/packages/graphql/src/api-v6/schema/schema-types/NestedEntityTypes.ts index d1114fdccd..27e7b5ab09 100644 --- a/packages/graphql/src/api-v6/schema/schema-types/NestedEntityTypes.ts +++ b/packages/graphql/src/api-v6/schema/schema-types/NestedEntityTypes.ts @@ -20,10 +20,12 @@ import type { InputTypeComposer, ListComposer, NonNullComposer, ObjectTypeComposer } from "graphql-compose"; import { Memoize } from "typescript-memoize"; import type { Attribute } from "../../../schema-model/attribute/Attribute"; +import { AttributeAdapter } from "../../../schema-model/attribute/model-adapters/AttributeAdapter"; import { ConcreteEntity } from "../../../schema-model/entity/ConcreteEntity"; import type { Relationship } from "../../../schema-model/relationship/Relationship"; +import { attributeAdapterToComposeFields } from "../../../schema/to-compose"; import type { NestedEntityTypeNames } from "../../graphQLTypeNames/NestedEntityTypeNames"; -import type { SchemaBuilder } from "../SchemaBuilder"; +import type { FieldDefinition, SchemaBuilder } from "../SchemaBuilder"; import { EntityTypes } from "./EntityTypes"; import type { StaticTypes } from "./StaticTypes"; @@ -71,9 +73,11 @@ export class NestedEntitySchemaTypes extends EntityTypes protected getConnectionArgs(): { sort?: ListComposer> | undefined } { return {}; } - private getRelationshipFields(): Record { - return Object.fromEntries( - [...this.relationship.attributes.values()].map((attribute) => [attribute.name, attribute.type.name]) + private getRelationshipFields(): Record { + const entityAttributes = [...this.relationship.attributes.values()].map( + (attribute) => new AttributeAdapter(attribute) ); + + return attributeAdapterToComposeFields(entityAttributes, new Map()) as Record; } } diff --git a/packages/graphql/tests/api-v6/integration/directives/alias/query.int.test.ts b/packages/graphql/tests/api-v6/integration/directives/alias/query.int.test.ts index ddd7792106..5fd1d583c6 100644 --- a/packages/graphql/tests/api-v6/integration/directives/alias/query.int.test.ts +++ b/packages/graphql/tests/api-v6/integration/directives/alias/query.int.test.ts @@ -98,8 +98,8 @@ describe("@alias directive", () => { }, }); }); - // this test fail, I believe is because the numeric resolver was not added on the relationship properties - test.skip("Query node and relationship with alias", async () => { + + test("Query node and relationship with alias", async () => { const query = /* GraphQL */ ` query { ${Movie.plural} {