Skip to content
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

MI-168: Use more specific type than autogenerated NormalPage in getTransformedPageData parameters #78

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import { NormalPage } from '@aligent/bigcommerce-operations';
import { CmsPage } from '@aligent/bigcommerce-resolvers';

export const bcHomePageContent: NormalPage = {
export const bcHomePageContent = {
id: 'Tm9ybWFsUGFnZToxNw==',
path: '/home/',
htmlBody: '<p>This is the test homepage</p>',
Expand Down Expand Up @@ -34,7 +31,7 @@ export const bcHomePageContent: NormalPage = {
__typename: 'NormalPage',
};

export const bcHomePageContentWithImages: NormalPage = {
export const bcHomePageContentWithImages = {
id: 'Tm9ybWFsUGFnZToyMw==',
path: '/chamal-image-test/',
htmlBody:
Expand All @@ -60,7 +57,7 @@ export const bcHomePageContentWithImages: NormalPage = {
__typename: 'NormalPage',
};

export const transformedHomePageContent: CmsPage = {
export const transformedHomePageContent = {
__typename: 'CmsPage',
url_key: 'home',
content: '<p>This is the test homepage</p>',
Expand All @@ -73,7 +70,7 @@ export const transformedHomePageContent: CmsPage = {
redirect_code: 0,
};

export const transformedHomePageContentWithImages: CmsPage = {
export const transformedHomePageContentWithImages = {
url_key: 'chamal-image-test',
content:
'<p><img class="__mce_add_custom__" title="half-banner-2.jpg" src="https://cdn11.bigcommerce.com/s-xxxxxx/product_images/uploaded_images/half-banner-2.jpg" alt="half-banner-2.jpg" width="900" height="376" /></p>',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import { NormalPage, RawHtmlPage } from '@aligent/bigcommerce-operations';
import { SeoDetailsFragment } from '@aligent/bigcommerce-operations';
import { CmsPage } from '@aligent/bigcommerce-resolvers';

const CND_MASK = /%%GLOBAL_CdnStorePath%%/g;

export const getTransformedPageData = (data: NormalPage | RawHtmlPage, cdnUrl: string): CmsPage => {
type PageData = {
path: string;
htmlBody: string;
name: string;
seo: SeoDetailsFragment;
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we have the SeoDetailsFragments as a manual type too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jackmacaa the fragment type is generated from our actual request to bigcommerce, so it won't break things when unrelated types change on the schema.

Ideally we would use fragments for the page types as well but that's not how the GraphQL requests were architected and I wanted to avoid runtime changes (which modifications to the GraphQL requests would be!)

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah ye that makes sense.


export const getTransformedPageData = (data: PageData, cdnUrl: string): CmsPage => {
const { path, htmlBody, name, seo } = data;
return {
url_key: path.replace(/\//g, ''),
Expand Down
Loading