Amber Shopify Project created using ReactJS+React-Redux with GraphQL API integration. Storefront Shopify API: https://github.com/Shopify/shopify-app-js/tree/main/packages/api-clients/storefront-api-client#readme

ProductService.js 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import axios from 'axios'
  2. import { createStorefrontApiClient } from '@shopify/storefront-api-client';
  3. import { API_URL, REACT_APP_API_KEY, REACT_APP_API_SECRET, REACT_APP_ACCESS_TOKEN, REACT_APP_SHOP_NAME } from '../utils/httpCommon'
  4. const shopUrl = REACT_APP_SHOP_NAME;
  5. const accessToken = REACT_APP_ACCESS_TOKEN;
  6. const client = createStorefrontApiClient({
  7. storeDomain: `https://${shopUrl}/api/2024-10/graphql.json`,
  8. apiVersion: '2024-10',
  9. publicAccessToken: accessToken,
  10. });
  11. const getProducts = async () => {
  12. const productQuery = `
  13. {
  14. products(first: 99) {
  15. nodes {
  16. title
  17. tags
  18. media(first: 4) {
  19. nodes {
  20. previewImage {
  21. url
  22. }
  23. }
  24. }
  25. variants(first: 10) {
  26. nodes {
  27. id
  28. title
  29. price {
  30. amount
  31. currencyCode
  32. }
  33. sku
  34. }
  35. }
  36. }
  37. }
  38. }
  39. `;
  40. const { data, errors, extensions } = await client.request(productQuery, {
  41. variables: {
  42. handle: 'sample-product',
  43. },
  44. });
  45. console.log(data)
  46. return
  47. }
  48. const ProductService = {
  49. getProducts
  50. }
  51. export default ProductService