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
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ProductService.js 1.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. media(first: 4) {
  17. nodes {
  18. previewImage {
  19. url
  20. }
  21. }
  22. }
  23. title
  24. tags
  25. }
  26. }
  27. }
  28. `;
  29. const { data, errors, extensions } = await client.request(productQuery, {
  30. variables: {
  31. handle: 'sample-product',
  32. },
  33. });
  34. console.log(data)
  35. return
  36. }
  37. const ProductService = {
  38. getProducts
  39. }
  40. export default ProductService