Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Add params sponsoredCount query search #2519

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/api/src/__generated__/schema.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions packages/api/src/platforms/vtex/clients/search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface SearchArgs {
hideUnavailableItems?: boolean
showInvisibleItems?: boolean
showSponsored?: boolean
sponsoredCount?: number
}

export interface ProductLocator {
Expand Down Expand Up @@ -115,6 +116,7 @@ export const IntelligentSearch = (
type,
fuzzy = 'auto',
showInvisibleItems,
sponsoredCount
}: SearchArgs): Promise<T> => {
const params = new URLSearchParams({
page: (page + 1).toString(),
Expand All @@ -141,6 +143,10 @@ export const IntelligentSearch = (
params.append('showSponsored', showSponsored.toString())
}

if (sponsoredCount !== undefined) {
params.append('sponsoredCount', sponsoredCount.toString())
}

const pathname = addDefaultFacets(selectedFacets)
.map(({ key, value }) => `${key}/${value}`)
.join('/')
Expand Down
3 changes: 2 additions & 1 deletion packages/api/src/platforms/vtex/resolvers/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export const Query = {
},
search: async (
_: unknown,
{ first, after: maybeAfter, sort, term, selectedFacets }: QuerySearchArgs,
{ first, after: maybeAfter, sort, term, selectedFacets, sponsoredCount }: QuerySearchArgs,
ctx: Context
) => {
// Insert channel in context for later usage
Expand Down Expand Up @@ -160,6 +160,7 @@ export const Query = {
query: query ?? undefined,
sort: SORT_MAP[sort ?? 'score_desc'],
selectedFacets: selectedFacets?.flatMap(transformSelectedFacet) ?? [],
sponsoredCount: sponsoredCount ?? undefined
}

const productSearchPromise = ctx.clients.search.products(searchArgs)
Expand Down
4 changes: 4 additions & 0 deletions packages/api/src/typeDefs/query.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ type Query {
Array of selected search facets.
"""
selectedFacets: [IStoreSelectedFacet!]
"""
Search advertisement products return in result.
"""
sponsoredCount: Int
): StoreSearchResult!
@cacheControl(scope: "public", sMaxAge: 120, staleWhileRevalidate: 3600)

Expand Down
8 changes: 4 additions & 4 deletions packages/core/@generated/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const documents = {
types.Filter_FacetsFragmentDoc,
'\n fragment ProductDetailsFragment_product on StoreProduct {\n id: productID\n sku\n name\n gtin\n description\n unitMultiplier\n isVariantOf {\n name\n productGroupID\n skuVariants {\n activeVariations\n slugsMap\n availableVariations\n }\n }\n\n image {\n url\n alternateName\n }\n\n brand {\n name\n }\n\n offers {\n lowPrice\n lowPriceWithTaxes\n offers {\n availability\n price\n priceWithTaxes\n listPrice\n listPriceWithTaxes\n seller {\n identifier\n }\n }\n }\n\n additionalProperty {\n propertyID\n name\n value\n valueReference\n }\n\n # Contains necessary info to add this item to cart\n ...CartProductItem\n }\n':
types.ProductDetailsFragment_ProductFragmentDoc,
'\n fragment ClientManyProducts on Query {\n search(\n first: $first\n after: $after\n sort: $sort\n term: $term\n selectedFacets: $selectedFacets\n ) {\n products {\n pageInfo {\n totalCount\n }\n }\n }\n }\n':
'\n fragment ClientManyProducts on Query {\n search(\n first: $first\n after: $after\n sort: $sort\n term: $term\n selectedFacets: $selectedFacets\n sponsoredCount: $sponsoredCount\n\n ) {\n products {\n pageInfo {\n totalCount\n }\n }\n }\n }\n':
types.ClientManyProductsFragmentDoc,
'\n fragment ClientProduct on Query {\n product(locator: $locator) {\n id: productID\n }\n }\n':
types.ClientProductFragmentDoc,
Expand All @@ -42,7 +42,7 @@ const documents = {
types.ValidateCartMutationDocument,
'\n mutation SubscribeToNewsletter($data: IPersonNewsletter!) {\n subscribeToNewsletter(data: $data) {\n id\n }\n }\n':
types.SubscribeToNewsletterDocument,
'\n query ClientManyProductsQuery(\n $first: Int!\n $after: String\n $sort: StoreSort!\n $term: String!\n $selectedFacets: [IStoreSelectedFacet!]!\n ) {\n ...ClientManyProducts\n search(\n first: $first\n after: $after\n sort: $sort\n term: $term\n selectedFacets: $selectedFacets\n ) {\n products {\n pageInfo {\n totalCount\n }\n edges {\n node {\n ...ProductSummary_product\n }\n }\n }\n }\n }\n':
'\n query ClientManyProductsQuery(\n $first: Int!\n $after: String\n $sort: StoreSort!\n $term: String!\n $selectedFacets: [IStoreSelectedFacet!]!\n $sponsoredCount: Int\n ) {\n ...ClientManyProducts\n search(\n first: $first\n after: $after\n sort: $sort\n term: $term\n selectedFacets: $selectedFacets\n sponsoredCount: $sponsoredCount\n ) {\n products {\n pageInfo {\n totalCount\n }\n edges {\n node {\n ...ProductSummary_product\n }\n }\n }\n }\n }\n':
types.ClientManyProductsQueryDocument,
'\n query ClientProductGalleryQuery(\n $first: Int!\n $after: String!\n $sort: StoreSort!\n $term: String!\n $selectedFacets: [IStoreSelectedFacet!]!\n ) {\n ...ClientProductGallery\n redirect(term: $term, selectedFacets: $selectedFacets) {\n url\n }\n search(\n first: $first\n after: $after\n sort: $sort\n term: $term\n selectedFacets: $selectedFacets\n ) {\n products {\n pageInfo {\n totalCount\n }\n }\n facets {\n ...Filter_facets\n }\n metadata {\n ...SearchEvent_metadata\n }\n }\n }\n\n fragment SearchEvent_metadata on SearchMetadata {\n isTermMisspelled\n logicalOperator\n }\n':
types.ClientProductGalleryQueryDocument,
Expand Down Expand Up @@ -80,7 +80,7 @@ export function gql(
* The gql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function gql(
source: '\n fragment ClientManyProducts on Query {\n search(\n first: $first\n after: $after\n sort: $sort\n term: $term\n selectedFacets: $selectedFacets\n ) {\n products {\n pageInfo {\n totalCount\n }\n }\n }\n }\n'
source: '\n fragment ClientManyProducts on Query {\n search(\n first: $first\n after: $after\n sort: $sort\n term: $term\n selectedFacets: $selectedFacets\n sponsoredCount: $sponsoredCount\n\n ) {\n products {\n pageInfo {\n totalCount\n }\n }\n }\n }\n'
): typeof import('./graphql').ClientManyProductsFragmentDoc
/**
* The gql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
Expand Down Expand Up @@ -152,7 +152,7 @@ export function gql(
* The gql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function gql(
source: '\n query ClientManyProductsQuery(\n $first: Int!\n $after: String\n $sort: StoreSort!\n $term: String!\n $selectedFacets: [IStoreSelectedFacet!]!\n ) {\n ...ClientManyProducts\n search(\n first: $first\n after: $after\n sort: $sort\n term: $term\n selectedFacets: $selectedFacets\n ) {\n products {\n pageInfo {\n totalCount\n }\n edges {\n node {\n ...ProductSummary_product\n }\n }\n }\n }\n }\n'
source: '\n query ClientManyProductsQuery(\n $first: Int!\n $after: String\n $sort: StoreSort!\n $term: String!\n $selectedFacets: [IStoreSelectedFacet!]!\n $sponsoredCount: Int\n ) {\n ...ClientManyProducts\n search(\n first: $first\n after: $after\n sort: $sort\n term: $term\n selectedFacets: $selectedFacets\n sponsoredCount: $sponsoredCount\n ) {\n products {\n pageInfo {\n totalCount\n }\n edges {\n node {\n ...ProductSummary_product\n }\n }\n }\n }\n }\n'
): typeof import('./graphql').ClientManyProductsQueryDocument
/**
* The gql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
Expand Down
5 changes: 4 additions & 1 deletion packages/core/@generated/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ export type QuerySearchArgs = {
first: Scalars['Int']['input']
selectedFacets: InputMaybe<Array<IStoreSelectedFacet>>
sort?: InputMaybe<StoreSort>
sponsoredCount: InputMaybe<Scalars['Int']['input']>
term?: InputMaybe<Scalars['String']['input']>
}

Expand Down Expand Up @@ -1431,6 +1432,7 @@ export type ClientManyProductsQueryQueryVariables = Exact<{
sort: StoreSort
term: Scalars['String']['input']
selectedFacets: Array<IStoreSelectedFacet> | IStoreSelectedFacet
sponsoredCount: InputMaybe<Scalars['Int']['input']>
}>

export type ClientManyProductsQueryQuery = {
Expand Down Expand Up @@ -1887,6 +1889,7 @@ export const ClientManyProductsFragmentDoc = new TypedDocumentString(
sort: $sort
term: $term
selectedFacets: $selectedFacets
sponsoredCount: $sponsoredCount
) {
products {
pageInfo {
Expand Down Expand Up @@ -2090,7 +2093,7 @@ export const SubscribeToNewsletterDocument = {
export const ClientManyProductsQueryDocument = {
__meta__: {
operationName: 'ClientManyProductsQuery',
operationHash: 'ad2eb78cfccb9dbd5a9f2d1e150cc70fea5da99a',
operationHash: '14148671fbf53498fad5c600ee87765920145019',
},
} as unknown as TypedDocumentString<
ClientManyProductsQueryQuery,
Expand Down
Loading
Loading