Skip to content

Commit 1ce9def

Browse files
committed
Ensure "Property" suffix is added in alias
1 parent 62bf9ef commit 1ce9def

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

packages/optimizely-cms-sdk/src/graph/__test__/createQuery.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ describe('createFragment() with component properties', () => {
580580
"fragment ContentUrl on ContentUrl { type default hierarchical internal graph base }",
581581
"fragment IContentMetadata on IContentMetadata { key locale fallbackForLocale version displayName url {...ContentUrl} types published status created lastModified sortOrder variation ...MediaMetadata ...ItemMetadata ...InstanceMetadata }",
582582
"fragment _IContent on _IContent { _id _metadata {...IContentMetadata} }",
583-
"fragment ctBlockProperty on ctBlockProperty { __typename ctBlock__p1:p1 }",
583+
"fragment ctBlockProperty on ctBlockProperty { __typename ctBlockProperty__p1:p1 }",
584584
"fragment ct1 on ct1 { __typename ct1__p1:p1 { ...ctBlockProperty } ..._IContent }",
585585
]
586586
`);

packages/optimizely-cms-sdk/src/graph/createQuery.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,16 @@ function convertProperty(
6969
name: string,
7070
property: AnyProperty,
7171
rootName: string,
72+
suffix: string,
7273
visited: Set<string>
7374
): { fields: string[]; extraFragments: string[] } {
74-
const result = convertPropertyField(name, property, rootName, visited);
75+
const result = convertPropertyField(
76+
name,
77+
property,
78+
rootName,
79+
suffix,
80+
visited
81+
);
7582

7683
// logs warnings if the fragment generation causes potential issues
7784
const warningMessage = checkTypeConstraintIssues(rootName, property, result);
@@ -95,12 +102,13 @@ function convertPropertyField(
95102
name: string,
96103
property: AnyProperty,
97104
rootName: string,
105+
suffix: string,
98106
visited: Set<string>
99107
): { fields: string[]; extraFragments: string[] } {
100108
const fields: string[] = [];
101109
const subfields: string[] = [];
102110
const extraFragments: string[] = [];
103-
const nameInFragment = `${rootName}__${name}:${name}`;
111+
const nameInFragment = `${rootName}${suffix}__${name}:${name}`;
104112

105113
if (property.type === 'component') {
106114
const key = property.contentType.key;
@@ -146,7 +154,7 @@ function convertPropertyField(
146154
extraFragments.push(CONTENT_URL_FRAGMENT);
147155
fields.push(`${nameInFragment} { key url { ...ContentUrl }}`);
148156
} else if (property.type === 'array') {
149-
const f = convertProperty(name, property.items, rootName, visited);
157+
const f = convertProperty(name, property.items, rootName, suffix, visited);
150158
fields.push(...f.fields);
151159
extraFragments.push(...f.extraFragments);
152160
} else {
@@ -237,6 +245,7 @@ export function createFragment(
237245
propKey,
238246
prop,
239247
contentTypeName,
248+
suffix,
240249
visited
241250
);
242251
fields.push(...f);

0 commit comments

Comments
 (0)