Skip to content

Commit

Permalink
adjust the conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
beatrizmaselli committed May 26, 2023
1 parent 7f5f313 commit d033056
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 27 deletions.
62 changes: 36 additions & 26 deletions packages/api/src/platforms/vtex/resolvers/query.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { FACET_CROSS_SELLING_MAP } from "./../utils/facets"
import { BadRequestError, NotFoundError } from "../../errors"
import { mutateChannelContext, mutateLocaleContext } from "../utils/contex"
import { enhanceSku } from "../utils/enhanceSku"
import { FACET_CROSS_SELLING_MAP } from './../utils/facets'
import { BadRequestError, NotFoundError } from '../../errors'
import { mutateChannelContext, mutateLocaleContext } from '../utils/contex'
import { enhanceSku } from '../utils/enhanceSku'
import {
findChannel,
findCrossSelling,
findLocale,
findSkuId,
findSlug,
transformSelectedFacet,
} from "../utils/facets"
import { SORT_MAP } from "../utils/sort"
import { StoreCollection } from "./collection"
} from '../utils/facets'
import { SORT_MAP } from '../utils/sort'
import { StoreCollection } from './collection'
import type {
QueryAllCollectionsArgs,
QueryAllProductsArgs,
Expand All @@ -20,12 +20,12 @@ import type {
QuerySearchArgs,
QuerySellersArgs,
QueryShippingArgs,
QueryRedirectArgs
} from "../../../__generated__/schema"
import type { CategoryTree } from "../clients/commerce/types/CategoryTree"
import type { Context } from "../index"
import { isValidSkuId, pickBestSku } from "../utils/sku"
import { SearchArgs } from "../clients/search"
QueryRedirectArgs,
} from '../../../__generated__/schema'
import type { CategoryTree } from '../clients/commerce/types/CategoryTree'
import type { Context } from '../index'
import { isValidSkuId, pickBestSku } from '../utils/sku'
import { SearchArgs } from '../clients/search'

export const Query = {
product: async (_: unknown, { locator }: QueryProductArgs, ctx: Context) => {
Expand Down Expand Up @@ -61,15 +61,16 @@ export const Query = {
* Here be dragons 🦄🦄🦄
*
* In some cases, the slug has a valid skuId for a different
* product. This condition makes sure that the fetched sku
* product. This condition makes sure that the fetched sku
* is the one we actually asked for
* */
if (
slug && sku.isVariantOf.linkText &&
slug &&
sku.isVariantOf.linkText &&
!slug.startsWith(sku.isVariantOf.linkText)
) {
throw new Error(
`Slug was set but the fetched sku does not satisfy the slug condition. slug: ${slug}, linkText: ${sku.isVariantOf.linkText}`,
`Slug was set but the fetched sku does not satisfy the slug condition. slug: ${slug}, linkText: ${sku.isVariantOf.linkText}`
)
}

Expand Down Expand Up @@ -139,13 +140,17 @@ export const Query = {
* etc
*/
if (crossSelling) {
const products = await ctx.clients.commerce.catalog.products.crossselling({
type: FACET_CROSS_SELLING_MAP[crossSelling.key],
productId: crossSelling.value,
})

query = `product:${products.map((x) => x.productId).slice(0, first).join(";")
}`
const products = await ctx.clients.commerce.catalog.products.crossselling(
{
type: FACET_CROSS_SELLING_MAP[crossSelling.key],
productId: crossSelling.value,
}
)

query = `product:${products
.map((x) => x.productId)
.slice(0, first)
.join(';')}`
}

const after = maybeAfter ? Number(maybeAfter) : 0
Expand Down Expand Up @@ -294,7 +299,7 @@ export const Query = {
})

return {
url: redirect
url: redirect,
}
},

Expand All @@ -307,13 +312,18 @@ export const Query = {
clients: { commerce },
} = ctx

const regionData = await commerce.checkout.region({ postalCode, geoCoordinates, country, salesChannel })
const regionData = await commerce.checkout.region({
postalCode,
geoCoordinates,
country,
salesChannel,
})
const region = regionData?.[0]
const { id, sellers } = region

return {
id,
sellers
sellers,
}
},
}
3 changes: 2 additions & 1 deletion packages/api/src/typeDefs/query.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,6 @@ type Query {
}

"""
Redirect informations, including url returned by the query.
https://schema.org/Thing
"""
Expand All @@ -343,7 +342,9 @@ type StoreRedirect {
URL to redirect
"""
url: String
}

"""
Regionalization with sellers information.
"""
type SellersData {
Expand Down

0 comments on commit d033056

Please sign in to comment.