core
core copied to clipboard
The disable_type_enforcement option is ignored (custom GraphQl mutation name's)
API Platform version(s) affected: v2.7.0-alpha.1
Description
The disable_type_enforcement option is ignored if a custom GraphQl mutation name is used
How to reproduce
#[ApiResource(
normalizationContext: ['groups' => ['read_normalization']]
)]
#[Mutation(
denormalizationContext: ['groups' => ['update_denormalization'], 'disable_type_enforcement' => true]
name: 'update'
)]
#[Mutation(
denormalizationContext: ['groups' => ['update_denormalization'], 'disable_type_enforcement' => true]
name: 'update2'
)]
class Domain
{
#[ORM\Column(type: "string", length: 255, nullable: false)]
#[Groups(['update_denormalization', 'read_normalization'])]
private ?string $apiToken = null;
#[ORM\Column(type: "boolean")]
#[Groups(['update_denormalization', 'read_normalization'])]
private bool $isActive = false;
// ...
}
{
"input": {
"id": "/api/domains/1",
"apiToken": null,
"isActive": false
}
}
When trying to run the "update2Domain" mutation, an error occurs:
{
"errors": [
{
"message": "Variable \"$input\" got invalid value {\"id\":\"\\/api\\/domains\\/1\",\"apiToken\":null,\"isActive\":false}; Expected non-nullable type String! not to be null at value.apiToken.",
"extensions": {
"category": "graphql"
},
"locations": [
{
"line": 1,
"column": 24
}
]
}
]
}
Schema generated incorrectly ("Boolean!" instead of "Boolean")
"""Updates a Domain."""
input updateDomainInput {
id: ID!
isActive: Boolean
clientMutationId: String
}
"""Update2s a Domain."""
input update2DomainInput {
id: ID!
isActive: Boolean!
clientMutationId: String
}
https://s20.directupload.net/images/220421/jakshend.png https://s20.directupload.net/images/220421/a32pgt3l.png
Possible Solution
...
Additional Context
https://github.com/api-platform/core/blob/39b4e43dff9463b13477cc64a760797978d052e8/src/Serializer/AbstractItemNormalizer.php#L1009
hi, I checked the context at https://github.com/api-platform/core/blob/main/src/GraphQl/Resolver/Stage/DeserializeStage.php#L51 and I do have the disable_type_enforcement if specified. Are you sure you removed the cache?
Yes, I cleared the cache, but the problem is still there.
I have added a repository to demonstrate this error: https://github.com/lermontex/api-platform-bug-example
I checked version v2.7.0-beta.4 - the bug is still there
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This bug is targeting 2.7, as API Platform 3.2 is out, version 2.7 has reached end of life. Therefore we'll close this issue.
We recommend to upgrade to API Platform 3.0, Les-Tilleuls.coop can offer paid support to help or even migrate your projects if they have tests.
We want to fund a Long Term Stable version of API Platform, if you or your organization would like to contribute to LTS support, please visit our Open Collective crowdfunding.