update codegen to include new vendors query and implement vendors query

Signed-off-by: Loan Laux <loan@outgrow.io>
This commit is contained in:
Loan Laux 2021-05-14 13:07:29 +04:00
parent b5559cc492
commit 16e475067b
No known key found for this signature in database
GPG Key ID: AF9E9BD6548AD52E
5 changed files with 170 additions and 21 deletions

View File

@ -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,
}
}

View File

@ -5062,6 +5062,8 @@ export type Query = {
catalogItems?: Maybe<CatalogItemConnection>
/** Gets product from catalog */
catalogItemProduct?: Maybe<CatalogItemProduct>
/** Gets an array of all vendors */
vendors?: Maybe<VendorConnection>
/** 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<Maybe<Scalars['ID']>>
tagIds?: Maybe<Array<Maybe<Scalars['ID']>>>
booleanFilters?: Maybe<Array<Maybe<CatalogBooleanFilter>>>
searchQuery?: Maybe<Scalars['String']>
after?: Maybe<Scalars['ConnectionCursor']>
before?: Maybe<Scalars['ConnectionCursor']>
first?: Maybe<Scalars['ConnectionLimitInt']>
@ -5287,6 +5290,17 @@ export type QueryCatalogItemProductArgs = {
slugOrId?: Maybe<Scalars['String']>
}
export type QueryVendorsArgs = {
shopIds: Array<Maybe<Scalars['ID']>>
tagIds?: Maybe<Array<Maybe<Scalars['ID']>>>
after?: Maybe<Scalars['ConnectionCursor']>
before?: Maybe<Scalars['ConnectionCursor']>
first?: Maybe<Scalars['ConnectionLimitInt']>
last?: Maybe<Scalars['ConnectionLimitInt']>
offset?: Maybe<Scalars['Int']>
sortOrder?: Maybe<SortOrder>
}
export type QueryProductsByTagIdArgs = {
shopId: Scalars['ID']
tagId: Scalars['ID']
@ -7575,6 +7589,44 @@ export type UserInput = {
username?: Maybe<Scalars['String']>
}
export type Vendor = {
__typename?: 'Vendor'
/** The name of the vendor */
name?: Maybe<Scalars['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)
*/
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<Array<Maybe<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?: Maybe<Array<Maybe<Vendor>>>
/** 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<Vendor>
}
/** Input for an `VerifySMTPEmailSettingsInput` */
export type VerifySmtpEmailSettingsInput = {
/** The ID of the shop this setting belongs to */

View File

@ -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`
"""

View File

@ -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<BrandEdge[]> => {
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: {

View File

@ -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
}
}
}