query all products for vendors & paths, improve search

This commit is contained in:
cond0r
2021-02-12 09:56:03 +02:00
parent 1450492826
commit 8d801ce5d7
20 changed files with 315 additions and 126 deletions

View File

@@ -0,0 +1,41 @@
import { ProductEdge } from '@framework/schema'
import { ShopifyConfig } from '..'
const fetchAllProducts = async ({
config,
query,
variables,
acc = [],
cursor,
}: {
config: ShopifyConfig
query: string
acc?: ProductEdge[]
variables?: any
cursor?: string
}): Promise<ProductEdge[]> => {
const { data } = await config.fetch(query, {
variables: { ...variables, cursor },
})
const edges: ProductEdge[] = data?.products?.edges ?? []
const hasNextPage = data?.products?.pageInfo?.hasNextPage
acc = acc.concat(edges)
if (hasNextPage) {
const cursor = edges.pop()?.cursor
if (cursor) {
return fetchAllProducts({
config,
query,
variables,
acc,
cursor,
})
}
}
return acc
}
export default fetchAllProducts