Skip to content

Fix GraphQL error when duplicating M2A items with same name fields of conflicting types.#26367

Merged
AlexGaillard merged 10 commits intodirectus:mainfrom
dstockton:fix/m2a-duplication-graphql-error
Jan 14, 2026
Merged

Fix GraphQL error when duplicating M2A items with same name fields of conflicting types.#26367
AlexGaillard merged 10 commits intodirectus:mainfrom
dstockton:fix/m2a-duplication-graphql-error

Conversation

@dstockton
Copy link
Contributor

Scope

What's changed:

  • Modified getGraphqlQueryFields to return aliased field names for M2A inline fragments, preventing GraphQL validation errors when collections have fields with the same name but different types
  • Added transformM2AAliases helper function to transform aliased response data back to original field names
  • Updated saveAsCopy to use the new alias mapping and transformation

Potential Risks / Drawbacks

  • Field names in M2A inline fragments are now aliased with collection prefix (e.g., child1__items instead of items), but this is transparent to users as the response is transformed back before use
  • Minimal risk as the change is isolated to the item duplication flow

Tested Scenarios

  • Duplicating items with M2A fields linking to collections with same-named fields of different types (JSON vs relation)
  • Verified generated GraphQL query contains proper aliases (child1__items: items)
  • Verified response transformation correctly restores original field names

Review Notes / Questions

Checklist

  • Added or updated tests
  • Documentation PR created here or not required
  • OpenAPI package PR created here or not required

Fixes #25476

@dstockton dstockton force-pushed the fix/m2a-duplication-graphql-error branch from ba52f20 to 05c8976 Compare December 16, 2025 19:59
@dstockton dstockton requested a review from gaetansenn December 16, 2025 20:08
@dstockton dstockton requested a review from gaetansenn December 17, 2025 22:57
@dstockton dstockton force-pushed the fix/m2a-duplication-graphql-error branch from 2800b73 to 6f73816 Compare December 18, 2025 22:20
@dstockton dstockton requested a review from gaetansenn December 19, 2025 09:13
…h M2A fields (directus#25476)

Use field aliases in GraphQL queries for M2A inline fragments to prevent
conflicts when different collections have fields with the same name but
different types. The aliased response data is transformed back to original
field names before creating the duplicated item.
@dstockton dstockton force-pushed the fix/m2a-duplication-graphql-error branch from 65f3e56 to 6a23acc Compare December 19, 2025 23:12
@dstockton dstockton requested a review from gaetansenn December 19, 2025 23:14
@dstockton dstockton requested a review from formfcw December 29, 2025 09:14
@formfcw formfcw removed their request for review January 9, 2026 08:15
Copy link
Contributor

@gaetansenn gaetansenn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM ! Thank you for the great work you did on this PR ❤️

@ComfortablyCoding ComfortablyCoding changed the title fix(app): resolve GraphQL validation error when duplicating items with M2A fields (#25476) Fix GraphQL error when duplicating M2A items with same name fields of conflicting types. Jan 13, 2026
Copy link
Member

@AlexGaillard AlexGaillard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🆒 🫘

@AlexGaillard AlexGaillard merged commit f24a391 into directus:main Jan 14, 2026
73 checks passed
@github-actions github-actions bot added this to the Next Release milestone Jan 14, 2026
@dstockton dstockton deleted the fix/m2a-duplication-graphql-error branch February 11, 2026 10:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Duplication of items with M2A field result in GraphQL error

5 participants