Skip to content

Conversation

@exacs
Copy link
Contributor

@exacs exacs commented Nov 12, 2025

This PR adds alias to custom properties by prefixing the content type name:

fragment ContentType on ContentType {
  ContentType__p1:p1
  ContentType__p2:p2
}

And implements a function that removes the prefixes before returning the response to the user.

Fields that are not defined by the user are unaffected

Copilot finished reviewing on behalf of exacs November 12, 2025 14:00
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds GraphQL field aliasing to prevent duplicated field name collisions when generating fragments. Custom properties are aliased with their content type name prefix (e.g., ContentType__p1:p1), and the prefixes are automatically stripped from responses before returning data to users.

  • Adds removeTypePrefix function to recursively remove type-name prefixes from GraphQL response data
  • Updates convertPropertyField to apply aliases using the pattern {typeName}__{fieldName}:{fieldName}
  • Integrates prefix removal into getContentByPath and getPreviewContent methods

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
packages/optimizely-cms-sdk/src/graph/index.ts Adds removeTypePrefix function and integrates it into response processing for getContentByPath and getPreviewContent
packages/optimizely-cms-sdk/src/graph/createQuery.ts Updates query generation to add GraphQL aliases to all user-defined properties using the type name as prefix
packages/optimizely-cms-sdk/src/graph/test/createQueryExperiences.test.ts Updates test expectations to reflect aliased field names in generated fragments
packages/optimizely-cms-sdk/src/graph/test/createQuery.test.ts Updates test expectations across multiple test cases to reflect aliased field names
test/test-website/with-display-templates.config.mjs Adds new test component file to the build configuration
test/test-website/src/components/with-repeated-properties.tsx Adds test content types with repeated property names to validate the collision prevention
test/test-website/src/app/query/[...slug]/page.tsx Adds test page component for manual testing of the GraphQL query functionality
test/test-website/src/app/query/[...slug]/layout.tsx Adds layout component that reuses the root layout
test/test-website/src/app/en/layout.tsx Registers new test content types for collision testing

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

@TRomesh TRomesh left a comment

Choose a reason for hiding this comment

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

LGTM

@exacs exacs merged commit fc09028 into main Nov 13, 2025
4 checks passed
@exacs exacs deleted the bugfix/CMS-46783-graph-collision branch November 13, 2025 08:04
@exacs exacs mentioned this pull request Nov 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants