Skip to content

Commit b3a5577

Browse files
committed
Add all fields for links
1 parent c959386 commit b3a5577

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
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
@@ -77,7 +77,7 @@ describe('createFragment() simple cases', () => {
7777
"fragment ContentUrl on ContentUrl { type default hierarchical internal graph base }",
7878
"fragment IContentMetadata on IContentMetadata {key locale fallbackForLocale version displayName url {...ContentUrl} types published status created lastModified sortOrder variation ...MediaMetadata }",
7979
"fragment _IContent on _IContent { _deleted _fulltext _modified _score _id _track _metadata {...IContentMetadata} }",
80-
"fragment ct1 on ct1 { __typename lin { url { type, default }} ric { html, json } lin2 { url { type, default }} ric2 { html, json } ..._IContent }",
80+
"fragment ct1 on ct1 { __typename lin { url { ...ContentUrl }} ric { html, json } lin2 { url { ...ContentUrl }} ric2 { html, json } ..._IContent }",
8181
]
8282
`);
8383
});

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
buildBaseTypeFragments,
1717
isBaseType,
1818
toBaseTypeFragmentKey,
19+
CONTENT_URL_FRAGMENT,
1920
} from '../util/baseTypeUtil.js';
2021
import { checkTypeConstraintIssues } from '../util/fragmentConstraintChecks.js';
2122
import { GraphMissingContentTypeError } from './error.js';
@@ -135,11 +136,14 @@ function convertPropertyField(
135136
} else if (property.type === 'richText') {
136137
fields.push(`${name} { html, json }`);
137138
} else if (property.type === 'url') {
138-
fields.push(`${name} { type, default }`);
139+
extraFragments.push(CONTENT_URL_FRAGMENT);
140+
fields.push(`${name} { ...ContentUrl }`);
139141
} else if (property.type === 'link') {
140-
fields.push(`${name} { url { type, default }}`);
142+
extraFragments.push(CONTENT_URL_FRAGMENT);
143+
fields.push(`${name} { url { ...ContentUrl }}`);
141144
} else if (property.type === 'contentReference') {
142-
fields.push(`${name} { url { type default }}`);
145+
extraFragments.push(CONTENT_URL_FRAGMENT);
146+
fields.push(`${name} { key url { ...ContentUrl }}`);
143147
} else if (property.type === 'array') {
144148
const f = convertProperty(name, property.items, rootName, visited);
145149
fields.push(...f.fields);

packages/optimizely-cms-sdk/src/util/baseTypeUtil.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,12 @@ export function isBaseMediaType(key: string): key is MediaStringTypes {
4646
return (MEDIA_BASE_TYPES as readonly string[]).includes(key);
4747
}
4848

49+
export const CONTENT_URL_FRAGMENT =
50+
'fragment ContentUrl on ContentUrl { type default hierarchical internal graph base }';
51+
4952
const COMMON_FRAGMENTS = [
5053
'fragment MediaMetadata on MediaMetadata { mimeType thumbnail content }',
51-
'fragment ContentUrl on ContentUrl { type default hierarchical internal graph base }',
54+
CONTENT_URL_FRAGMENT,
5255
'fragment IContentMetadata on IContentMetadata {key locale fallbackForLocale version displayName url {...ContentUrl} types published status created lastModified sortOrder variation ...MediaMetadata }',
5356
'fragment _IContent on _IContent { _deleted _fulltext _modified _score _id _track _metadata {...IContentMetadata} }',
5457
];

0 commit comments

Comments
 (0)