Repository: Quramy/prisma-fabbrica
Pull request #16 (2022-11-22 15:27:54)

feat: Make `defaultData` optional if it can


Patch:
diff --git a/examples/example-prj/src/__generated__/fabbrica.ts b/examples/example-prj/src/__generated__/fabbrica.ts
index 627f53e..f806360 100644
--- a/examples/example-prj/src/__generated__/fabbrica.ts
+++ b/examples/example-prj/src/__generated__/fabbrica.ts
@@ -13,7 +13,7 @@ type UserFactoryDefineInput = {
     posts?: Prisma.PostCreateNestedManyWithoutAuthorInput;
 };
 type UserFactoryDefineOptions = {
-    defaultData: Resolver<UserFactoryDefineInput>;
+    defaultData?: Resolver<UserFactoryDefineInput>;
 };
 function autoGenrateUserScalarsOrEnums(): UserScalarOrEnumFields {
     return {
@@ -21,10 +21,10 @@ function autoGenrateUserScalarsOrEnums(): UserScalarOrEnumFields {
         name: scalarFieldValueGenerator.String({ modelName: "User", fieldName: "name", isId: false, isUnique: false })
     };
 }
-export function defineUserFactory({ defaultData: defaultDataResolver }: UserFactoryDefineOptions) {
+function defineUserFactoryInternal({ defaultData: defaultDataResolver }: UserFactoryDefineOptions) {
     const buildCreateInput = async (inputData: Partial<Prisma.UserCreateInput> = {}) => {
         const requiredScalarData = autoGenrateUserScalarsOrEnums();
-        const defaultData = await resolveValue(defaultDataResolver);
+        const defaultData = await resolveValue(defaultDataResolver ?? {});
         const defaultAssociations = {};
         const data: Prisma.UserCreateInput = { ...requiredScalarData, ...defaultData, ...defaultAssociations, ...inputData };
         return data;
@@ -39,6 +39,9 @@ export function defineUserFactory({ defaultData: defaultDataResolver }: UserFact
         create,
     };
 }
+export function defineUserFactory(args: UserFactoryDefineOptions = {}) {
+    return defineUserFactoryInternal(args);
+}
 type PostScalarOrEnumFields = {
     id: string;
     title: string;
@@ -64,12 +67,14 @@ function autoGenratePostScalarsOrEnums(): PostScalarOrEnumFields {
         title: scalarFieldValueGenerator.String({ modelName: "Post", fieldName: "title", isId: false, isUnique: false })
     };
 }
-export function definePostFactory({ defaultData: defaultDataResolver }: PostFactoryDefineOptions) {
+function definePostFactoryInternal({ defaultData: defaultDataResolver }: PostFactoryDefineOptions) {
     const buildCreateInput = async (inputData: Partial<Prisma.PostCreateInput> = {}) => {
         const requiredScalarData = autoGenratePostScalarsOrEnums();
-        const defaultData = await resolveValue(defaultDataResolver);
+        const defaultData = await resolveValue(defaultDataResolver ?? {});
         const defaultAssociations = {
-            author: isPostauthorFactory(defaultData.author) ? { create: await defaultData.author.buildCreateInput() } : defaultData.author
+            author: isPostauthorFactory(defaultData.author) ? {
+                create: await defaultData.author.buildCreateInput()
+            } : defaultData.author
         };
         const data: Prisma.PostCreateInput = { ...requiredScalarData, ...defaultData, ...defaultAssociations, ...inputData };
         return data;
@@ -84,3 +89,6 @@ export function definePostFactory({ defaultData: defaultDataResolver }: PostFact
         create,
     };
 }
+export function definePostFactory(args: PostFactoryDefineOptions) {
+    return definePostFactoryInternal(args);
+}
diff --git a/packages/prisma-fabbrica/src/templates/index.ts b/packages/prisma-fabbrica/src/templates/index.ts
index e02e6fc..baa610e 100644
--- a/packages/prisma-fabbrica/src/templates/index.ts
+++ b/packages/prisma-fabbrica/src/templates/index.ts
@@ -173,15 +173,24 @@ export const modelFactoryDefineInput = (modelName: string, inputType: DMMF.Input
     MODEL_FACTORY_DEFINE_INPUT: ast.createIdentifier(`${modelName}FactoryDefineInput`),
   });
 
-export const modelFactoryDefineOptions = (modelName: string) =>
-  template.statement<ts.TypeAliasDeclaration>`
-    type MODEL_FACTORY_DEFINE_OPTIONS = {
-      defaultData: Resolver<MODEL_FACTORY_DEFINE_INPUT>;
-    };
-  `({
-    MODEL_FACTORY_DEFINE_OPTIONS: ast.createIdentifier(`${modelName}FactoryDefineOptions`),
-    MODEL_FACTORY_DEFINE_INPUT: ast.createIdentifier(`${modelName}FactoryDefineInput`),
-  });
+export const modelFactoryDefineOptions = (modelName: string, isOpionalDefaultData: boolean) =>
+  isOpionalDefaultData
+    ? template.statement<ts.TypeAliasDeclaration>`
+        type MODEL_FACTORY_DEFINE_OPTIONS = {
+          defaultData?: Resolver<MODEL_FACTORY_DEFINE_INPUT>;
+        };
+      `({
+        MODEL_FACTORY_DEFINE_OPTIONS: ast.createIdentifier(`${modelName}FactoryDefineOptions`),
+        MODEL_FACTORY_DEFINE_INPUT: ast.createIdentifier(`${modelName}FactoryDefineInput`),
+      })
+    : template.statement<ts.TypeAliasDeclaration>`
+        type MODEL_FACTORY_DEFINE_OPTIONS = {
+          defaultData: Resolver<MODEL_FACTORY_DEFINE_INPUT>;
+        };
+      `({
+        MODEL_FACTORY_DEFINE_OPTIONS: ast.createIdentifier(`${modelName}FactoryDefineOptions`),
+        MODEL_FACTORY_DEFINE_INPUT: ast.createIdentifier(`${modelName}FactoryDefineInput`),
+      });
 
 export const isModelAssociationFactory = (fieldType: DMMF.SchemaArg, model: DMMF.Model) => {
   const targetModel = model.fields.find(f => f.name === fieldType.name)!;
@@ -234,16 +243,16 @@ export const autoGenrateModelScalarsOrEnums = (
     MODEL_SCALAR_OR_ENUM_FIELDS: ast.createIdentifier(`${modelName}ScalarOrEnumFields`),
   });
 
-export const defineModelFactory = (modelName: string, inputType: DMMF.InputType) =>
+export const defineModelFactoryInernal = (modelName: string, inputType: DMMF.InputType) =>
   template.statement<ts.FunctionDeclaration>`
-    export function DEFINE_MODEL_FACTORY({
+    function DEFINE_MODEL_FACTORY_INERNAL({
       defaultData: defaultDataResolver
     }: MODEL_FACTORY_DEFINE_OPTIONS) {
       const buildCreateInput = async (
         inputData: Partial<Prisma.MODEL_CREATE_INPUT> = {}
       ) => {
         const requiredScalarData = AUTO_GENRATE_MODEL_SCALARS_OR_ENUMS()
-        const defaultData= await resolveValue(defaultDataResolver);
+        const defaultData= await resolveValue(defaultDataResolver ?? {});
         const defaultAssociations = ${() =>
           ast.createObjectLiteralExpression(
             filterRequiredInputObjectTypeField(inputType).map(field =>
@@ -278,12 +287,33 @@ export const defineModelFactory = (modelName: string, inputType: DMMF.InputType)
     }
   `({
     MODEL_KEY: ast.createIdentifier(camelize(modelName)),
-    DEFINE_MODEL_FACTORY: ast.createIdentifier(`define${modelName}Factory`),
+    DEFINE_MODEL_FACTORY_INERNAL: ast.createIdentifier(`define${modelName}FactoryInternal`),
     MODEL_FACTORY_DEFINE_OPTIONS: ast.createIdentifier(`${modelName}FactoryDefineOptions`),
     MODEL_CREATE_INPUT: ast.createIdentifier(`${modelName}CreateInput`),
     AUTO_GENRATE_MODEL_SCALARS_OR_ENUMS: ast.createIdentifier(`autoGenrate${modelName}ScalarsOrEnums`),
   });
 
+export const defineModelFactory = (modelName: string, inputType: DMMF.InputType) =>
+  filterRequiredInputObjectTypeField(inputType).length
+    ? template.statement<ts.FunctionDeclaration>`
+        export function DEFINE_MODEL_FACTORY(args: MODEL_FACTORY_DEFINE_OPTIONS) {
+          return DEFINE_MODEL_FACTORY_INERNAL(args);
+        }
+      `({
+        DEFINE_MODEL_FACTORY: ast.createIdentifier(`define${modelName}Factory`),
+        DEFINE_MODEL_FACTORY_INERNAL: ast.createIdentifier(`define${modelName}FactoryInternal`),
+        MODEL_FACTORY_DEFINE_OPTIONS: ast.createIdentifier(`${modelName}FactoryDefineOptions`),
+      })
+    : template.statement<ts.FunctionDeclaration>`
+        export function DEFINE_MODEL_FACTORY(args: MODEL_FACTORY_DEFINE_OPTIONS = {}) {
+          return DEFINE_MODEL_FACTORY_INERNAL(args);
+        }
+      `({
+        DEFINE_MODEL_FACTORY: ast.createIdentifier(`define${modelName}Factory`),
+        DEFINE_MODEL_FACTORY_INERNAL: ast.createIdentifier(`define${modelName}FactoryInternal`),
+        MODEL_FACTORY_DEFINE_OPTIONS: ast.createIdentifier(`${modelName}FactoryDefineOptions`),
+      });
+
 export function getSourceFile({
   document,
   importSpecifierToPrismaClient,
@@ -310,11 +340,12 @@ export function getSourceFile({
           modelBelongsToRelationFactory(fieldType, model),
         ),
         modelFactoryDefineInput(model.name, createInputType),
-        modelFactoryDefineOptions(model.name),
+        modelFactoryDefineOptions(model.name, filterRequiredInputObjectTypeField(createInputType).length === 0),
         ...filterRequiredInputObjectTypeField(createInputType).map(fieldType =>
           isModelAssociationFactory(fieldType, model),
         ),
         autoGenrateModelScalarsOrEnums(model.name, createInputType, model, document.schema.enumTypes.model ?? []),
+        defineModelFactoryInernal(model.name, createInputType),
         defineModelFactory(model.name, createInputType),
       ]),
   ];


Test patch:
diff --git a/examples/example-prj/src/sample.test.ts b/examples/example-prj/src/sample.test.ts
index 2e357d2..7d2d3bd 100644
--- a/examples/example-prj/src/sample.test.ts
+++ b/examples/example-prj/src/sample.test.ts
@@ -1,8 +1,6 @@
 import { defineUserFactory, definePostFactory } from "./__generated__/fabbrica";
 
-const UserFactory = defineUserFactory({
-  defaultData: {},
-});
+const UserFactory = defineUserFactory();
 
 const PostFactory = definePostFactory({
   defaultData: {
diff --git a/packages/prisma-fabbrica/src/templates/__snapshots__/index.test.ts.snap b/packages/prisma-fabbrica/src/templates/__snapshots__/index.test.ts.snap
index f92ee4b..3da4b11 100644
--- a/packages/prisma-fabbrica/src/templates/__snapshots__/index.test.ts.snap
+++ b/packages/prisma-fabbrica/src/templates/__snapshots__/index.test.ts.snap
@@ -15,7 +15,7 @@ type UserFactoryDefineInput = {
     name?: string;
 };
 type UserFactoryDefineOptions = {
-    defaultData: Resolver<UserFactoryDefineInput>;
+    defaultData?: Resolver<UserFactoryDefineInput>;
 };
 function autoGenrateUserScalarsOrEnums(): UserScalarOrEnumFields {
     return {
@@ -23,10 +23,10 @@ function autoGenrateUserScalarsOrEnums(): UserScalarOrEnumFields {
         name: scalarFieldValueGenerator.String({ modelName: "User", fieldName: "name", isId: false, isUnique: false })
     };
 }
-export function defineUserFactory({ defaultData: defaultDataResolver }: UserFactoryDefineOptions) {
+function defineUserFactoryInternal({ defaultData: defaultDataResolver }: UserFactoryDefineOptions) {
     const buildCreateInput = async (inputData: Partial<Prisma.UserCreateInput> = {}) => {
         const requiredScalarData = autoGenrateUserScalarsOrEnums();
-        const defaultData = await resolveValue(defaultDataResolver);
+        const defaultData = await resolveValue(defaultDataResolver ?? {});
         const defaultAssociations = {};
         const data: Prisma.UserCreateInput = { ...requiredScalarData, ...defaultData, ...defaultAssociations, ...inputData };
         return data;
@@ -41,5 +41,8 @@ export function defineUserFactory({ defaultData: defaultDataResolver }: UserFact
         create,
     };
 }
+export function defineUserFactory(args: UserFactoryDefineOptions = {}) {
+    return defineUserFactoryInternal(args);
+}
 "
 `;
diff --git a/packages/ts-compile-testing/fixtures/enum-model/__generated__/fabbrica.ts b/packages/ts-compile-testing/fixtures/enum-model/__generated__/fabbrica.ts
index 98a7a9e..db4590c 100644
--- a/packages/ts-compile-testing/fixtures/enum-model/__generated__/fabbrica.ts
+++ b/packages/ts-compile-testing/fixtures/enum-model/__generated__/fabbrica.ts
@@ -15,7 +15,7 @@ type UserFactoryDefineInput = {
     roles?: Prisma.UserCreaterolesInput | Prisma.Enumerable<Role>;
 };
 type UserFactoryDefineOptions = {
-    defaultData: Resolver<UserFactoryDefineInput>;
+    defaultData?: Resolver<UserFactoryDefineInput>;
 };
 function autoGenrateUserScalarsOrEnums(): UserScalarOrEnumFields {
     return {
@@ -23,10 +23,10 @@ function autoGenrateUserScalarsOrEnums(): UserScalarOrEnumFields {
         role: "USER"
     };
 }
-export function defineUserFactory({ defaultData: defaultDataResolver }: UserFactoryDefineOptions) {
+function defineUserFactoryInternal({ defaultData: defaultDataResolver }: UserFactoryDefineOptions) {
     const buildCreateInput = async (inputData: Partial<Prisma.UserCreateInput> = {}) => {
         const requiredScalarData = autoGenrateUserScalarsOrEnums();
-        const defaultData = await resolveValue(defaultDataResolver);
+        const defaultData = await resolveValue(defaultDataResolver ?? {});
         const defaultAssociations = {};
         const data: Prisma.UserCreateInput = { ...requiredScalarData, ...defaultData, ...defaultAssociations, ...inputData };
         return data;
@@ -41,3 +41,6 @@ export function defineUserFactory({ defaultData: defaultDataResolver }: UserFact
         create,
     };
 }
+export function defineUserFactory(args: UserFactoryDefineOptions = {}) {
+    return defineUserFactoryInternal(args);
+}
diff --git a/packages/ts-compile-testing/fixtures/relations-many-to-many/__generated__/fabbrica.ts b/packages/ts-compile-testing/fixtures/relations-many-to-many/__generated__/fabbrica.ts
index 0cf2f3b..90c990a 100644
--- a/packages/ts-compile-testing/fixtures/relations-many-to-many/__generated__/fabbrica.ts
+++ b/packages/ts-compile-testing/fixtures/relations-many-to-many/__generated__/fabbrica.ts
@@ -13,7 +13,7 @@ type PostFactoryDefineInput = {
     categories?: Prisma.CategoryCreateNestedManyWithoutPostsInput;
 };
 type PostFactoryDefineOptions = {
-    defaultData: Resolver<PostFactoryDefineInput>;
+    defaultData?: Resolver<PostFactoryDefineInput>;
 };
 function autoGenratePostScalarsOrEnums(): PostScalarOrEnumFields {
     return {
@@ -21,10 +21,10 @@ function autoGenratePostScalarsOrEnums(): PostScalarOrEnumFields {
         title: scalarFieldValueGenerator.String({ modelName: "Post", fieldName: "title", isId: false, isUnique: false })
     };
 }
-export function definePostFactory({ defaultData: defaultDataResolver }: PostFactoryDefineOptions) {
+function definePostFactoryInternal({ defaultData: defaultDataResolver }: PostFactoryDefineOptions) {
     const buildCreateInput = async (inputData: Partial<Prisma.PostCreateInput> = {}) => {
         const requiredScalarData = autoGenratePostScalarsOrEnums();
-        const defaultData = await resolveValue(defaultDataResolver);
+        const defaultData = await resolveValue(defaultDataResolver ?? {});
         const defaultAssociations = {};
         const data: Prisma.PostCreateInput = { ...requiredScalarData, ...defaultData, ...defaultAssociations, ...inputData };
         return data;
@@ -39,6 +39,9 @@ export function definePostFactory({ defaultData: defaultDataResolver }: PostFact
         create,
     };
 }
+export function definePostFactory(args: PostFactoryDefineOptions = {}) {
+    return definePostFactoryInternal(args);
+}
 type CategoryScalarOrEnumFields = {
     id: string;
     name: string;
@@ -49,7 +52,7 @@ type CategoryFactoryDefineInput = {
     posts?: Prisma.PostCreateNestedManyWithoutCategoriesInput;
 };
 type CategoryFactoryDefineOptions = {
-    defaultData: Resolver<CategoryFactoryDefineInput>;
+    defaultData?: Resolver<CategoryFactoryDefineInput>;
 };
 function autoGenrateCategoryScalarsOrEnums(): CategoryScalarOrEnumFields {
     return {
@@ -57,10 +60,10 @@ function autoGenrateCategoryScalarsOrEnums(): CategoryScalarOrEnumFields {
         name: scalarFieldValueGenerator.String({ modelName: "Category", fieldName: "name", isId: false, isUnique: false })
     };
 }
-export function defineCategoryFactory({ defaultData: defaultDataResolver }: CategoryFactoryDefineOptions) {
+function defineCategoryFactoryInternal({ defaultData: defaultDataResolver }: CategoryFactoryDefineOptions) {
     const buildCreateInput = async (inputData: Partial<Prisma.CategoryCreateInput> = {}) => {
         const requiredScalarData = autoGenrateCategoryScalarsOrEnums();
-        const defaultData = await resolveValue(defaultDataResolver);
+        const defaultData = await resolveValue(defaultDataResolver ?? {});
         const defaultAssociations = {};
         const data: Prisma.CategoryCreateInput = { ...requiredScalarData, ...defaultData, ...defaultAssociations, ...inputData };
         return data;
@@ -75,3 +78,6 @@ export function defineCategoryFactory({ defaultData: defaultDataResolver }: Cate
         create,
     };
 }
+export function defineCategoryFactory(args: CategoryFactoryDefineOptions = {}) {
+    return defineCategoryFactoryInternal(args);
+}
diff --git a/packages/ts-compile-testing/fixtures/relations-many-to-many/sample.ts b/packages/ts-compile-testing/fixtures/relations-many-to-many/sample.ts
index 3a1fc50..04b714e 100644
--- a/packages/ts-compile-testing/fixtures/relations-many-to-many/sample.ts
+++ b/packages/ts-compile-testing/fixtures/relations-many-to-many/sample.ts
@@ -1,4 +1,4 @@
 import { defineCategoryFactory, definePostFactory } from "./__generated__/fabbrica";
 
-export const PostFactory = definePostFactory({ defaultData: {} });
-export const CategoryFactory = defineCategoryFactory({ defaultData: {} });
+export const PostFactory = definePostFactory();
+export const CategoryFactory = defineCategoryFactory();
diff --git a/packages/ts-compile-testing/fixtures/relations-one-to-many/__generated__/fabbrica.ts b/packages/ts-compile-testing/fixtures/relations-one-to-many/__generated__/fabbrica.ts
index f18eb3b..c1d6296 100644
--- a/packages/ts-compile-testing/fixtures/relations-one-to-many/__generated__/fabbrica.ts
+++ b/packages/ts-compile-testing/fixtures/relations-one-to-many/__generated__/fabbrica.ts
@@ -14,7 +14,7 @@ type UserFactoryDefineInput = {
     reviews?: Prisma.ReviewCreateNestedManyWithoutReviewerInput;
 };
 type UserFactoryDefineOptions = {
-    defaultData: Resolver<UserFactoryDefineInput>;
+    defaultData?: Resolver<UserFactoryDefineInput>;
 };
 function autoGenrateUserScalarsOrEnums(): UserScalarOrEnumFields {
     return {
@@ -22,10 +22,10 @@ function autoGenrateUserScalarsOrEnums(): UserScalarOrEnumFields {
         name: scalarFieldValueGenerator.String({ modelName: "User", fieldName: "name", isId: false, isUnique: false })
     };
 }
-export function defineUserFactory({ defaultData: defaultDataResolver }: UserFactoryDefineOptions) {
+function defineUserFactoryInternal({ defaultData: defaultDataResolver }: UserFactoryDefineOptions) {
     const buildCreateInput = async (inputData: Partial<Prisma.UserCreateInput> = {}) => {
         const requiredScalarData = autoGenrateUserScalarsOrEnums();
-        const defaultData = await resolveValue(defaultDataResolver);
+        const defaultData = await resolveValue(defaultDataResolver ?? {});
         const defaultAssociations = {};
         const data: Prisma.UserCreateInput = { ...requiredScalarData, ...defaultData, ...defaultAssociations, ...inputData };
         return data;
@@ -40,6 +40,9 @@ export function defineUserFactory({ defaultData: defaultDataResolver }: UserFact
         create,
     };
 }
+export function defineUserFactory(args: UserFactoryDefineOptions = {}) {
+    return defineUserFactoryInternal(args);
+}
 type PostScalarOrEnumFields = {
     id: string;
     title: string;
@@ -51,7 +54,7 @@ type PostFactoryDefineInput = {
     reviews?: Prisma.ReviewCreateNestedManyWithoutPostInput;
 };
 type PostFactoryDefineOptions = {
-    defaultData: Resolver<PostFactoryDefineInput>;
+    defaultData?: Resolver<PostFactoryDefineInput>;
 };
 function autoGenratePostScalarsOrEnums(): PostScalarOrEnumFields {
     return {
@@ -59,10 +62,10 @@ function autoGenratePostScalarsOrEnums(): PostScalarOrEnumFields {
         title: scalarFieldValueGenerator.String({ modelName: "Post", fieldName: "title", isId: false, isUnique: false })
     };
 }
-export function definePostFactory({ defaultData: defaultDataResolver }: PostFactoryDefineOptions) {
+function definePostFactoryInternal({ defaultData: defaultDataResolver }: PostFactoryDefineOptions) {
     const buildCreateInput = async (inputData: Partial<Prisma.PostCreateInput> = {}) => {
         const requiredScalarData = autoGenratePostScalarsOrEnums();
-        const defaultData = await resolveValue(defaultDataResolver);
+        const defaultData = await resolveValue(defaultDataResolver ?? {});
         const defaultAssociations = {};
         const data: Prisma.PostCreateInput = { ...requiredScalarData, ...defaultData, ...defaultAssociations, ...inputData };
         return data;
@@ -77,6 +80,9 @@ export function definePostFactory({ defaultData: defaultDataResolver }: PostFact
         create,
     };
 }
+export function definePostFactory(args: PostFactoryDefineOptions = {}) {
+    return definePostFactoryInternal(args);
+}
 type ReviewScalarOrEnumFields = {
     id: string;
     body: string;
@@ -110,13 +116,17 @@ function autoGenrateReviewScalarsOrEnums(): ReviewScalarOrEnumFields {
         body: scalarFieldValueGenerator.String({ modelName: "Review", fieldName: "body", isId: false, isUnique: false })
     };
 }
-export function defineReviewFactory({ defaultData: defaultDataResolver }: ReviewFactoryDefineOptions) {
+function defineReviewFactoryInternal({ defaultData: defaultDataResolver }: ReviewFactoryDefineOptions) {
     const buildCreateInput = async (inputData: Partial<Prisma.ReviewCreateInput> = {}) => {
         const requiredScalarData = autoGenrateReviewScalarsOrEnums();
-        const defaultData = await resolveValue(defaultDataResolver);
+        const defaultData = await resolveValue(defaultDataResolver ?? {});
         const defaultAssociations = {
-            post: isReviewpostFactory(defaultData.post) ? { create: await defaultData.post.buildCreateInput() } : defaultData.post,
-            reviewer: isReviewreviewerFactory(defaultData.reviewer) ? { create: await defaultData.reviewer.buildCreateInput() } : defaultData.reviewer
+            post: isReviewpostFactory(defaultData.post) ? {
+                create: await defaultData.post.buildCreateInput()
+            } : defaultData.post,
+            reviewer: isReviewreviewerFactory(defaultData.reviewer) ? {
+                create: await defaultData.reviewer.buildCreateInput()
+            } : defaultData.reviewer
         };
         const data: Prisma.ReviewCreateInput = { ...requiredScalarData, ...defaultData, ...defaultAssociations, ...inputData };
         return data;
@@ -131,3 +141,6 @@ export function defineReviewFactory({ defaultData: defaultDataResolver }: Review
         create,
     };
 }
+export function defineReviewFactory(args: ReviewFactoryDefineOptions) {
+    return defineReviewFactoryInternal(args);
+}
diff --git a/packages/ts-compile-testing/fixtures/relations-one-to-many/sample.ts b/packages/ts-compile-testing/fixtures/relations-one-to-many/sample.ts
index e6e7cd3..944e5e3 100644
--- a/packages/ts-compile-testing/fixtures/relations-one-to-many/sample.ts
+++ b/packages/ts-compile-testing/fixtures/relations-one-to-many/sample.ts
@@ -1,7 +1,7 @@
 import { definePostFactory, defineUserFactory, defineReviewFactory } from "./__generated__/fabbrica";
 
-export const UserFactory = defineUserFactory({ defaultData: {} });
-export const PostFactory = definePostFactory({ defaultData: {} });
+export const UserFactory = defineUserFactory();
+export const PostFactory = definePostFactory();
 export const ReviewFactory = defineReviewFactory({
   defaultData: {
     post: PostFactory,
diff --git a/packages/ts-compile-testing/fixtures/relations-one-to-one/__generated__/fabbrica.ts b/packages/ts-compile-testing/fixtures/relations-one-to-one/__generated__/fabbrica.ts
index 7fc9dad..c58eace 100644
--- a/packages/ts-compile-testing/fixtures/relations-one-to-one/__generated__/fabbrica.ts
+++ b/packages/ts-compile-testing/fixtures/relations-one-to-one/__generated__/fabbrica.ts
@@ -13,7 +13,7 @@ type UserFactoryDefineInput = {
     profile?: Prisma.ProfileCreateNestedOneWithoutUserInput;
 };
 type UserFactoryDefineOptions = {
-    defaultData: Resolver<UserFactoryDefineInput>;
+    defaultData?: Resolver<UserFactoryDefineInput>;
 };
 function autoGenrateUserScalarsOrEnums(): UserScalarOrEnumFields {
     return {
@@ -21,10 +21,10 @@ function autoGenrateUserScalarsOrEnums(): UserScalarOrEnumFields {
         name: scalarFieldValueGenerator.String({ modelName: "User", fieldName: "name", isId: false, isUnique: false })
     };
 }
-export function defineUserFactory({ defaultData: defaultDataResolver }: UserFactoryDefineOptions) {
+function defineUserFactoryInternal({ defaultData: defaultDataResolver }: UserFactoryDefineOptions) {
     const buildCreateInput = async (inputData: Partial<Prisma.UserCreateInput> = {}) => {
         const requiredScalarData = autoGenrateUserScalarsOrEnums();
-        const defaultData = await resolveValue(defaultDataResolver);
+        const defaultData = await resolveValue(defaultDataResolver ?? {});
         const defaultAssociations = {};
         const data: Prisma.UserCreateInput = { ...requiredScalarData, ...defaultData, ...defaultAssociations, ...inputData };
         return data;
@@ -39,6 +39,9 @@ export function defineUserFactory({ defaultData: defaultDataResolver }: UserFact
         create,
     };
 }
+export function defineUserFactory(args: UserFactoryDefineOptions = {}) {
+    return defineUserFactoryInternal(args);
+}
 type ProfileScalarOrEnumFields = {
     id: string;
 };
@@ -61,12 +64,14 @@ function autoGenrateProfileScalarsOrEnums(): ProfileScalarOrEnumFields {
         id: scalarFieldValueGenerator.String({ modelName: "Profile", fieldName: "id", isId: true, isUnique: false })
     };
 }
-export function defineProfileFactory({ defaultData: defaultDataResolver }: ProfileFactoryDefineOptions) {
+function defineProfileFactoryInternal({ defaultData: defaultDataResolver }: ProfileFactoryDefineOptions) {
     const buildCreateInput = async (inputData: Partial<Prisma.ProfileCreateInput> = {}) => {
         const requiredScalarData = autoGenrateProfileScalarsOrEnums();
-        const defaultData = await resolveValue(defaultDataResolver);
+        const defaultData = await resolveValue(defaultDataResolver ?? {});
         const defaultAssociations = {
-            user: isProfileuserFactory(defaultData.user) ? { create: await defaultData.user.buildCreateInput() } : defaultData.user
+            user: isProfileuserFactory(defaultData.user) ? {
+                create: await defaultData.user.buildCreateInput()
+            } : defaultData.user
         };
         const data: Prisma.ProfileCreateInput = { ...requiredScalarData, ...defaultData, ...defaultAssociations, ...inputData };
         return data;
@@ -81,3 +86,6 @@ export function defineProfileFactory({ defaultData: defaultDataResolver }: Profi
         create,
     };
 }
+export function defineProfileFactory(args: ProfileFactoryDefineOptions) {
+    return defineProfileFactoryInternal(args);
+}
diff --git a/packages/ts-compile-testing/fixtures/relations-one-to-one/sample.ts b/packages/ts-compile-testing/fixtures/relations-one-to-one/sample.ts
index 928e2f4..104f1be 100644
--- a/packages/ts-compile-testing/fixtures/relations-one-to-one/sample.ts
+++ b/packages/ts-compile-testing/fixtures/relations-one-to-one/sample.ts
@@ -1,4 +1,4 @@
 import { defineUserFactory, defineProfileFactory } from "./__generated__/fabbrica";
 
-export const UserFactory = defineUserFactory({ defaultData: {} });
+export const UserFactory = defineUserFactory();
 export const ProfileFactory = defineProfileFactory({ defaultData: { user: UserFactory } });
diff --git a/packages/ts-compile-testing/fixtures/simple-model/__generated__/fabbrica.ts b/packages/ts-compile-testing/fixtures/simple-model/__generated__/fabbrica.ts
index 9877cd2..fb1439b 100644
--- a/packages/ts-compile-testing/fixtures/simple-model/__generated__/fabbrica.ts
+++ b/packages/ts-compile-testing/fixtures/simple-model/__generated__/fabbrica.ts
@@ -12,7 +12,7 @@ type UserFactoryDefineInput = {
     name?: string;
 };
 type UserFactoryDefineOptions = {
-    defaultData: Resolver<UserFactoryDefineInput>;
+    defaultData?: Resolver<UserFactoryDefineInput>;
 };
 function autoGenrateUserScalarsOrEnums(): UserScalarOrEnumFields {
     return {
@@ -20,10 +20,10 @@ function autoGenrateUserScalarsOrEnums(): UserScalarOrEnumFields {
         name: scalarFieldValueGenerator.String({ modelName: "User", fieldName: "name", isId: false, isUnique: false })
     };
 }
-export function defineUserFactory({ defaultData: defaultDataResolver }: UserFactoryDefineOptions) {
+function defineUserFactoryInternal({ defaultData: defaultDataResolver }: UserFactoryDefineOptions) {
     const buildCreateInput = async (inputData: Partial<Prisma.UserCreateInput> = {}) => {
         const requiredScalarData = autoGenrateUserScalarsOrEnums();
-        const defaultData = await resolveValue(defaultDataResolver);
+        const defaultData = await resolveValue(defaultDataResolver ?? {});
         const defaultAssociations = {};
         const data: Prisma.UserCreateInput = { ...requiredScalarData, ...defaultData, ...defaultAssociations, ...inputData };
         return data;
@@ -38,3 +38,6 @@ export function defineUserFactory({ defaultData: defaultDataResolver }: UserFact
         create,
     };
 }
+export function defineUserFactory(args: UserFactoryDefineOptions = {}) {
+    return defineUserFactoryInternal(args);
+}