【发布时间】:2022-02-19 21:37:34
【问题描述】:
// image.entity.ts
import { Field, ObjectType } from '@nestjs/graphql';
import {
Column,
DeleteDateColumn,
Entity,
PrimaryGeneratedColumn,
} from 'typeorm';
@ObjectType()
@Entity()
export class ImageEntity {
@PrimaryGeneratedColumn('uuid')
@Field(() => String)
id: string;
@Column({ default: false })
@Field(() => Boolean, { defaultValue: false })
isThumbnail: boolean;
//isThumbnail?: boolean; // it worked without question mark
}
//image.resolver.ts
import { Args, Mutation, Query, Resolver } from '@nestjs/graphql';
import { ImageEntity } from './entities/image.entity';
import { ImageService } from './image.service';
@Resolver()
export class ImageResolver {
constructor(private readonly imageService: ImageService) {}
@Mutation(() => ImageEntity)
async createImage(
@Args('imageUrl') imageUrl: string,
//=============this part=================
@Args('isThumbnail', { nullable: true }) isThumbnail?: boolean, // <--- that question mark I'm takin bout
// @Args('isThumbnail', { nullable: true }) isThumbnail: boolean, // it work fine without the question mark
// what this thing for?
//========================================
) {
return await this.imageService.create({ isThumbnail, imageUrl });
}
}
就像代码一样,它与 TypeORM 和 GraphQL 相关联。并且一些 args(也是相关列)可以为空。
我知道 {nullable : true} 使 GraphQL 和 TypeORM 的 args 和列都可以在没有问号的情况下使用。它工作得很好,但是在nestjs doc上,问号就在
的正下方@Field(()=>某些类型,{nullable: true}。
我的问题是问号只是表示它作为打字稿类型是可选的?
【问题讨论】:
标签: typescript graphql