Graphql 不能为不可为空的字段返回空值

时间:2021-07-30 05:45:27

标签: node.js graphql

使用 GraphQL,我需要字段 globalConfig 至少返回空值。这是我对该领域的变异和声明。它可以为空,默认值:null。为什么它给我那个错误? "message": "不能为非空字段 Customer.globalConfig 返回空值。"?为什么 globalConfig 不可为空?

  createOneCustomer(input: { customer: { 
    uid: "", 
    login: "asSSfSSd", 
    name: ""
  }}) { 
    _id, 
    uid, 
    login, 
    permission, 
    name,
    globalConfig {
      _id
    }
  } 
}

export default class CustomerInputDTO {
  @IsString()
  @Field({ nullable: true })
  uid: string;

  @IsString()
  @Field()
  login: string;

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

  @Field(() => ID, { nullable: true, defaultValue: null })
  globalConfig: string;
}

@Prop({ type: SchemaTypes.ObjectId, ref: 'GlobalConfig', required: false })
globalConfig?: Types.ObjectId | null

0 个答案:

没有答案