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.
This commit is contained in:
+1
-4
@@ -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]: {
|
||||
|
||||
Reference in New Issue
Block a user