diff --git a/framework/reactioncommerce/common/get-site-info.ts b/framework/reactioncommerce/common/get-site-info.ts index e84ffaccf..4fcf8868f 100644 --- a/framework/reactioncommerce/common/get-site-info.ts +++ b/framework/reactioncommerce/common/get-site-info.ts @@ -20,11 +20,11 @@ const getSiteInfo = async (options?: { config = getConfig(config) const categories = await getCategories(config) - // const brands = await getVendors(config) + const brands = await getVendors(config) return { categories, - brands: [], + brands, } } diff --git a/framework/reactioncommerce/schema.d.ts b/framework/reactioncommerce/schema.d.ts index 21b174606..f313e489c 100644 --- a/framework/reactioncommerce/schema.d.ts +++ b/framework/reactioncommerce/schema.d.ts @@ -5062,6 +5062,8 @@ export type Query = { catalogItems?: Maybe /** Gets product from catalog */ catalogItemProduct?: Maybe + /** Gets an array of all vendors */ + vendors?: Maybe /** Returns a list of product in a tag */ productsByTagId: TagProductConnection /** Returns a tag from a provided tag ID or slug. Tags with isVisible set to false are excluded by default. */ @@ -5272,6 +5274,7 @@ export type QueryCatalogItemsArgs = { shopIds: Array> tagIds?: Maybe>> booleanFilters?: Maybe>> + searchQuery?: Maybe after?: Maybe before?: Maybe first?: Maybe @@ -5287,6 +5290,17 @@ export type QueryCatalogItemProductArgs = { slugOrId?: Maybe } +export type QueryVendorsArgs = { + shopIds: Array> + tagIds?: Maybe>> + after?: Maybe + before?: Maybe + first?: Maybe + last?: Maybe + offset?: Maybe + sortOrder?: Maybe +} + export type QueryProductsByTagIdArgs = { shopId: Scalars['ID'] tagId: Scalars['ID'] @@ -7575,6 +7589,44 @@ export type UserInput = { username?: Maybe } +export type Vendor = { + __typename?: 'Vendor' + /** The name of the vendor */ + name?: Maybe +} + +/** + * Wraps an array of vendors, providing pagination cursors and information. + * + * For information about what Relay-compatible connections are and how to use them, see the following articles: + * - [Relay Connection Documentation](https://facebook.github.io/relay/docs/en/graphql-server-specification.html#connections) + * - [Relay Connection Specification](https://facebook.github.io/relay/graphql/connections.htm) + * - [Using Relay-style Connections With Apollo Client](https://www.apollographql.com/docs/react/recipes/pagination.html) + */ +export type VendorConnection = { + __typename?: 'VendorConnection' + /** The list of nodes that match the query, wrapped in an edge to provide a cursor string for each */ + edges?: Maybe>> + /** + * You can request the `nodes` directly to avoid the extra wrapping that `NodeEdge` has, + * if you know you will not need to paginate the results. + */ + nodes?: Maybe>> + /** Information to help a client request the next or previous page */ + pageInfo: PageInfo + /** The total number of nodes that match your query */ + totalCount: Scalars['Int'] +} + +/** A connection edge in which each node is a String representing a vendor */ +export type VendorEdge = { + __typename?: 'VendorEdge' + /** The cursor that represents this node in the paginated results */ + cursor: Scalars['ConnectionCursor'] + /** The vendor */ + node?: Maybe +} + /** Input for an `VerifySMTPEmailSettingsInput` */ export type VerifySmtpEmailSettingsInput = { /** The ID of the shop this setting belongs to */ diff --git a/framework/reactioncommerce/schema.graphql b/framework/reactioncommerce/schema.graphql index d0f9c96c5..9f6232ad4 100644 --- a/framework/reactioncommerce/schema.graphql +++ b/framework/reactioncommerce/schema.graphql @@ -9508,6 +9508,11 @@ type Query { """ booleanFilters: [CatalogBooleanFilter] + """ + Optional text search query + """ + searchQuery: String + """ Return only results that come after this cursor. Use this with `first` to specify the number of results to return. """ @@ -9565,6 +9570,51 @@ type Query { slugOrId: String ): CatalogItemProduct + """ + Gets an array of all vendors + """ + vendors( + """ + Optionally provide a list of shop IDs from which you want to get the vendors + """ + shopIds: [ID]! + + """ + Optionally provide a list of tag IDs to further filter the vendors + """ + tagIds: [ID] + + """ + Return only results that come after this cursor. Use this with `first` to specify the number of results to return. + """ + after: ConnectionCursor + + """ + Return only results that come before this cursor. Use this with `last` to specify the number of results to return. + """ + before: ConnectionCursor + + """ + Return at most this many results. This parameter may be used with either `after` or `offset` parameters. + """ + first: ConnectionLimitInt + + """ + Return at most this many results. This parameter may be used with the `before` parameter. + """ + last: ConnectionLimitInt + + """ + Return only results that come after the Nth result. This parameter may be used with the `first` parameter. + """ + offset: Int + + """ + Return results sorted in this order + """ + sortOrder: SortOrder = asc + ): VendorConnection + """ Returns a list of product in a tag """ @@ -14163,6 +14213,59 @@ input UserInput { username: String } +type Vendor { + """ + The name of the vendor + """ + name: String +} + +""" +Wraps an array of vendors, providing pagination cursors and information. + +For information about what Relay-compatible connections are and how to use them, see the following articles: +- [Relay Connection Documentation](https://facebook.github.io/relay/docs/en/graphql-server-specification.html#connections) +- [Relay Connection Specification](https://facebook.github.io/relay/graphql/connections.htm) +- [Using Relay-style Connections With Apollo Client](https://www.apollographql.com/docs/react/recipes/pagination.html) +""" +type VendorConnection { + """ + The list of nodes that match the query, wrapped in an edge to provide a cursor string for each + """ + edges: [VendorEdge] + + """ + You can request the `nodes` directly to avoid the extra wrapping that `NodeEdge` has, + if you know you will not need to paginate the results. + """ + nodes: [Vendor] + + """ + Information to help a client request the next or previous page + """ + pageInfo: PageInfo! + + """ + The total number of nodes that match your query + """ + totalCount: Int! +} + +""" +A connection edge in which each node is a String representing a vendor +""" +type VendorEdge { + """ + The cursor that represents this node in the paginated results + """ + cursor: ConnectionCursor! + + """ + The vendor + """ + node: Vendor +} + """ Input for an `VerifySMTPEmailSettingsInput` """ diff --git a/framework/reactioncommerce/utils/get-vendors.ts b/framework/reactioncommerce/utils/get-vendors.ts index 5c68c0a03..55b8b1cfc 100644 --- a/framework/reactioncommerce/utils/get-vendors.ts +++ b/framework/reactioncommerce/utils/get-vendors.ts @@ -1,14 +1,15 @@ import { ReactionCommerceConfig } from '../api' -import fetchAllProducts from '../api/utils/fetch-all-products' import getAllProductVendors from './queries/get-all-product-vendors-query' +import { Vendor } from '@framework/schema' -export type BrandNode = { +export type Brand = { + entityId: string name: string path: string } export type BrandEdge = { - node: BrandNode + node: Brand } export type Brands = BrandEdge[] @@ -16,15 +17,15 @@ export type Brands = BrandEdge[] const getVendors = async ( config: ReactionCommerceConfig ): Promise => { - const vendors = await fetchAllProducts({ - config, - query: getAllProductVendors, + const { + data: { vendors }, + } = await config.fetch(getAllProductVendors, { variables: { - first: 250, + shopIds: [config.shopId], }, }) - let vendorsStrings = vendors.map(({ node: { vendor } }) => vendor) + let vendorsStrings: string[] = vendors.nodes?.map(({ name }: Vendor) => name) return [...new Set(vendorsStrings)].map((v) => ({ node: { diff --git a/framework/reactioncommerce/utils/queries/get-all-product-vendors-query.ts b/framework/reactioncommerce/utils/queries/get-all-product-vendors-query.ts index be08b8ec6..ab55b4ea2 100644 --- a/framework/reactioncommerce/utils/queries/get-all-product-vendors-query.ts +++ b/framework/reactioncommerce/utils/queries/get-all-product-vendors-query.ts @@ -1,15 +1,8 @@ const getAllProductVendors = /* GraphQL */ ` - query getAllProductVendors($first: Int = 250, $cursor: String) { - products(first: $first, after: $cursor) { - pageInfo { - hasNextPage - hasPreviousPage - } - edges { - node { - vendor - } - cursor + query getAllProductVendors($shopIds: [ID]!) { + vendors(shopIds: $shopIds) { + nodes { + name } } }