Continue Migration, almost done

This commit is contained in:
Daniele Pancottini
2022-12-20 19:15:40 +01:00
parent 15faacc7de
commit e5ebf60e83
11 changed files with 290 additions and 196 deletions

View File

@@ -19,6 +19,8 @@ import type {
Collection,
Maybe,
Metafield as ShopifyMetafield,
MediaConnection,
Model3d,
} from '../../schema'
import { colorMap } from './colors'
@@ -112,6 +114,7 @@ export function normalizeProduct(
priceRange,
options,
metafields,
media,
...rest
}: ShopifyProduct,
locale?: string
@@ -131,6 +134,7 @@ export function normalizeProduct(
.map((o) => normalizeProductOption(o))
: [],
metafields: normalizeMetafields(metafields, locale),
media: media ? normalizeProductMedia(media) : [],
description: description || '',
...(descriptionHtml && { descriptionHtml }),
...rest,
@@ -256,3 +260,18 @@ export const normalizeMetafieldValue = (
}
return getMetafieldValue(type, value, locale)
}
const normalizeProductMedia = ({ edges }: MediaConnection) => {
return edges
.filter(({ node }) => Object.keys(node).length !== 0)
.map(({ node }) => {
return {
sources: (node as Model3d).sources.map(({ format, url }) => {
return {
format: format,
url: url,
}
}),
}
})
}

View File

@@ -83,6 +83,7 @@ const getProductQuery = /* GraphQL */ `
}
}
}
}
metafields(identifiers: $withMetafields) {
key
value