为什么nestjs生成的GraphQL的SDL,使得可为空的字段成为必需的?

问题描述 投票:0回答:0

我正在使用代码优先方法进行开发 Nestjs 生成的模式忽略了另一个对象类型的 nullable: true

// user.entity.ts
@ObjectType()
export class UserObjectType implements User {
  @Field()
  id: string;

  @Field({ nullable: true})
  name: string;

 @Field(type => UserServicesObjectType, { 
    nullable: true, // 👈 here i declare as nullable
 })
  services: UserServicesObjectType | null;
}
// schema.gql (autogenerated)
type UserObjectType {
  id: String!
  name: String
services: UserServicesObjectType! // 👈 but the schema is generated as no-null
}

我预计会是这样

// schema.gql (autogenerated)
type UserObjectType {
  id: String!
  name: String
services: UserServicesObjectType // 👈 I expected to be nullable (without the !)
}
graphql nestjs apollo-server
© www.soinside.com 2019 - 2024. All rights reserved.