@dadoagency/ecom-gatsby-builder-checkout-plugin
v1.0.8
Published
Query product data from builder.io and the checkout API
Downloads
17
Readme
This plugin is used to source product data from builder.io and the checkout API.
How To publish:
npm publish --access=public
How this works:
On build:
- query all the productPage pages that exist
- query the product selector for each productPage
- get the list of references to ProductVariant
- fetch product data from the checkout API for each ProductVariant
- merge the checkout API data with the builder data to generate a
productPageData
node with the following shape:
{
id: "",
path: "",
productSelector: {
onetime: {
products: [],
discounts: []
},
subscription: {
products: [],
discounts: []
}
}
}
The productPage page template should have a single page query that queries productPageData where path = '$path' to get all the product data for that specific productPage.
We aren't querying allBuilderModels since they don't include refs so instead we query our own data type 'productPageData'
Improvement opportunities:
- use gatsby cache to cache requests in gatsby-node.js to improve build times
- create graphql fragments to simplify page queries
- create a distinction between otp and subs products in builder.io
- do a single request to the checkout API in sourceNodes per page rather than a request per product (checkoutSDK can query a list of products)