mirror of
https://github.com/vercel/commerce.git
synced 2025-07-26 19:51:23 +00:00
query all products for vendors & paths, improve search
This commit is contained in:
@@ -19,14 +19,12 @@ const getAllPages = async (options?: {
|
||||
config = getConfig(config)
|
||||
|
||||
const { data } = await config.fetch(getAllPagesQuery, { variables })
|
||||
const edges = data?.pages?.edges
|
||||
|
||||
const pages = data.pages.edges.map(({ node }: PageEdge) => {
|
||||
return {
|
||||
...node,
|
||||
name: node.handle,
|
||||
url: `${config!.locale}/${node.handle}`,
|
||||
}
|
||||
})
|
||||
const pages = edges?.map(({ node }: PageEdge) => ({
|
||||
...node,
|
||||
url: node.handle,
|
||||
}))
|
||||
|
||||
return { pages }
|
||||
}
|
||||
|
@@ -1,27 +1,39 @@
|
||||
import { ShopifyConfig, getConfig } from '../api'
|
||||
import type { Page } from '../types'
|
||||
import { GraphQLFetcherResult } from '@commerce/api'
|
||||
|
||||
export type { Page }
|
||||
import { getConfig, ShopifyConfig } from '../api'
|
||||
import getPageQuery from '@framework/utils/queries/get-page-query'
|
||||
import { Page, PageEdge } from '@framework/schema'
|
||||
|
||||
export type GetPageResult<T extends { page?: any } = { page?: Page }> = T
|
||||
|
||||
export type PageVariables = {
|
||||
id: string
|
||||
type Variables = {
|
||||
slug: string
|
||||
}
|
||||
|
||||
async function getPage({
|
||||
url,
|
||||
variables,
|
||||
config,
|
||||
preview,
|
||||
}: {
|
||||
url?: string
|
||||
variables: PageVariables
|
||||
config?: ShopifyConfig
|
||||
type ReturnType = {
|
||||
page: any
|
||||
}
|
||||
|
||||
const getPage = async (options: {
|
||||
variables: Variables
|
||||
config: ShopifyConfig
|
||||
preview?: boolean
|
||||
}): Promise<GetPageResult> {
|
||||
}): Promise<ReturnType> => {
|
||||
let { config, variables } = options ?? {}
|
||||
config = getConfig(config)
|
||||
return {}
|
||||
|
||||
const { data }: GraphQLFetcherResult = await config.fetch(getPageQuery, {
|
||||
variables,
|
||||
})
|
||||
|
||||
const page: Page = data?.pageByHandle
|
||||
|
||||
return {
|
||||
page: page
|
||||
? {
|
||||
...page,
|
||||
url: page?.handle,
|
||||
}
|
||||
: null,
|
||||
}
|
||||
}
|
||||
|
||||
export default getPage
|
||||
|
@@ -1,30 +1,30 @@
|
||||
import { CollectionEdge } from '@framework/schema'
|
||||
import getCategories, { Category } from '@framework/utils/get-categories'
|
||||
import getVendors, { Brands } from '@framework/utils/get-vendors'
|
||||
|
||||
import { getConfig, ShopifyConfig } from '../api'
|
||||
import getAllCollectionsQuery from '../utils/queries/get-all-collections-query'
|
||||
|
||||
export type GetSiteInfoResult<
|
||||
T extends { categories: any[]; brands: any[] } = {
|
||||
categories: Category[]
|
||||
brands: Brands
|
||||
}
|
||||
> = T
|
||||
|
||||
const getSiteInfo = async (options?: {
|
||||
variables?: any
|
||||
config: ShopifyConfig
|
||||
preview?: boolean
|
||||
}) => {
|
||||
let { config, variables = { first: 250 } } = options ?? {}
|
||||
}): Promise<GetSiteInfoResult> => {
|
||||
let { config } = options ?? {}
|
||||
|
||||
config = getConfig(config)
|
||||
|
||||
const { data } = await config.fetch(getAllCollectionsQuery, { variables })
|
||||
const edges = data.collections?.edges ?? []
|
||||
|
||||
const categories = edges.map(
|
||||
({ node: { id: entityId, title: name, handle } }: CollectionEdge) => ({
|
||||
entityId,
|
||||
name,
|
||||
path: `/${handle}`,
|
||||
})
|
||||
)
|
||||
const categories = await getCategories(config)
|
||||
const brands = await getVendors(config)
|
||||
|
||||
return {
|
||||
categories,
|
||||
brands: [],
|
||||
brands,
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user