-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
RFC: File System Routing Improvements #24463
Conversation
@blainekasten looks really good, I've got an example that I currently use on a Gatsby site ~10K pages. I'll try to create a relevant scenario with the products collection builder. So you've used Currently this is trivial as you just need: //gatsby-node.js
products.forEach(product => {
//create product page
createPage()
product.reviews.forEach(review => {
//create review page
createPage()
}
}) I wonder if the // filepath:
// /src/pages/product/{id}/reviews/{name}.js
//
// urls:
// /product/1/reviews/newyorktimes (burger)
// /product/2/reviews/chickenlovers (chicken)
//
// This macro fetches the Product's, and generates a page for each one with the component given.
export default createPagesFromData([[Product, `Product`], [Review, `Review`]])
// This component then can fetch it's own data to use inside of the component.
export const query = graphql`
query RootProduct($id: String) {
product(id: { eq: $id }) {
id
name
}
review(id: { eq: $id }) {
id
name
}
}
` Each "braced" template will just take the matching item of the array. Thoughts? |
@herecydev Thanks for the feedback on this! So our goal with this API is to solve the 90% of use-cases. Working with multiple data sources is a bit tricky. Is the product and reviewed tied together in the node module? If it is you could do something like this:
This is assuming there is some structure like this:
If this doesn't exist already, you could make the connection in gatsby-node, or even create a new data structure that marries the two types. I'm curious how frequently people are merging two entirely unique data types together to decide if that warrants specific API support. |
Yer I get that, hard to quantify how big a problem it will be.
That's awesome, I assume any "magic" like @links or schemaCustomizations should work as well. Basically as long as you could query that normally... |
How would the approach proposed here look like to create individual pages for localized products while additionally requiring query pagination? As an example, let's consider the following GraphQL query for products stored in commercetools: query MyProductsQuery($locale: commercetools_Locale, $offset: Int) {
ct {
products(offset: $offset) {
results {
masterData {
current {
slug(locale: $locale)
}
}
}
}
}
} We use As an alternative, we could retrieve all available locales as an array of query MyProductsQuery($offset: Int) {
ct {
products(offset: $offset) {
results {
masterData {
current {
slugAllLocales {
locale
value
}
}
}
}
}
}
} The goal in both cases is to create product pages located at |
Gatsby Cloud Build Reportclient-only-paths 🎉 Your build was successful! See the Deploy preview here. Build Details🕐 Build time: 12s PerformanceLighthouse report
|
Gatsby Cloud Build Reportusing-styled-components 🎉 Your build was successful! See the Deploy preview here. Build Details🕐 Build time: 13s PerformanceLighthouse report
|
Gatsby Cloud Build Reportgatsby-master 🎉 Your build was successful! See the Deploy preview here. Build Details🕐 Build time: 14s PerformanceLighthouse report
|
Gatsby Cloud Build Report🚩 Your build failed. See the build logs here Errors Error getting repo data for starter "gatsby-starter-styled": Unexpected token : in JSON at position 3 in "https://raw.githubusercontent.com/gregoralbrecht/gatsby-starter-styled/master/package.json": 404: Not Found... |
Gatsby Cloud Build Report🚩 Your build failed. See the build logs here Errors Error getting repo data for starter "gatsby-starter-styled": Unexpected token : in JSON at position 3 in "https://raw.githubusercontent.com/gregoralbrecht/gatsby-starter-styled/master/package.json": 404: Not Found... |
a8f13a2
to
8688fe2
Compare
8688fe2
to
27cfd35
Compare
Click here to see the latest version rendered