我希望我的实体上的必填布尔字段具有默认值
TRUE
。我已定义我的 #api-platform
属性,如下所示。
#[ApiResource(
attributes: ['security' => "is_granted('ROLE_USER')"],
graphql: [
'item_query' => ['security' => "is_granted('ROLE_USER') and object.owner == user"],
'collection_query' => ['security' => "is_granted('ROLE_ADMIN')"],
'delete' => ['security' => "is_granted('ROLE_DEVELOPER')"],
'update' => ['security' => "is_granted('ROLE_DEVELOPER')"],
'create' => [
'defaults' => ['active' => TRUE],
'security' => "is_granted('ROLE_DEVELOPER')"
]
]
)]
活动字段本身注释为
/**
* @ORM\Column(type="boolean", options={"default":true})
*/
private $active;
这确实在数据库模式中设置了默认值,但是 GraphQL 突变似乎仍然要求在请求中提供此属性。 当尝试创建一个没有指定
active
属性的新实体时,我收到以下错误。
... Field value.active of required type Boolean! was not provided.
设置默认值不应该是这样的。
/**
* @ORM\Column(type="boolean", options={"default":true})
*/
private bool $active = true;
当我向解析器或突变声明参数时,我使用了 defaultValue 选项。
#[ApiResource(
operations: [],
graphQlOperations: [
new Mutation(
resolver: MyMutationResolver::class,
args: [
'comment' => ['type' => 'String', 'defaultValue' => null],
],
name: 'operatioName'
)