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
Merged

Conversation

tlgimenes
Copy link
Contributor

@tlgimenes tlgimenes commented Jun 28, 2021

What's the purpose of this pull request?

As it's described in here, using the addThirdPartySchema API goes against the Gatsby architecture and causes many problems when using Gatsby's incremental builds. This PR uses gatsby-graphql-toolkit for sourcing data and uses the declarative Gatsby File System API for declaratively create product pages. Also, from now on, we will use Gatsby's cache for not having to fetch all products every time. If you want to refresh the products, you will have to clear the cache Gatsby's cache with

yarn clean

These optimizations made me change a little bit the GraphQL schema we were using. Now, you can query for product during build using the APIs query { storeProduct } and query { allStoreProducts } and the product is behind the new StoreProduct type.

How to test it?

https://github.com/vtex-sites/btglobal.store/pull/663
https://github.com/vtex-sites/marinbrasil.store/pull/536
https://github.com/vtex-sites/storecomponents.store/pull/1001
https://github.com/vtex-sites/carrefourbrfood.store/pull/859

Results

The table below compares the build times, in seconds, without any cache, with cache and the current build times (controls).

Account without cache with cache control
btglobal 130 52 132
storecomponents 109 64 88
marinbrasil 333 68 185
carrefourbrfood 729 207 500

@netlify
Copy link

netlify bot commented Jun 28, 2021

✔️ Deploy Preview for storeui ready!

🔨 Explore the source changes: bbec9b9

🔍 Inspect the deploy log: https://app.netlify.com/sites/storeui/deploys/60db3100e69a950008ae9c1d

😎 Browse the preview: https://deploy-preview-793--storeui.netlify.app

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jun 28, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit bbec9b9:

Sandbox Source
Store UI Typescript Configuration

@tlgimenes tlgimenes marked this pull request as ready for review June 28, 2021 22:31
@tlgimenes tlgimenes requested a review from a team as a code owner June 28, 2021 22:31
@tlgimenes tlgimenes changed the title feat: use Gatsby file system API feat: use Gatsby file system routing API Jun 28, 2021
@tlgimenes tlgimenes changed the title feat: use Gatsby file system routing API feat: product page incremental builds Jun 28, 2021
Copy link
Contributor

@igorbrasileiro igorbrasileiro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job! I left some comments.

'Department',
'Category',
'Brand',
'SubCategory',
]

const readFile = promisify(readFileAsync)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain why you need to use the promisify? I was reading the node doc and saw that the readFile already return a promise.

Copy link
Contributor Author

@tlgimenes tlgimenes Jun 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice suggestion. Then I'd need to import from fs/promises instead of just fs. However fs/promises is available in node14 only. Do you think we can increase our node dependency?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, good point. I think we can increase our node to v14, because we are in alpha, and after alpha will be more difficult to change. I'm only seeing good points bumping the node dependency, what do you think about it?

* Source products
*/
promisses.push(async () => {
// Step1. Set up remote schema:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about create functions for each step? It may improve maintainability and readability. Also, you can create documentation for each step, for others that don't have too much context can understand too.

Copy link
Contributor Author

@tlgimenes tlgimenes Jun 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, like this it's easy to follow the tutorial and understand what's happening
https://github.com/gatsbyjs/gatsby-graphql-toolkit#how-it-works

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I can understand, and your comment directs well the reader to the specific documentation. Good work commenting.

@@ -0,0 +1,45 @@
import { graphql } from 'gatsby'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a suggestive name for this file? What does this p mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not really, because this is the path. Changing the name of this file changes the route generated. So to have a product in the path /<slug>/p we need to have a file named p.tsx in our filesystem

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, i forget that gatsby uses the file's path.

Comment on lines +28 to +43
export const query = graphql`
query ServerProductPageQuery($id: String!) {
product: storeProduct(id: { eq: $id }) {
...ProductDetailsTemplate_product
...StructuredProductFragment_product
titleTag
metaTagDescription
id: productId
description
categoryTree {
name
href
}
}
}
`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a doubt, why our queries can't be written inside .gql or .graphql files?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's because on how Gatsby query processing works

packages/gatsby-theme-store/src/sdk/pixel/events.ts Outdated Show resolved Hide resolved
packages/gatsby-theme-store/src/views/search/index.tsx Outdated Show resolved Hide resolved
packages/gatsby-theme-store/src/views/search/index.tsx Outdated Show resolved Hide resolved
@igorbrasileiro
Copy link
Contributor

This PR is breaking on btglobal.store at the product page.

@tlgimenes
Copy link
Contributor Author

This PR is breaking on btglobal.store at the product page.

This is because of an unrelated issue. More info at: https://vtex.slack.com/archives/C92590P39/p1624912880182900

Copy link
Contributor

@igorbrasileiro igorbrasileiro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, seems good! Nice job

'Department',
'Category',
'Brand',
'SubCategory',
]

const readFile = promisify(readFileAsync)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, good point. I think we can increase our node to v14, because we are in alpha, and after alpha will be more difficult to change. I'm only seeing good points bumping the node dependency, what do you think about it?

* Source products
*/
promisses.push(async () => {
// Step1. Set up remote schema:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I can understand, and your comment directs well the reader to the specific documentation. Good work commenting.

@tlgimenes tlgimenes merged commit 8ab8bf0 into master Jun 29, 2021
@tlgimenes tlgimenes deleted the feat/gatsby-graphql-toolkit branch June 29, 2021 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants