1.1.0 • Published 4 years ago
gatsby-source-saphy v1.1.0
gatsby-source-saphy
use saphy strore as a source to your gatsbyjs ecommerce website
Installation
#NPM
npm i --save gatsby-source-saphy
#YARN
yarn add gatsby-source-saphy
add the envirenment variable SAPHY_KEY=...
use in gatsby-config.js
plugins: [
//...
{
resolve:'gatsby-source-saphy',
options:{
SAPHY_KEY:"..."
}
}
]
query all product from your store using GraphQL
exports.createPages = async ({ graphql, actions }) => {
const { createPage } = actions;
const postTempalte = path.resolve("./src/templates/post.js");
return graphql(`
query {
allSaphy {
edges {
node {
avatar
name
id
}
}
}
}
`).then(result => {
let alledges = result.data.allSaphy.edges
alledges.forEach(({ node }) => {
createPage({
path: _.kebabCase(node.name),
id: node.id,
component: postTempalte,
context: {
id: node.id
}
})
})
})
}