diff --git a/node/codegen.go b/node/codegen.go index 3d79135cb..6294ab2c6 100644 --- a/node/codegen.go +++ b/node/codegen.go @@ -273,13 +273,16 @@ func writeWhereConditionsInterface(w *codegen.Writer, model *proto.Model) { w.Write(": ") if field.Type.Type == proto.Type_TYPE_MODEL { // Embed related models where conditions - w.Writef("%sWhereConditions | null;", field.Type.ModelName.Value) + w.Writef("%sWhereConditions", field.Type.ModelName.Value) } else { w.Write(toTypeScriptType(field.Type, false)) w.Write(" | ") w.Write(toWhereConditionType(field)) - w.Write(" | null;") } + if field.Optional { + w.Write(" | null") + } + w.Write(";") w.Writeln("") } diff --git a/node/codegen_test.go b/node/codegen_test.go index 00456a67d..9e5f55604 100644 --- a/node/codegen_test.go +++ b/node/codegen_test.go @@ -126,15 +126,15 @@ export interface PostCreateValues { func TestWriteWhereConditionsInterface(t *testing.T) { expected := ` export interface PersonWhereConditions { - firstName?: string | runtime.StringWhereCondition | null; + firstName?: string | runtime.StringWhereCondition; lastName?: string | runtime.StringWhereCondition | null; - age?: number | runtime.NumberWhereCondition | null; - dateOfBirth?: Date | runtime.DateWhereCondition | null; - gender?: Gender | GenderWhereCondition | null; - hasChildren?: boolean | runtime.BooleanWhereCondition | null; - id?: string | runtime.IDWhereCondition | null; - createdAt?: Date | runtime.DateWhereCondition | null; - updatedAt?: Date | runtime.DateWhereCondition | null; + age?: number | runtime.NumberWhereCondition; + dateOfBirth?: Date | runtime.DateWhereCondition; + gender?: Gender | GenderWhereCondition; + hasChildren?: boolean | runtime.BooleanWhereCondition; + id?: string | runtime.IDWhereCondition; + createdAt?: Date | runtime.DateWhereCondition; + updatedAt?: Date | runtime.DateWhereCondition; }` runWriterTest(t, testSchema, expected, func(s *proto.Schema, w *codegen.Writer) { m := proto.FindModel(s.Models, "Person")