core icon indicating copy to clipboard operation
core copied to clipboard

The disable_type_enforcement option is ignored (custom GraphQl mutation name's)

Open lermontex opened this issue 3 years ago • 3 comments

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

lermontex avatar Apr 21 '22 17:04 lermontex

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?

soyuka avatar Apr 22 '22 12:04 soyuka

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

lermontex avatar Apr 24 '22 01:04 lermontex

I checked version v2.7.0-beta.4 - the bug is still there

lermontex avatar Jul 12 '22 14:07 lermontex

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.

stale[bot] avatar Nov 04 '22 21:11 stale[bot]

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.

soyuka avatar Oct 17 '23 09:10 soyuka