Compare commits

...
Author SHA1 Message Date
Sonarly Claude Code 5a5c95f882 fix: respect isNullable for relation FK scalar in create input type
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.
2026-03-15 21:00:49 +00:00
@@ -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]: {