Great guide man, thanks for writing it!
It works great when you manually add the products through products.json, but I am currently trying to use this is on a website where I am getting the product data from Contentful / graphql. How would I go about adding the products from the graphql query to products.json or the checkout function? Thanks again and sorry if this is a stupid question but I'm fairly new to web development.
James Peters, Thanks for reading the article and asking. Are you using the Netlify Function to load the product or directly from gatsby? If it is from gatsby directly, we can use something like Apollo Client for React to fetch it. This will also help you in syncing the UI when data changed in the backend.
If you are connecting to a DB through netlify functions, there also we can query using GraphQL. I have a few examples here,
James Peters, It depends on where and when do you want to fetch the product list. But you can actually do the same in both components of losing and checkout using the react-appolo library as you are calling it directly from GraphQL.
These steps may be helpful,
First define the GraphQL query. Here is an example of fetching tags,
const ALL_TAGS = gql`
query {
allTags {
data {
_id
name
description
}
}
}
`
Then use the useQuery hook from the apollo react lib.
James Peters
Great guide man, thanks for writing it! It works great when you manually add the products through products.json, but I am currently trying to use this is on a website where I am getting the product data from Contentful / graphql. How would I go about adding the products from the graphql query to products.json or the checkout function? Thanks again and sorry if this is a stupid question but I'm fairly new to web development.