mirror of
https://github.com/vercel/commerce.git
synced 2025-07-26 19:51:23 +00:00
✨ feat: get all collection
:%s
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import type { CommerceAPIConfig } from '@commerce/api'
|
||||
import { CommerceAPI, getCommerceApi as commerceApi } from '@commerce/api'
|
||||
import getAllFacets from './operations/get-all-facets'
|
||||
import getAllCollections from './operations/get-all-collection'
|
||||
import getAllPages from './operations/get-all-pages'
|
||||
import getAllProductPaths from './operations/get-all-product-paths'
|
||||
import getAllProducts from './operations/get-all-products'
|
||||
@@ -42,6 +43,7 @@ const operations = {
|
||||
getAllProducts,
|
||||
getProduct,
|
||||
getAllFacets,
|
||||
getAllCollections,
|
||||
}
|
||||
|
||||
export const provider = { config, operations }
|
||||
|
45
framework/vendure/api/operations/get-all-collection.ts
Normal file
45
framework/vendure/api/operations/get-all-collection.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { OperationContext } from '@commerce/api/operations'
|
||||
import { Collection } from '@commerce/types/collection'
|
||||
import { Provider, VendureConfig } from '..'
|
||||
import { GetAllCollectionsQuery } from '../../schema'
|
||||
import { getAllCollectionsQuery } from '../../utils/queries/get-all-collections-query'
|
||||
|
||||
export type CollectionVariables = { first?: number }
|
||||
|
||||
export default function getAllCollectionsOperation({
|
||||
commerce,
|
||||
}: OperationContext<Provider>) {
|
||||
async function getAllCollections(opts?: {
|
||||
variables?: CollectionVariables
|
||||
config?: Partial<VendureConfig>
|
||||
preview?: boolean
|
||||
}): Promise<{ collections: Collection[] }>
|
||||
|
||||
async function getAllCollections({
|
||||
query = getAllCollectionsQuery,
|
||||
variables: { ...vars } = {},
|
||||
config: cfg,
|
||||
}: {
|
||||
query?: string
|
||||
variables?: CollectionVariables
|
||||
config?: Partial<VendureConfig>
|
||||
preview?: boolean
|
||||
} = {}): Promise<{ collections: Collection[] | any[] }> {
|
||||
const config = commerce.getConfig(cfg)
|
||||
const variables = {
|
||||
input: {
|
||||
take: vars.first,
|
||||
groupByCollection: true,
|
||||
},
|
||||
}
|
||||
const { data } = await config.fetch<GetAllCollectionsQuery>(query, {
|
||||
variables,
|
||||
})
|
||||
|
||||
return {
|
||||
collections: data.collections.items,
|
||||
}
|
||||
}
|
||||
|
||||
return getAllCollections
|
||||
}
|
17
framework/vendure/schema.d.ts
vendored
17
framework/vendure/schema.d.ts
vendored
@@ -3240,6 +3240,23 @@ export type GetAllFacetsQuery = { __typename?: 'Query' } & {
|
||||
}
|
||||
}
|
||||
|
||||
export type GetAllCollectionsQuery = { __typename?: 'Query' } & {
|
||||
collections: { __typename?: 'CollectionList' } & {
|
||||
items: Array<
|
||||
{ __typename?: 'Collection' } & Pick<
|
||||
Collection,
|
||||
'id' | 'name' | 'slug'
|
||||
> & {
|
||||
parent?: Maybe<{ __typename?: 'Collection' } & Pick<Collection, 'id'>>
|
||||
children?: Maybe<
|
||||
Array<{ __typename?: 'Collection' } & Pick<Collection, 'id'>>
|
||||
>
|
||||
}
|
||||
>,
|
||||
'totalItems'
|
||||
}
|
||||
}
|
||||
|
||||
export type ActiveOrderQueryVariables = Exact<{ [key: string]: never }>
|
||||
|
||||
export type ActiveOrderQuery = { __typename?: 'Query' } & {
|
||||
|
@@ -18,7 +18,6 @@ export function normalizeSearchResult(item: SearchResultFragment): ProductCard {
|
||||
// discount
|
||||
// isNotSell
|
||||
// weight
|
||||
// category
|
||||
}
|
||||
}
|
||||
|
||||
|
12
framework/vendure/utils/queries/get-all-collections-query.ts
Normal file
12
framework/vendure/utils/queries/get-all-collections-query.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
export const getAllCollectionsQuery = /* GraphQL */ `
|
||||
query collections ($options: CollectionListOptions) {
|
||||
collections (options: $options){
|
||||
totalItems,
|
||||
items {
|
||||
id
|
||||
name
|
||||
slug
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
Reference in New Issue
Block a user