@Resolver()
export class NameCardCreateResolver {
@Mutation(() => BaseMutationResponse)
async namecardCreate(
@Arg("chosenSNSUrls", () => SNSInput)
{ facebook, twitter, instagram, blog, youtube }: SNSInput,
@Arg("owner", () => NameCardOwner)
{ ownerEmail }: NameCardOwner
): Promise<BaseMutationResponse> {
const response = new BaseMutationResponse();
try {
await NameCardModel.create({
sns: {
facebook,
twitter,
instagram,
blog,
youtube
},
owner: {
email: ownerEmail,
},
and also defined the SNSINPUT type as shown below:
@InputType()
export class SNSInput {
@Field({ nullable: true, defaultValue: null })
facebook?: string;
@Field({ nullable: true, defaultValue: null })
instagram?: string;
@Field({ nullable: true, defaultValue: null })
youtube?: string;
@Field({ nullable: true, defaultValue: null })
blog?: string;
@Field({ nullable: true, defaultValue: null })
twitter?: string;
}
although it works well, I noticed that in my MongoDB field, unnecessary null values are still being created.
How can I prevent these unnecessary null processed sns fields from being created?