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: product page incremental builds #793

Merged
merged 16 commits into from
Jun 29, 2021
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-cms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@babel/register": "^7.12.1",
"chokidar": "^3.5.0",
"fs-extra": "^9.0.1",
"gatsby-graphql-source-toolkit": "^0.6.3",
"gatsby-graphql-source-toolkit": "^2.0.1",
"p-map": "^4.0.0"
}
}
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-pixel-facebook/src/pixel/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const handler: PixelEventHandler = (event) => {
const items = product?.items

fbq('track', 'ViewContent', {
content_ids: items?.map((item) => item?.itemId),
content_ids: items?.map((item: any) => item?.itemId),
content_name: product?.productName,
content_type: 'product',
// TODO: send currency
Expand Down
8 changes: 5 additions & 3 deletions packages/gatsby-source-vtex/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"files": [
"dist",
"gatsby-*",
"index.js"
"index.js",
"src"
],
"engines": {
"node": ">=10"
Expand All @@ -28,8 +29,9 @@
"prepare": "tsdx build"
},
"dependencies": {
"@graphql-tools/delegate": "^6.0.15",
"@graphql-tools/wrap": "^6.0.15",
"@graphql-tools/delegate": "^7.1.5",
"@graphql-tools/wrap": "^7.0.8",
"gatsby-graphql-source-toolkit": "^2.0.1",
"isomorphic-unfetch": "^3.0.0",
"p-map": "^4.0.0",
"slugify": "^1.4.6",
Expand Down
27 changes: 0 additions & 27 deletions packages/gatsby-source-vtex/src/api.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,4 @@
interface SearchOptions {
query?: string
page: number
count: number
sort: 'orders:desc'
operator: 'and' | 'or'
fuzzy?: string
locale?: string
bgy_leap?: boolean
'hide-unavailable-items'?: boolean
}

export const api = {
is: {
search: (params: SearchOptions) => {
const searchParams = new URLSearchParams()

Object.keys(params).forEach((key) => {
const value = params[key as keyof SearchOptions]

if (value) {
searchParams.set(key, `${value}`)
}
})

return `/api/split/product_search/trade-policy/1?${searchParams}`
},
},
catalog: {
brand: {
list: ({ page, pageSize }: { page: number; pageSize: number }) =>
Expand Down
28 changes: 4 additions & 24 deletions packages/gatsby-source-vtex/src/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { inspect } from 'util'

import fetch from 'isomorphic-unfetch'

export interface VTEXOptions {
Expand Down Expand Up @@ -54,14 +56,13 @@ export const fetchGraphQL = async <T>(

retryCount += 1
console.error(
`[gatsby-source-vtex]: Error while fetching graphql data. Retry ${retryCount}`,
response.errors
`[gatsby-source-vtex]: Error while fetching graphql data. Retry ${retryCount}`
)
}

if (response) {
for (const error of response.errors) {
console.error(error)
console.error(inspect(error, false, 100, true))
}

throw new Error(
Expand Down Expand Up @@ -92,24 +93,3 @@ export const fetchVTEX = async <T>(
throw err
}
}

export const fetchIS = async <T>(
path: string,
options: VTEXOptions,
init?: RequestInit
): Promise<T> => {
try {
const url = `https://search.biggylabs.com.br/search-api/v1/${options.tenant}${path}`

return await fetchRetry(url, {
...init,
headers: {
...headers,
...init?.headers,
},
})
} catch (err) {
console.error(err)
throw err
}
}
Loading