【发布时间】:2021-12-17 13:14:17
【问题描述】:
@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,
},
还有SNSINPUT类型,,
@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;
}
它运作良好,但它是在我的 MongoDB 领域中创建的。
如何防止创建不必要的 null 处理 sns 字段?
【问题讨论】:
标签: typescript mongodb graphql resolver typegraphql