drizzle-graphql-plus 0.8.23 → 0.8.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.cjs CHANGED
@@ -2424,8 +2424,21 @@ var generateTypeDefs = (tables, relations) => {
2424
2424
  const targetTableName = relationInfo.targetTableName;
2425
2425
  const targetTypeName = capitalize(targetTableName);
2426
2426
  if (isOne) {
2427
+ const relation = relationInfo.relation;
2428
+ const config = relation.config;
2429
+ let isNonNullable = false;
2430
+ if (config?.fields && config.fields.length > 0) {
2431
+ isNonNullable = config.fields.every((field) => {
2432
+ const fieldColumnName = field.name;
2433
+ const column = Object.values(tableInfo.columns).find(
2434
+ (col) => col.name === fieldColumnName
2435
+ );
2436
+ return column && column.notNull;
2437
+ });
2438
+ }
2439
+ const nullableModifier = isNonNullable ? "!" : "";
2427
2440
  fields.push(
2428
- ` ${relationName}(where: ${targetTypeName}Filters): ${targetTypeName}`
2441
+ ` ${relationName}(where: ${targetTypeName}Filters): ${targetTypeName}${nullableModifier}`
2429
2442
  );
2430
2443
  } else {
2431
2444
  fields.push(