diff --git a/framework/swell/api/utils/fetch-swell-api.ts b/framework/swell/api/utils/fetch-swell-api.ts index 805aa46e8..c8707230d 100644 --- a/framework/swell/api/utils/fetch-swell-api.ts +++ b/framework/swell/api/utils/fetch-swell-api.ts @@ -3,11 +3,10 @@ import { swellConfig } from '../../index' const fetchSwellApi = async ( query: string, method: string, - variables: object | string + variables: [] = [] ) => { const { swell } = swellConfig - const res = await swell[query][method](variables) - return res + return await swell[query][method](...variables) } export default fetchSwellApi diff --git a/framework/swell/common/get-all-pages.ts b/framework/swell/common/get-all-pages.ts index a092823ca..1088a472c 100644 --- a/framework/swell/common/get-all-pages.ts +++ b/framework/swell/common/get-all-pages.ts @@ -25,16 +25,12 @@ const getAllPages = async (options?: { }): Promise => { let { config, variables = { first: 250 } } = options ?? {} config = getConfig(config) - const { locale } = config - const { data } = await config.fetch(getAllPagesQuery, { variables }) - - const pages = data.pages?.edges?.map( - ({ node: { title: name, handle, ...node } }: PageEdge) => ({ - ...node, - url: `/${locale}/${handle}`, - name, - }) - ) + const { locale, fetchSwell } = config + const { results } = await fetchSwell('content', 'list', ['pages']) + const pages = results.map(({ slug, ...rest }) => ({ + url: `/${locale}/${slug}`, + ...rest, + })) return { pages } } diff --git a/framework/swell/common/get-page.ts b/framework/swell/common/get-page.ts index ae7c0370b..40e9f6982 100644 --- a/framework/swell/common/get-page.ts +++ b/framework/swell/common/get-page.ts @@ -17,18 +17,15 @@ const getPage = async (options: { config = getConfig(config) const { locale } = config - - const { data } = await config.fetch(getPageQuery, { - variables, - }) - const page = data.node + const { id } = variables + const result = await config.fetchSwell('content', 'get', ['pages', id]) + const page = result return { page: page ? { ...page, - name: page.title, - url: `/${locale}/${page.handle}`, + url: `/${locale}/${page.slug}`, } : null, } diff --git a/framework/swell/product/get-all-products.ts b/framework/swell/product/get-all-products.ts index 5150af993..e212a2494 100644 --- a/framework/swell/product/get-all-products.ts +++ b/framework/swell/product/get-all-products.ts @@ -21,9 +21,11 @@ const getAllProducts = async (options: { }): Promise => { let { config, variables = { first: 250 } } = options ?? {} config = getConfig(config) - const { results } = await config.fetchSwell('products', 'list', { - limit: variables.first, - }) + const { results } = await config.fetchSwell('products', 'list', [ + { + limit: variables.first, + }, + ]) const products = results.map((product) => normalizeProduct(product)) ?? [] return { products, diff --git a/framework/swell/product/get-product.ts b/framework/swell/product/get-product.ts index c06617221..a95610a10 100644 --- a/framework/swell/product/get-product.ts +++ b/framework/swell/product/get-product.ts @@ -18,7 +18,7 @@ const getProduct = async (options: { let { config, variables } = options ?? {} config = getConfig(config) - const product = await config.fetchSwell('products', 'get', variables.slug) + const product = await config.fetchSwell('products', 'get', [variables.slug]) return { product: product ? normalizeProduct(product) : null,