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.js CHANGED
@@ -2479,8 +2479,21 @@ var generateTypeDefs = (tables, relations) => {
2479
2479
  const targetTableName = relationInfo.targetTableName;
2480
2480
  const targetTypeName = capitalize(targetTableName);
2481
2481
  if (isOne) {
2482
+ const relation = relationInfo.relation;
2483
+ const config = relation.config;
2484
+ let isNonNullable = false;
2485
+ if (config?.fields && config.fields.length > 0) {
2486
+ isNonNullable = config.fields.every((field) => {
2487
+ const fieldColumnName = field.name;
2488
+ const column = Object.values(tableInfo.columns).find(
2489
+ (col) => col.name === fieldColumnName
2490
+ );
2491
+ return column && column.notNull;
2492
+ });
2493
+ }
2494
+ const nullableModifier = isNonNullable ? "!" : "";
2482
2495
  fields.push(
2483
- ` ${relationName}(where: ${targetTypeName}Filters): ${targetTypeName}`
2496
+ ` ${relationName}(where: ${targetTypeName}Filters): ${targetTypeName}${nullableModifier}`
2484
2497
  );
2485
2498
  } else {
2486
2499
  fields.push(