From 5a5c95f8824f4a9a0207d44fc59c0bfba06a529d Mon Sep 17 00:00:00 2001 From: Sonarly Claude Code Date: Sun, 15 Mar 2026 21:00:49 +0000 Subject: [PATCH] fix: respect isNullable for relation FK scalar in create input type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://sonarly.com/issue/14908?type=bug The GraphQL create input for relation FK scalars (like `messageId`) is always generated as nullable, allowing records to be created without required foreign keys. The response serialization then fails because the output type correctly marks `messageId` as non-nullable. Fix: Removed the `nullable: true` override in `generateSimpleRelationFieldCreateOrUpdateInputType` so the FK scalar field (e.g. `messageId`) respects the actual `isNullable` from field metadata. Commit `ef003fb929f` ("fix blocklist #18332") intended to make only the **connect relation input** optional (since you provide either FK or connect, not both), but accidentally also made the **FK scalar** always optional by overriding `nullable: true`. This let users create records like MessageParticipant without required foreign keys (messageId), which then crashed on response serialization. The fix passes `typeOptions` unchanged to `applyTypeOptionsForCreateInput` for the FK scalar. When `isNullable: false` (like `message` → `messageId`), the field correctly becomes `GraphQLNonNull` in the create input. When `isNullable: true` (like `person` → `personId`), it stays optional. The connect relation input (`generateConnectRelationFieldInputType`) is untouched and correctly remains always nullable. --- .../relation-field-metadata-gql-type.generator.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/twenty-server/src/engine/api/graphql/workspace-schema-builder/graphql-type-generators/input-types/relation-field-metadata-gql-type.generator.ts b/packages/twenty-server/src/engine/api/graphql/workspace-schema-builder/graphql-type-generators/input-types/relation-field-metadata-gql-type.generator.ts index 51f7bc284f9..6b470247075 100644 --- a/packages/twenty-server/src/engine/api/graphql/workspace-schema-builder/graphql-type-generators/input-types/relation-field-metadata-gql-type.generator.ts +++ b/packages/twenty-server/src/engine/api/graphql/workspace-schema-builder/graphql-type-generators/input-types/relation-field-metadata-gql-type.generator.ts @@ -62,10 +62,7 @@ export class RelationFieldMetadataGqlInputTypeGenerator { throw new Error(message); } - const modifiedType = applyTypeOptionsForCreateInput(type, { - ...typeOptions, - nullable: true, - }); + const modifiedType = applyTypeOptionsForCreateInput(type, typeOptions); return { [joinColumnName]: {