Refactor API for getProduct and getAllProductPaths

Signed-off-by: Loan Laux <loan@outgrow.io>
This commit is contained in:
Loan Laux
2021-07-06 16:11:26 +03:00
parent 23e0d57cf5
commit ad1547a586
2 changed files with 18 additions and 49 deletions

View File

@@ -39,12 +39,17 @@ export default function getAllProductPathsOperation({
// RecursivePartial forces the method to check for every prop in the data, which is
// required in case there's a custom `query`
const { data } = await config.fetch<CatalogItem>(query, {
variables,
variables: {
...variables,
shopIds: [config.shopId],
},
})
const products = data.products.items
const products = data.catalogItems?.edges
return {
products: products.map((p) => ({ path: `/${p.slug}` })),
products: products.map(({ node }) => ({
path: `/${node.product?.slug}`,
})),
}
}