-
Notifications
You must be signed in to change notification settings - Fork 2
Add alias in graph to prevent duplicated fields in fragments #171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this 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
removeTypePrefixfunction to recursively remove type-name prefixes from GraphQL response data - Updates
convertPropertyFieldto apply aliases using the pattern{typeName}__{fieldName}:{fieldName} - Integrates prefix removal into
getContentByPathandgetPreviewContentmethods
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 <[email protected]>
Co-authored-by: Copilot <[email protected]>
TRomesh
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This PR adds alias to custom properties by prefixing the content type name:
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