-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: wrong allCollections query pagination and pagetype timeout errors
- Loading branch information
Showing
8 changed files
with
114 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 13 additions & 8 deletions
21
packages/api/src/platforms/vtex/clients/commerce/types/Portal.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,19 @@ | ||
export interface PortalPagetype { | ||
export type PortalPagetype = ValidPortalPagetype | NotFoundPortalPagetype | ||
|
||
export interface ValidPortalPagetype { | ||
id: number | ||
name: string | ||
url: string | ||
title: string | ||
metaTagDescription: string | ||
pageType: | ||
| 'Brand' | ||
| 'Category' | ||
| 'Department' | ||
| 'Subcategory' | ||
| 'FullText' | ||
| 'NotFound' | ||
pageType: 'Brand' | 'Category' | 'Department' | 'Subcategory' | 'FullText' | ||
} | ||
|
||
export interface NotFoundPortalPagetype { | ||
id: null | ||
name: null | ||
url: null | ||
title: null | ||
metaTagDescription: null | ||
pageType: 'NotFound' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
import { getSimulationLoader } from './simulation' | ||
import { getSkuLoader } from './sku' | ||
import { getPagetypeLoader } from './pagetype' | ||
import type { Context, Options } from '..' | ||
|
||
export type Loaders = ReturnType<typeof getLoaders> | ||
|
||
export const getLoaders = (options: Options, { clients }: Context) => { | ||
const skuLoader = getSkuLoader(options, clients) | ||
const simulationLoader = getSimulationLoader(options, clients) | ||
const pagetypeLoader = getPagetypeLoader(options, clients) | ||
|
||
return { | ||
skuLoader, | ||
simulationLoader, | ||
pagetypeLoader, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import DataLoader from 'dataloader' | ||
import pLimit from 'p-limit' | ||
|
||
import type { Options } from '..' | ||
import type { Clients } from '../clients' | ||
import type { PortalPagetype } from '../clients/commerce/types/Portal' | ||
|
||
// Limits concurrent requests to 20 so that they don't timeout | ||
const CONCURRENT_REQUESTS_MAX = 20 | ||
|
||
export const getPagetypeLoader = (_: Options, clients: Clients) => { | ||
const limit = pLimit(CONCURRENT_REQUESTS_MAX) | ||
|
||
const loader = (slugs: readonly string[]) => { | ||
return Promise.all( | ||
slugs.map((s: string) => | ||
limit(() => clients.commerce.catalog.portal.pagetype(s)) | ||
) | ||
) | ||
} | ||
|
||
return new DataLoader<string, PortalPagetype>(loader, { | ||
// DataLoader is being used to cache requests, not to batch them | ||
batch: false, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters