craftcms / cms

Build bespoke content experiences with Craft.
https://craftcms.com
Other
3.2k stars 617 forks source link

[5.x]: GraphQL type name collision #15269

Closed AugustMiller closed 1 day ago

AugustMiller commented 4 days ago

What happened?

When GraphQL mutation names are generated for nested entries and sections, a collision is possible for _Drafts.

Mutations for Matrix field entry drafts omit the Field segment, meaning they will receive the same name as the mutation for drafts in a section that shares a handle with the field.

https://github.com/craftcms/cms/blob/5.x/src/gql/mutations/Entry.php#L285

Steps to Reproduce

  1. Create an entry type named Stop (with handle stop);
  2. Create a section named Tours (with handle tours) and an entry type named Tour (with handle tour) — the naming here is immaterial and doesn’t contribute to the bug… we just need a place to stick the field, semantically;
  3. Create a Matrix field named Stops that uses the Stop entry type, and attach it to the Tour entry type’s field layout;
  4. Create a section named Stops (also with handle stops) that uses the Stop entry type;

(This last step is contrived—most developers are probably not creating deliberately ambiguous content types like this!)

The resulting GraphQL schema would produce these four mutations:

The second and third _Draft type names are the same! Currently, Craft appears to only acknowledge the latter (or… whichever one is created second?)

Craft CMS version

5.0.0+

PHP version

No response

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

No response

brandonkelly commented 1 day ago

Fixed for 5.3 (8fdd6e0608f6b1fd9789e43ee2f477fef968ca03).