@anker-in/shopify-sdk 1.2.0-beta.8 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/index.js.map +1 -1
- package/dist/client/index.mjs.map +1 -1
- package/dist/fragments/index.d.mts +17 -5
- package/dist/fragments/index.d.ts +17 -5
- package/dist/fragments/index.js +116 -6
- package/dist/fragments/index.js.map +1 -1
- package/dist/fragments/index.mjs +113 -7
- package/dist/fragments/index.mjs.map +1 -1
- package/dist/index.d.mts +151 -53
- package/dist/index.d.ts +151 -53
- package/dist/index.js +453 -145
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +446 -146
- package/dist/index.mjs.map +1 -1
- package/dist/queries/index.js +6 -4
- package/dist/queries/index.js.map +1 -1
- package/dist/queries/index.mjs +6 -4
- package/dist/queries/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -6,23 +6,21 @@ var shopifyCore = require('@anker-in/shopify-core');
|
|
|
6
6
|
var SPECIAL_METAFIELD_NAMESPACES = ["__discountCodeApp", "discounts_function"];
|
|
7
7
|
function constructMetafieldIdentifiersQueryParams(metafieldIdentifiers, metafieldNamespacePrefix) {
|
|
8
8
|
if (!metafieldIdentifiers || Object.keys(metafieldIdentifiers).length === 0) {
|
|
9
|
-
return {
|
|
10
|
-
productMetafieldIdentifiers: [],
|
|
11
|
-
variantMetafieldIdentifiers: []
|
|
12
|
-
};
|
|
9
|
+
return {};
|
|
13
10
|
}
|
|
14
11
|
const identifiers = Object.entries(metafieldIdentifiers).reduce(
|
|
15
12
|
(queryInput, [key, value]) => {
|
|
16
13
|
const metafieldIdentifiers2 = value;
|
|
14
|
+
const comboNamespace = `${metafieldNamespacePrefix}combo`;
|
|
17
15
|
const mappedIdentifiers = metafieldIdentifiers2.map((item) => {
|
|
18
|
-
if (SPECIAL_METAFIELD_NAMESPACES.includes(item.namespace)) {
|
|
16
|
+
if (SPECIAL_METAFIELD_NAMESPACES.includes(item.namespace) || item.namespace?.startsWith(comboNamespace)) {
|
|
19
17
|
return {
|
|
20
18
|
namespace: item.namespace,
|
|
21
19
|
key: item.key
|
|
22
20
|
};
|
|
23
21
|
}
|
|
24
22
|
return {
|
|
25
|
-
namespace:
|
|
23
|
+
namespace: comboNamespace,
|
|
26
24
|
key: item.namespace
|
|
27
25
|
};
|
|
28
26
|
});
|
|
@@ -32,10 +30,7 @@ function constructMetafieldIdentifiersQueryParams(metafieldIdentifiers, metafiel
|
|
|
32
30
|
queryInput[`${key}MetafieldIdentifiers`] = uniqueIdentifiers;
|
|
33
31
|
return queryInput;
|
|
34
32
|
},
|
|
35
|
-
{
|
|
36
|
-
productMetafieldIdentifiers: [],
|
|
37
|
-
variantMetafieldIdentifiers: []
|
|
38
|
-
}
|
|
33
|
+
{}
|
|
39
34
|
);
|
|
40
35
|
return identifiers;
|
|
41
36
|
}
|
|
@@ -699,8 +694,6 @@ var articleFragment = (
|
|
|
699
694
|
name
|
|
700
695
|
}
|
|
701
696
|
}
|
|
702
|
-
${imageFragment}
|
|
703
|
-
${seoFragment}
|
|
704
697
|
`
|
|
705
698
|
);
|
|
706
699
|
var articleWithMetafieldsFragment = (
|
|
@@ -729,9 +722,6 @@ var articleWithMetafieldsFragment = (
|
|
|
729
722
|
...metafield
|
|
730
723
|
}
|
|
731
724
|
}
|
|
732
|
-
${imageFragment}
|
|
733
|
-
${seoFragment}
|
|
734
|
-
${metafieldFragment}
|
|
735
725
|
`
|
|
736
726
|
);
|
|
737
727
|
var blogFragment = (
|
|
@@ -745,7 +735,6 @@ var blogFragment = (
|
|
|
745
735
|
...seo
|
|
746
736
|
}
|
|
747
737
|
}
|
|
748
|
-
${seoFragment}
|
|
749
738
|
`
|
|
750
739
|
);
|
|
751
740
|
var blogWithMetafieldsFragment = (
|
|
@@ -762,11 +751,123 @@ var blogWithMetafieldsFragment = (
|
|
|
762
751
|
...metafield
|
|
763
752
|
}
|
|
764
753
|
}
|
|
754
|
+
`
|
|
755
|
+
);
|
|
756
|
+
|
|
757
|
+
// src/fragments/page.ts
|
|
758
|
+
var pageFragment = (
|
|
759
|
+
/* GraphQL */
|
|
760
|
+
`
|
|
761
|
+
fragment page on Page {
|
|
762
|
+
id
|
|
763
|
+
handle
|
|
764
|
+
title
|
|
765
|
+
body
|
|
766
|
+
bodySummary
|
|
767
|
+
createdAt
|
|
768
|
+
updatedAt
|
|
769
|
+
seo {
|
|
770
|
+
...seo
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
${seoFragment}
|
|
774
|
+
`
|
|
775
|
+
);
|
|
776
|
+
var pageWithMetafieldsFragment = (
|
|
777
|
+
/* GraphQL */
|
|
778
|
+
`
|
|
779
|
+
fragment pageWithMetafields on Page {
|
|
780
|
+
id
|
|
781
|
+
handle
|
|
782
|
+
title
|
|
783
|
+
body
|
|
784
|
+
bodySummary
|
|
785
|
+
createdAt
|
|
786
|
+
updatedAt
|
|
787
|
+
seo {
|
|
788
|
+
...seo
|
|
789
|
+
}
|
|
790
|
+
metafields(identifiers: $pageMetafieldIdentifiers) {
|
|
791
|
+
...metafield
|
|
792
|
+
}
|
|
793
|
+
}
|
|
765
794
|
${seoFragment}
|
|
766
795
|
${metafieldFragment}
|
|
767
796
|
`
|
|
768
797
|
);
|
|
769
798
|
|
|
799
|
+
// src/fragments/shop.ts
|
|
800
|
+
var shopFragment = (
|
|
801
|
+
/* GraphQL */
|
|
802
|
+
`
|
|
803
|
+
fragment shop on Shop {
|
|
804
|
+
name
|
|
805
|
+
description
|
|
806
|
+
moneyFormat
|
|
807
|
+
primaryDomain {
|
|
808
|
+
host
|
|
809
|
+
url
|
|
810
|
+
}
|
|
811
|
+
paymentSettings {
|
|
812
|
+
currencyCode
|
|
813
|
+
enabledPresentmentCurrencies
|
|
814
|
+
}
|
|
815
|
+
brand {
|
|
816
|
+
logo {
|
|
817
|
+
image {
|
|
818
|
+
url
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
colors {
|
|
822
|
+
primary {
|
|
823
|
+
background
|
|
824
|
+
}
|
|
825
|
+
secondary {
|
|
826
|
+
background
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
`
|
|
832
|
+
);
|
|
833
|
+
var shopWithMetafieldsFragment = (
|
|
834
|
+
/* GraphQL */
|
|
835
|
+
`
|
|
836
|
+
fragment shopWithMetafields on Shop {
|
|
837
|
+
name
|
|
838
|
+
description
|
|
839
|
+
moneyFormat
|
|
840
|
+
primaryDomain {
|
|
841
|
+
host
|
|
842
|
+
url
|
|
843
|
+
}
|
|
844
|
+
paymentSettings {
|
|
845
|
+
currencyCode
|
|
846
|
+
enabledPresentmentCurrencies
|
|
847
|
+
}
|
|
848
|
+
brand {
|
|
849
|
+
logo {
|
|
850
|
+
image {
|
|
851
|
+
url
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
colors {
|
|
855
|
+
primary {
|
|
856
|
+
background
|
|
857
|
+
}
|
|
858
|
+
secondary {
|
|
859
|
+
background
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
metafields(identifiers: $shopMetafieldIdentifiers) {
|
|
864
|
+
...metafield
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
${metafieldFragment}
|
|
868
|
+
`
|
|
869
|
+
);
|
|
870
|
+
|
|
770
871
|
// src/queries/product/get-product.ts
|
|
771
872
|
var getProductQuery = (
|
|
772
873
|
/* GraphQL */
|
|
@@ -961,10 +1062,12 @@ var getCollectionsByHandlesQuery = (handles) => (
|
|
|
961
1062
|
...metafield
|
|
962
1063
|
}
|
|
963
1064
|
variants(first: 10) {
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
1065
|
+
edges {
|
|
1066
|
+
node {
|
|
1067
|
+
...variant
|
|
1068
|
+
metafields(identifiers: $variantMetafieldIdentifiers) {
|
|
1069
|
+
...metafield
|
|
1070
|
+
}
|
|
968
1071
|
}
|
|
969
1072
|
}
|
|
970
1073
|
}
|
|
@@ -1301,13 +1404,16 @@ var getProductQuery2 = (
|
|
|
1301
1404
|
`
|
|
1302
1405
|
);
|
|
1303
1406
|
async function getProduct(client, options) {
|
|
1304
|
-
const { handle, metafieldIdentifiers } = options;
|
|
1407
|
+
const { handle, graphqlQuery, metafieldIdentifiers } = options;
|
|
1408
|
+
const query = graphqlQuery || getProductQuery2;
|
|
1305
1409
|
const variables = { handle };
|
|
1306
|
-
|
|
1307
|
-
variables
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1410
|
+
const data = await client.query(query, {
|
|
1411
|
+
...variables,
|
|
1412
|
+
...constructMetafieldIdentifiersQueryParams(
|
|
1413
|
+
metafieldIdentifiers,
|
|
1414
|
+
client.getConfig().getMetafieldNamespacePrefix()
|
|
1415
|
+
)
|
|
1416
|
+
});
|
|
1311
1417
|
if (!data?.product) {
|
|
1312
1418
|
return void 0;
|
|
1313
1419
|
}
|
|
@@ -1361,8 +1467,9 @@ var getAllProductsQuery = (
|
|
|
1361
1467
|
${imageFragment}
|
|
1362
1468
|
`
|
|
1363
1469
|
);
|
|
1364
|
-
async function
|
|
1365
|
-
const { first = 250, query, sortKey, reverse, metafieldIdentifiers } = options;
|
|
1470
|
+
async function fetchAllProducts(client, options, afterCursor) {
|
|
1471
|
+
const { first = 250, query, graphqlQuery, sortKey, reverse, metafieldIdentifiers } = options;
|
|
1472
|
+
const queryString = graphqlQuery || getAllProductsQuery;
|
|
1366
1473
|
const variables = {
|
|
1367
1474
|
first,
|
|
1368
1475
|
after: afterCursor,
|
|
@@ -1370,26 +1477,37 @@ async function fetchAllPages(client, options, afterCursor) {
|
|
|
1370
1477
|
sortKey,
|
|
1371
1478
|
reverse
|
|
1372
1479
|
};
|
|
1373
|
-
|
|
1374
|
-
variables
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1480
|
+
const data = await client.query(queryString, {
|
|
1481
|
+
...variables,
|
|
1482
|
+
...constructMetafieldIdentifiersQueryParams(
|
|
1483
|
+
metafieldIdentifiers,
|
|
1484
|
+
client.getConfig().getMetafieldNamespacePrefix()
|
|
1485
|
+
)
|
|
1486
|
+
});
|
|
1378
1487
|
if (!data || !data.products) {
|
|
1379
1488
|
return [];
|
|
1380
1489
|
}
|
|
1381
1490
|
const products = data.products.edges.map((edge) => normalizeProduct(edge.node));
|
|
1382
1491
|
if (data.products.pageInfo.hasNextPage) {
|
|
1383
|
-
const nextProducts = await
|
|
1492
|
+
const nextProducts = await fetchAllProducts(client, options, data.products.pageInfo.endCursor);
|
|
1384
1493
|
return [...products, ...nextProducts];
|
|
1385
1494
|
}
|
|
1386
1495
|
return products;
|
|
1387
1496
|
}
|
|
1388
1497
|
async function getAllProducts(client, options) {
|
|
1389
|
-
return
|
|
1498
|
+
return fetchAllProducts(client, options);
|
|
1390
1499
|
}
|
|
1391
1500
|
async function getProducts(client, options) {
|
|
1392
|
-
const {
|
|
1501
|
+
const {
|
|
1502
|
+
first = 250,
|
|
1503
|
+
after,
|
|
1504
|
+
query,
|
|
1505
|
+
graphqlQuery,
|
|
1506
|
+
sortKey,
|
|
1507
|
+
reverse,
|
|
1508
|
+
metafieldIdentifiers
|
|
1509
|
+
} = options;
|
|
1510
|
+
const queryString = graphqlQuery || getAllProductsQuery;
|
|
1393
1511
|
const variables = {
|
|
1394
1512
|
first,
|
|
1395
1513
|
after,
|
|
@@ -1401,7 +1519,7 @@ async function getProducts(client, options) {
|
|
|
1401
1519
|
variables.productMetafieldIdentifiers = metafieldIdentifiers;
|
|
1402
1520
|
variables.variantMetafieldIdentifiers = metafieldIdentifiers;
|
|
1403
1521
|
}
|
|
1404
|
-
const data = await client.query(
|
|
1522
|
+
const data = await client.query(queryString, variables);
|
|
1405
1523
|
if (!data || !data.products) {
|
|
1406
1524
|
return {
|
|
1407
1525
|
products: [],
|
|
@@ -1451,11 +1569,11 @@ function buildProductsByHandlesQuery(handles) {
|
|
|
1451
1569
|
);
|
|
1452
1570
|
}
|
|
1453
1571
|
async function getProductsByHandles(client, options) {
|
|
1454
|
-
const { handles, metafieldIdentifiers } = options;
|
|
1572
|
+
const { handles, graphqlQuery, metafieldIdentifiers } = options;
|
|
1455
1573
|
if (!handles || handles.length === 0) {
|
|
1456
1574
|
return [];
|
|
1457
1575
|
}
|
|
1458
|
-
const query = buildProductsByHandlesQuery(handles);
|
|
1576
|
+
const query = graphqlQuery || buildProductsByHandlesQuery(handles);
|
|
1459
1577
|
const data = await client.query(query, {
|
|
1460
1578
|
handles,
|
|
1461
1579
|
// 请勿删除,这个参数虽然没有在 query 中使用,但方便在 chrome dev tools 中查看请求参数
|
|
@@ -1576,7 +1694,8 @@ function normalizeCart(cart) {
|
|
|
1576
1694
|
|
|
1577
1695
|
// src/api/cart/get-cart.ts
|
|
1578
1696
|
async function getCart(client, options) {
|
|
1579
|
-
const { id, cookieAdapter, metafieldIdentifiers } = options;
|
|
1697
|
+
const { id, cookieAdapter, graphqlQuery, metafieldIdentifiers } = options;
|
|
1698
|
+
const query = graphqlQuery || getCartQuery;
|
|
1580
1699
|
const locale = client.getLocale();
|
|
1581
1700
|
const cartId = id || cookieAdapter?.getCartId(locale);
|
|
1582
1701
|
console.log("cartId", cartId);
|
|
@@ -1584,7 +1703,7 @@ async function getCart(client, options) {
|
|
|
1584
1703
|
return void 0;
|
|
1585
1704
|
}
|
|
1586
1705
|
try {
|
|
1587
|
-
const data = await client.query(
|
|
1706
|
+
const data = await client.query(query, {
|
|
1588
1707
|
cartId,
|
|
1589
1708
|
...constructMetafieldIdentifiersQueryParams(
|
|
1590
1709
|
metafieldIdentifiers,
|
|
@@ -1619,12 +1738,14 @@ async function createCart(client, options = {}) {
|
|
|
1619
1738
|
buyerIdentity,
|
|
1620
1739
|
discountCodes,
|
|
1621
1740
|
customAttributes,
|
|
1741
|
+
graphqlQuery,
|
|
1622
1742
|
metafieldIdentifiers,
|
|
1623
1743
|
updateCookie = false
|
|
1624
1744
|
} = options;
|
|
1745
|
+
const query = graphqlQuery || createCartMutation;
|
|
1625
1746
|
const locale = client.getLocale();
|
|
1626
1747
|
try {
|
|
1627
|
-
const data = await client.query(
|
|
1748
|
+
const data = await client.query(query, {
|
|
1628
1749
|
lines,
|
|
1629
1750
|
buyerIdentity,
|
|
1630
1751
|
discountCodes,
|
|
@@ -1654,7 +1775,8 @@ async function createCart(client, options = {}) {
|
|
|
1654
1775
|
|
|
1655
1776
|
// src/api/cart/add-cart-lines.ts
|
|
1656
1777
|
async function addCartLines(client, options) {
|
|
1657
|
-
const { cartId: providedCartId, lines, cookieAdapter, metafieldIdentifiers } = options;
|
|
1778
|
+
const { cartId: providedCartId, lines, cookieAdapter, graphqlQuery, metafieldIdentifiers } = options;
|
|
1779
|
+
const query = graphqlQuery || addCartItemsMutation;
|
|
1658
1780
|
const locale = client.getLocale();
|
|
1659
1781
|
const cartId = providedCartId || cookieAdapter?.getCartId(locale);
|
|
1660
1782
|
if (!cartId) {
|
|
@@ -1665,7 +1787,7 @@ async function addCartLines(client, options) {
|
|
|
1665
1787
|
client.getConfig().getMetafieldNamespacePrefix()
|
|
1666
1788
|
);
|
|
1667
1789
|
try {
|
|
1668
|
-
const data = await client.query(
|
|
1790
|
+
const data = await client.query(query, {
|
|
1669
1791
|
cartId,
|
|
1670
1792
|
lines,
|
|
1671
1793
|
...normalizedMetafieldIdentifiers
|
|
@@ -1690,7 +1812,8 @@ async function addCartLines(client, options) {
|
|
|
1690
1812
|
|
|
1691
1813
|
// src/api/cart/update-cart-lines.ts
|
|
1692
1814
|
async function updateCartLines(client, options) {
|
|
1693
|
-
const { cartId: providedCartId, lines, cookieAdapter, metafieldIdentifiers } = options;
|
|
1815
|
+
const { cartId: providedCartId, lines, cookieAdapter, graphqlQuery, metafieldIdentifiers } = options;
|
|
1816
|
+
const query = graphqlQuery || updateCartItemsMutation;
|
|
1694
1817
|
const locale = client.getLocale();
|
|
1695
1818
|
const cartId = providedCartId || cookieAdapter?.getCartId(locale);
|
|
1696
1819
|
if (!cartId) {
|
|
@@ -1703,7 +1826,7 @@ async function updateCartLines(client, options) {
|
|
|
1703
1826
|
console.log("update-cart-lines metafieldIdentifiers:", metafieldIdentifiers);
|
|
1704
1827
|
console.log("update-cart-lines metafieldParams:", metafieldParams);
|
|
1705
1828
|
try {
|
|
1706
|
-
const data = await client.query(
|
|
1829
|
+
const data = await client.query(query, {
|
|
1707
1830
|
cartId,
|
|
1708
1831
|
lines,
|
|
1709
1832
|
...metafieldParams
|
|
@@ -1737,14 +1860,15 @@ async function updateCartLines(client, options) {
|
|
|
1737
1860
|
|
|
1738
1861
|
// src/api/cart/remove-cart-lines.ts
|
|
1739
1862
|
async function removeCartLines(client, options) {
|
|
1740
|
-
const { cartId: providedCartId, lineIds, cookieAdapter, metafieldIdentifiers } = options;
|
|
1863
|
+
const { cartId: providedCartId, lineIds, cookieAdapter, graphqlQuery, metafieldIdentifiers } = options;
|
|
1864
|
+
const query = graphqlQuery || removeCartItemsMutation;
|
|
1741
1865
|
const locale = client.getLocale();
|
|
1742
1866
|
const cartId = providedCartId || cookieAdapter?.getCartId(locale);
|
|
1743
1867
|
if (!cartId) {
|
|
1744
1868
|
throw new Error("Invalid input used for this operation: Miss cartId");
|
|
1745
1869
|
}
|
|
1746
1870
|
try {
|
|
1747
|
-
const data = await client.query(
|
|
1871
|
+
const data = await client.query(query, {
|
|
1748
1872
|
cartId,
|
|
1749
1873
|
lineIds,
|
|
1750
1874
|
...constructMetafieldIdentifiersQueryParams(
|
|
@@ -1771,14 +1895,15 @@ async function removeCartLines(client, options) {
|
|
|
1771
1895
|
|
|
1772
1896
|
// src/api/cart/update-cart-codes.ts
|
|
1773
1897
|
async function updateCartCodes(client, options) {
|
|
1774
|
-
const { cartId: providedCartId, discountCodes, cookieAdapter, metafieldIdentifiers } = options;
|
|
1898
|
+
const { cartId: providedCartId, discountCodes, cookieAdapter, graphqlQuery, metafieldIdentifiers } = options;
|
|
1899
|
+
const query = graphqlQuery || updateCartDiscountCodeMutation;
|
|
1775
1900
|
const locale = client.getLocale();
|
|
1776
1901
|
const cartId = providedCartId || cookieAdapter?.getCartId(locale);
|
|
1777
1902
|
if (!cartId) {
|
|
1778
1903
|
throw new Error("Invalid input used for this operation: Miss cartId");
|
|
1779
1904
|
}
|
|
1780
1905
|
try {
|
|
1781
|
-
const data = await client.query(
|
|
1906
|
+
const data = await client.query(query, {
|
|
1782
1907
|
cartId,
|
|
1783
1908
|
discountCodes,
|
|
1784
1909
|
...constructMetafieldIdentifiersQueryParams(
|
|
@@ -1802,14 +1927,15 @@ async function updateCartCodes(client, options) {
|
|
|
1802
1927
|
|
|
1803
1928
|
// src/api/cart/update-cart-attributes.ts
|
|
1804
1929
|
async function updateCartAttributes(client, options) {
|
|
1805
|
-
const { cartId: providedCartId, attributes, cookieAdapter, metafieldIdentifiers } = options;
|
|
1930
|
+
const { cartId: providedCartId, attributes, cookieAdapter, graphqlQuery, metafieldIdentifiers } = options;
|
|
1931
|
+
const query = graphqlQuery || updateCartAttributesMutation;
|
|
1806
1932
|
const locale = client.getLocale();
|
|
1807
1933
|
const cartId = providedCartId || cookieAdapter?.getCartId(locale);
|
|
1808
1934
|
if (!cartId) {
|
|
1809
1935
|
throw new Error("Invalid input used for this operation: Miss cartId");
|
|
1810
1936
|
}
|
|
1811
1937
|
try {
|
|
1812
|
-
const data = await client.query(
|
|
1938
|
+
const data = await client.query(query, {
|
|
1813
1939
|
cartId,
|
|
1814
1940
|
attributes,
|
|
1815
1941
|
...constructMetafieldIdentifiersQueryParams(
|
|
@@ -1836,14 +1962,15 @@ async function updateCartAttributes(client, options) {
|
|
|
1836
1962
|
|
|
1837
1963
|
// src/api/cart/update-cart-delivery-options.ts
|
|
1838
1964
|
async function updateCartDeliveryOptions(client, options) {
|
|
1839
|
-
const { cartId: providedCartId, selectedDeliveryOptions, cookieAdapter, metafieldIdentifiers } = options;
|
|
1965
|
+
const { cartId: providedCartId, selectedDeliveryOptions, cookieAdapter, graphqlQuery, metafieldIdentifiers } = options;
|
|
1966
|
+
const query = graphqlQuery || updateCartDeliveryOptionsMutation;
|
|
1840
1967
|
const locale = client.getLocale();
|
|
1841
1968
|
const cartId = providedCartId || cookieAdapter?.getCartId(locale);
|
|
1842
1969
|
if (!cartId) {
|
|
1843
1970
|
throw new Error("Invalid input used for this operation: Miss cartId");
|
|
1844
1971
|
}
|
|
1845
1972
|
try {
|
|
1846
|
-
const data = await client.query(
|
|
1973
|
+
const data = await client.query(query, {
|
|
1847
1974
|
cartId,
|
|
1848
1975
|
selectedDeliveryOptions,
|
|
1849
1976
|
...constructMetafieldIdentifiersQueryParams(
|
|
@@ -1870,14 +1997,15 @@ async function updateCartDeliveryOptions(client, options) {
|
|
|
1870
1997
|
|
|
1871
1998
|
// src/api/cart/update-buyer-identity.ts
|
|
1872
1999
|
async function updateBuyerIdentity(client, options) {
|
|
1873
|
-
const { cartId: providedCartId, buyerIdentity, cookieAdapter, metafieldIdentifiers } = options;
|
|
2000
|
+
const { cartId: providedCartId, buyerIdentity, cookieAdapter, graphqlQuery, metafieldIdentifiers } = options;
|
|
2001
|
+
const query = graphqlQuery || updateBuyerIdentityMutation;
|
|
1874
2002
|
const locale = client.getLocale();
|
|
1875
2003
|
const cartId = providedCartId || cookieAdapter?.getCartId(locale);
|
|
1876
2004
|
if (!cartId) {
|
|
1877
2005
|
throw new Error("Invalid input used for this operation: Miss cartId");
|
|
1878
2006
|
}
|
|
1879
2007
|
try {
|
|
1880
|
-
const data = await client.query(
|
|
2008
|
+
const data = await client.query(query, {
|
|
1881
2009
|
cartId,
|
|
1882
2010
|
buyerIdentity,
|
|
1883
2011
|
...constructMetafieldIdentifiersQueryParams(
|
|
@@ -1948,12 +2076,16 @@ var getCollectionQuery = (
|
|
|
1948
2076
|
`
|
|
1949
2077
|
);
|
|
1950
2078
|
async function getCollection(client, options) {
|
|
1951
|
-
const { handle, metafieldIdentifiers } = options;
|
|
2079
|
+
const { handle, graphqlQuery, metafieldIdentifiers } = options;
|
|
2080
|
+
const query = graphqlQuery || getCollectionQuery;
|
|
1952
2081
|
const variables = { handle };
|
|
1953
|
-
|
|
1954
|
-
variables
|
|
1955
|
-
|
|
1956
|
-
|
|
2082
|
+
const data = await client.query(query, {
|
|
2083
|
+
...variables,
|
|
2084
|
+
...constructMetafieldIdentifiersQueryParams(
|
|
2085
|
+
metafieldIdentifiers,
|
|
2086
|
+
client.getConfig().getMetafieldNamespacePrefix()
|
|
2087
|
+
)
|
|
2088
|
+
});
|
|
1957
2089
|
if (!data?.collection) {
|
|
1958
2090
|
return void 0;
|
|
1959
2091
|
}
|
|
@@ -1995,8 +2127,9 @@ var getAllCollectionsQuery = (
|
|
|
1995
2127
|
${imageFragment}
|
|
1996
2128
|
`
|
|
1997
2129
|
);
|
|
1998
|
-
async function
|
|
1999
|
-
const { first = 250, query, sortKey, reverse, metafieldIdentifiers } = options;
|
|
2130
|
+
async function fetchAllPages(client, options, afterCursor) {
|
|
2131
|
+
const { first = 250, query, graphqlQuery, sortKey, reverse, metafieldIdentifiers } = options;
|
|
2132
|
+
const queryString = graphqlQuery || getAllCollectionsQuery;
|
|
2000
2133
|
const variables = {
|
|
2001
2134
|
first,
|
|
2002
2135
|
after: afterCursor,
|
|
@@ -2004,25 +2137,41 @@ async function fetchAllPages2(client, options, afterCursor) {
|
|
|
2004
2137
|
sortKey,
|
|
2005
2138
|
reverse
|
|
2006
2139
|
};
|
|
2007
|
-
|
|
2008
|
-
variables
|
|
2009
|
-
|
|
2010
|
-
|
|
2140
|
+
const data = await client.query(queryString, {
|
|
2141
|
+
...variables,
|
|
2142
|
+
...constructMetafieldIdentifiersQueryParams(
|
|
2143
|
+
metafieldIdentifiers,
|
|
2144
|
+
client.getConfig().getMetafieldNamespacePrefix()
|
|
2145
|
+
)
|
|
2146
|
+
});
|
|
2011
2147
|
if (!data || !data.collections) {
|
|
2012
2148
|
return [];
|
|
2013
2149
|
}
|
|
2014
2150
|
const collections = data.collections.edges.map((edge) => normalizeCollection(edge.node));
|
|
2015
2151
|
if (data.collections.pageInfo.hasNextPage) {
|
|
2016
|
-
const nextCollections = await
|
|
2152
|
+
const nextCollections = await fetchAllPages(
|
|
2153
|
+
client,
|
|
2154
|
+
options,
|
|
2155
|
+
data.collections.pageInfo.endCursor
|
|
2156
|
+
);
|
|
2017
2157
|
return [...collections, ...nextCollections];
|
|
2018
2158
|
}
|
|
2019
2159
|
return collections;
|
|
2020
2160
|
}
|
|
2021
2161
|
async function getAllCollections(client, options) {
|
|
2022
|
-
return
|
|
2162
|
+
return fetchAllPages(client, options);
|
|
2023
2163
|
}
|
|
2024
2164
|
async function getCollections(client, options) {
|
|
2025
|
-
const {
|
|
2165
|
+
const {
|
|
2166
|
+
first = 250,
|
|
2167
|
+
after,
|
|
2168
|
+
query,
|
|
2169
|
+
graphqlQuery,
|
|
2170
|
+
sortKey,
|
|
2171
|
+
reverse,
|
|
2172
|
+
metafieldIdentifiers
|
|
2173
|
+
} = options;
|
|
2174
|
+
const queryString = graphqlQuery || getAllCollectionsQuery;
|
|
2026
2175
|
const variables = {
|
|
2027
2176
|
first,
|
|
2028
2177
|
after,
|
|
@@ -2030,10 +2179,13 @@ async function getCollections(client, options) {
|
|
|
2030
2179
|
sortKey,
|
|
2031
2180
|
reverse
|
|
2032
2181
|
};
|
|
2033
|
-
|
|
2034
|
-
variables
|
|
2035
|
-
|
|
2036
|
-
|
|
2182
|
+
const data = await client.query(queryString, {
|
|
2183
|
+
...variables,
|
|
2184
|
+
...constructMetafieldIdentifiersQueryParams(
|
|
2185
|
+
metafieldIdentifiers,
|
|
2186
|
+
client.getConfig().getMetafieldNamespacePrefix()
|
|
2187
|
+
)
|
|
2188
|
+
});
|
|
2037
2189
|
if (!data || !data.collections) {
|
|
2038
2190
|
return {
|
|
2039
2191
|
collections: [],
|
|
@@ -2051,15 +2203,12 @@ async function getCollections(client, options) {
|
|
|
2051
2203
|
}
|
|
2052
2204
|
|
|
2053
2205
|
// src/api/collection/get-collections-by-handles.ts
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
options
|
|
2057
|
-
}) => {
|
|
2058
|
-
const { handles, metafieldIdentifiers } = options;
|
|
2206
|
+
async function getCollectionsByHandles(client, options) {
|
|
2207
|
+
const { handles, graphqlQuery, metafieldIdentifiers } = options;
|
|
2059
2208
|
if (handles.length === 0) {
|
|
2060
2209
|
return [];
|
|
2061
2210
|
}
|
|
2062
|
-
const query = getCollectionsByHandlesQuery(handles);
|
|
2211
|
+
const query = graphqlQuery || getCollectionsByHandlesQuery(handles);
|
|
2063
2212
|
const data = await client.query(query, {
|
|
2064
2213
|
handles,
|
|
2065
2214
|
// 请勿删除,这个参数虽然没有在 query 中使用,但方便在 chrome dev tools 中查看请求参数
|
|
@@ -2078,7 +2227,7 @@ var getCollectionsByHandles = async ({
|
|
|
2078
2227
|
return normalizeCollection(item);
|
|
2079
2228
|
});
|
|
2080
2229
|
return collections;
|
|
2081
|
-
}
|
|
2230
|
+
}
|
|
2082
2231
|
|
|
2083
2232
|
// src/api/blog/normalize.ts
|
|
2084
2233
|
function normalizeBlog(blog) {
|
|
@@ -2124,28 +2273,34 @@ function normalizeMetafields2(metafields) {
|
|
|
2124
2273
|
|
|
2125
2274
|
// src/api/blog/get-blog.ts
|
|
2126
2275
|
async function getBlog(client, options) {
|
|
2127
|
-
const { handle, metafieldIdentifiers } = options;
|
|
2128
|
-
const hasMetafields = metafieldIdentifiers
|
|
2276
|
+
const { handle, graphqlQuery, metafieldIdentifiers } = options;
|
|
2277
|
+
const hasMetafields = metafieldIdentifiers?.blog?.length;
|
|
2129
2278
|
const fragment = hasMetafields ? blogWithMetafieldsFragment : blogFragment;
|
|
2130
|
-
const
|
|
2279
|
+
const defaultQuery = (
|
|
2131
2280
|
/* GraphQL */
|
|
2132
2281
|
`
|
|
2133
2282
|
query getBlog(
|
|
2134
2283
|
$handle: String!
|
|
2135
2284
|
${hasMetafields ? "$blogMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
|
|
2136
|
-
)
|
|
2285
|
+
) {
|
|
2137
2286
|
blog(handle: $handle) {
|
|
2138
2287
|
...${hasMetafields ? "blogWithMetafields" : "blog"}
|
|
2139
2288
|
}
|
|
2140
2289
|
}
|
|
2290
|
+
${hasMetafields ? metafieldFragment : ""}
|
|
2291
|
+
${seoFragment}
|
|
2141
2292
|
${fragment}
|
|
2142
2293
|
`
|
|
2143
2294
|
);
|
|
2295
|
+
const query = graphqlQuery || defaultQuery;
|
|
2144
2296
|
const variables = { handle };
|
|
2145
|
-
|
|
2146
|
-
variables
|
|
2147
|
-
|
|
2148
|
-
|
|
2297
|
+
const data = await client.query(query, {
|
|
2298
|
+
...variables,
|
|
2299
|
+
...constructMetafieldIdentifiersQueryParams(
|
|
2300
|
+
metafieldIdentifiers,
|
|
2301
|
+
client.getConfig().getMetafieldNamespacePrefix()
|
|
2302
|
+
)
|
|
2303
|
+
});
|
|
2149
2304
|
if (!data || !data.blog) {
|
|
2150
2305
|
return void 0;
|
|
2151
2306
|
}
|
|
@@ -2153,11 +2308,11 @@ async function getBlog(client, options) {
|
|
|
2153
2308
|
}
|
|
2154
2309
|
|
|
2155
2310
|
// src/api/blog/get-all-blogs.ts
|
|
2156
|
-
async function
|
|
2157
|
-
const { first = 250, query, metafieldIdentifiers } = options;
|
|
2158
|
-
const hasMetafields = metafieldIdentifiers
|
|
2311
|
+
async function fetchAllPages2(client, options, afterCursor) {
|
|
2312
|
+
const { first = 250, query, graphqlQuery, metafieldIdentifiers } = options;
|
|
2313
|
+
const hasMetafields = !!metafieldIdentifiers?.blog?.length;
|
|
2159
2314
|
const fragment = hasMetafields ? blogWithMetafieldsFragment : blogFragment;
|
|
2160
|
-
const
|
|
2315
|
+
const defaultQueryString = (
|
|
2161
2316
|
/* GraphQL */
|
|
2162
2317
|
`
|
|
2163
2318
|
query getAllBlogs(
|
|
@@ -2165,7 +2320,7 @@ async function fetchAllPages3(client, options, afterCursor) {
|
|
|
2165
2320
|
$after: String
|
|
2166
2321
|
${query ? "$query: String!" : ""}
|
|
2167
2322
|
${hasMetafields ? "$blogMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
|
|
2168
|
-
)
|
|
2323
|
+
) {
|
|
2169
2324
|
blogs(
|
|
2170
2325
|
first: $first
|
|
2171
2326
|
after: $after
|
|
@@ -2181,67 +2336,80 @@ async function fetchAllPages3(client, options, afterCursor) {
|
|
|
2181
2336
|
}
|
|
2182
2337
|
}
|
|
2183
2338
|
}
|
|
2339
|
+
${hasMetafields ? metafieldFragment : ""}
|
|
2340
|
+
${seoFragment}
|
|
2184
2341
|
${fragment}
|
|
2185
2342
|
${pageInfoFragment}
|
|
2186
2343
|
`
|
|
2187
2344
|
);
|
|
2345
|
+
const queryString = graphqlQuery || defaultQueryString;
|
|
2188
2346
|
const variables = { first, after: afterCursor };
|
|
2189
2347
|
if (query) {
|
|
2190
2348
|
variables.query = query;
|
|
2191
2349
|
}
|
|
2192
|
-
|
|
2193
|
-
variables
|
|
2194
|
-
|
|
2195
|
-
|
|
2350
|
+
const data = await client.query(queryString, {
|
|
2351
|
+
...variables,
|
|
2352
|
+
...constructMetafieldIdentifiersQueryParams(
|
|
2353
|
+
metafieldIdentifiers,
|
|
2354
|
+
client.getConfig().getMetafieldNamespacePrefix()
|
|
2355
|
+
)
|
|
2356
|
+
});
|
|
2196
2357
|
if (!data || !data.blogs) {
|
|
2197
2358
|
return [];
|
|
2198
2359
|
}
|
|
2199
2360
|
const blogs = data.blogs.edges?.map((edge) => normalizeBlog(edge.node)) || [];
|
|
2200
2361
|
if (data.blogs.pageInfo.hasNextPage) {
|
|
2201
|
-
const nextBlogs = await
|
|
2362
|
+
const nextBlogs = await fetchAllPages2(client, options, data.blogs.pageInfo.endCursor);
|
|
2202
2363
|
return [...blogs, ...nextBlogs];
|
|
2203
2364
|
}
|
|
2204
2365
|
return blogs;
|
|
2205
2366
|
}
|
|
2206
2367
|
async function getAllBlogs(client, options) {
|
|
2207
|
-
return
|
|
2368
|
+
return fetchAllPages2(client, options);
|
|
2208
2369
|
}
|
|
2209
2370
|
|
|
2210
2371
|
// src/api/blog/get-article.ts
|
|
2211
2372
|
async function getArticle(client, options) {
|
|
2212
|
-
const { blogHandle, articleHandle, metafieldIdentifiers } = options;
|
|
2213
|
-
const
|
|
2214
|
-
const
|
|
2215
|
-
const
|
|
2216
|
-
const
|
|
2373
|
+
const { blogHandle, articleHandle, graphqlQuery, metafieldIdentifiers } = options;
|
|
2374
|
+
const hasArticleMetafields = !!metafieldIdentifiers?.article?.length;
|
|
2375
|
+
const hasBlogMetafields = !!metafieldIdentifiers?.blog?.length;
|
|
2376
|
+
const articleFrag = hasArticleMetafields ? articleWithMetafieldsFragment : articleFragment;
|
|
2377
|
+
const blogFrag = hasBlogMetafields ? blogWithMetafieldsFragment : blogFragment;
|
|
2378
|
+
const defaultQuery = (
|
|
2217
2379
|
/* GraphQL */
|
|
2218
2380
|
`
|
|
2219
2381
|
query getArticle(
|
|
2220
2382
|
$blogHandle: String!
|
|
2221
2383
|
$articleHandle: String!
|
|
2222
|
-
${
|
|
2223
|
-
${
|
|
2224
|
-
)
|
|
2384
|
+
${hasBlogMetafields ? "$blogMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
|
|
2385
|
+
${hasArticleMetafields ? "$articleMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
|
|
2386
|
+
) {
|
|
2225
2387
|
blog(handle: $blogHandle) {
|
|
2226
|
-
...${
|
|
2388
|
+
...${hasBlogMetafields ? "blogWithMetafields" : "blog"}
|
|
2227
2389
|
articleByHandle(handle: $articleHandle) {
|
|
2228
|
-
...${
|
|
2390
|
+
...${hasArticleMetafields ? "articleWithMetafields" : "article"}
|
|
2229
2391
|
blog {
|
|
2230
|
-
...${
|
|
2392
|
+
...${hasBlogMetafields ? "blogWithMetafields" : "blog"}
|
|
2231
2393
|
}
|
|
2232
2394
|
}
|
|
2233
2395
|
}
|
|
2234
2396
|
}
|
|
2397
|
+
${imageFragment}
|
|
2398
|
+
${hasArticleMetafields || hasBlogMetafields ? metafieldFragment : ""}
|
|
2399
|
+
${seoFragment}
|
|
2235
2400
|
${articleFrag}
|
|
2236
2401
|
${blogFrag}
|
|
2237
2402
|
`
|
|
2238
2403
|
);
|
|
2404
|
+
const query = graphqlQuery || defaultQuery;
|
|
2239
2405
|
const variables = { blogHandle, articleHandle };
|
|
2240
|
-
|
|
2241
|
-
variables
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2406
|
+
const data = await client.query(query, {
|
|
2407
|
+
...variables,
|
|
2408
|
+
...constructMetafieldIdentifiersQueryParams(
|
|
2409
|
+
metafieldIdentifiers,
|
|
2410
|
+
client.getConfig().getMetafieldNamespacePrefix()
|
|
2411
|
+
)
|
|
2412
|
+
});
|
|
2245
2413
|
if (!data || !data.blog || !data.blog.articleByHandle) {
|
|
2246
2414
|
return void 0;
|
|
2247
2415
|
}
|
|
@@ -2249,11 +2417,18 @@ async function getArticle(client, options) {
|
|
|
2249
2417
|
}
|
|
2250
2418
|
|
|
2251
2419
|
// src/api/blog/get-articles.ts
|
|
2252
|
-
async function
|
|
2253
|
-
const {
|
|
2254
|
-
|
|
2420
|
+
async function fetchAllArticles(client, options, afterCursor) {
|
|
2421
|
+
const {
|
|
2422
|
+
first = 250,
|
|
2423
|
+
query,
|
|
2424
|
+
graphqlQuery,
|
|
2425
|
+
sortKey = "PUBLISHED_AT",
|
|
2426
|
+
reverse = false,
|
|
2427
|
+
metafieldIdentifiers
|
|
2428
|
+
} = options;
|
|
2429
|
+
const hasMetafields = !!metafieldIdentifiers?.article?.length;
|
|
2255
2430
|
const fragment = hasMetafields ? articleWithMetafieldsFragment : articleFragment;
|
|
2256
|
-
const
|
|
2431
|
+
const defaultQueryString = (
|
|
2257
2432
|
/* GraphQL */
|
|
2258
2433
|
`
|
|
2259
2434
|
query getArticles(
|
|
@@ -2263,7 +2438,7 @@ async function fetchAllPages4(client, options, afterCursor) {
|
|
|
2263
2438
|
$sortKey: ArticleSortKeys!
|
|
2264
2439
|
$reverse: Boolean!
|
|
2265
2440
|
${hasMetafields ? "$articleMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
|
|
2266
|
-
)
|
|
2441
|
+
) {
|
|
2267
2442
|
articles(
|
|
2268
2443
|
first: $first
|
|
2269
2444
|
after: $after
|
|
@@ -2281,10 +2456,14 @@ async function fetchAllPages4(client, options, afterCursor) {
|
|
|
2281
2456
|
}
|
|
2282
2457
|
}
|
|
2283
2458
|
}
|
|
2459
|
+
${imageFragment}
|
|
2460
|
+
${hasMetafields ? metafieldFragment : ""}
|
|
2461
|
+
${seoFragment}
|
|
2284
2462
|
${fragment}
|
|
2285
2463
|
${pageInfoFragment}
|
|
2286
2464
|
`
|
|
2287
2465
|
);
|
|
2466
|
+
const queryString = graphqlQuery || defaultQueryString;
|
|
2288
2467
|
const variables = {
|
|
2289
2468
|
first,
|
|
2290
2469
|
after: afterCursor,
|
|
@@ -2294,31 +2473,42 @@ async function fetchAllPages4(client, options, afterCursor) {
|
|
|
2294
2473
|
if (query) {
|
|
2295
2474
|
variables.query = query;
|
|
2296
2475
|
}
|
|
2297
|
-
|
|
2298
|
-
variables
|
|
2299
|
-
|
|
2300
|
-
|
|
2476
|
+
const data = await client.query(queryString, {
|
|
2477
|
+
...variables,
|
|
2478
|
+
...constructMetafieldIdentifiersQueryParams(
|
|
2479
|
+
metafieldIdentifiers,
|
|
2480
|
+
client.getConfig().getMetafieldNamespacePrefix()
|
|
2481
|
+
)
|
|
2482
|
+
});
|
|
2301
2483
|
if (!data || !data.articles) {
|
|
2302
2484
|
return [];
|
|
2303
2485
|
}
|
|
2304
2486
|
const articles = data.articles.edges?.map((edge) => normalizeArticle(edge.node)) || [];
|
|
2305
2487
|
if (data.articles.pageInfo.hasNextPage) {
|
|
2306
|
-
const nextArticles = await
|
|
2488
|
+
const nextArticles = await fetchAllArticles(client, options, data.articles.pageInfo.endCursor);
|
|
2307
2489
|
return [...articles, ...nextArticles];
|
|
2308
2490
|
}
|
|
2309
2491
|
return articles;
|
|
2310
2492
|
}
|
|
2311
2493
|
async function getArticles(client, options) {
|
|
2312
|
-
return
|
|
2494
|
+
return fetchAllArticles(client, options);
|
|
2313
2495
|
}
|
|
2314
2496
|
|
|
2315
2497
|
// src/api/blog/get-articles-in-blog.ts
|
|
2316
|
-
async function
|
|
2317
|
-
const {
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2498
|
+
async function fetchArticlesInBlog(client, options, afterCursor) {
|
|
2499
|
+
const {
|
|
2500
|
+
blogHandle,
|
|
2501
|
+
first = 250,
|
|
2502
|
+
graphqlQuery,
|
|
2503
|
+
sortKey = "PUBLISHED_AT",
|
|
2504
|
+
reverse = false,
|
|
2505
|
+
metafieldIdentifiers
|
|
2506
|
+
} = options;
|
|
2507
|
+
const hasArticleMetafields = !!metafieldIdentifiers?.article?.length;
|
|
2508
|
+
const hasBlogMetafields = !!metafieldIdentifiers?.blog?.length;
|
|
2509
|
+
const articleFrag = hasArticleMetafields ? articleWithMetafieldsFragment : articleFragment;
|
|
2510
|
+
const blogFrag = hasBlogMetafields ? blogWithMetafieldsFragment : blogFragment;
|
|
2511
|
+
const defaultQuery = (
|
|
2322
2512
|
/* GraphQL */
|
|
2323
2513
|
`
|
|
2324
2514
|
query getArticlesInBlog(
|
|
@@ -2327,11 +2517,11 @@ async function fetchAllPages5(client, options, afterCursor) {
|
|
|
2327
2517
|
$after: String
|
|
2328
2518
|
$sortKey: ArticleSortKeys!
|
|
2329
2519
|
$reverse: Boolean!
|
|
2330
|
-
${
|
|
2331
|
-
${
|
|
2332
|
-
)
|
|
2520
|
+
${hasBlogMetafields ? "$blogMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
|
|
2521
|
+
${hasArticleMetafields ? "$articleMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
|
|
2522
|
+
) {
|
|
2333
2523
|
blog(handle: $blogHandle) {
|
|
2334
|
-
...${
|
|
2524
|
+
...${hasBlogMetafields ? "blogWithMetafields" : "blog"}
|
|
2335
2525
|
articles(
|
|
2336
2526
|
first: $first
|
|
2337
2527
|
after: $after
|
|
@@ -2340,7 +2530,7 @@ async function fetchAllPages5(client, options, afterCursor) {
|
|
|
2340
2530
|
) {
|
|
2341
2531
|
edges {
|
|
2342
2532
|
node {
|
|
2343
|
-
...${
|
|
2533
|
+
...${hasArticleMetafields ? "articleWithMetafields" : "article"}
|
|
2344
2534
|
}
|
|
2345
2535
|
}
|
|
2346
2536
|
pageInfo {
|
|
@@ -2349,11 +2539,15 @@ async function fetchAllPages5(client, options, afterCursor) {
|
|
|
2349
2539
|
}
|
|
2350
2540
|
}
|
|
2351
2541
|
}
|
|
2542
|
+
${imageFragment}
|
|
2543
|
+
${hasArticleMetafields || hasBlogMetafields ? metafieldFragment : ""}
|
|
2544
|
+
${seoFragment}
|
|
2352
2545
|
${articleFrag}
|
|
2353
2546
|
${blogFrag}
|
|
2354
2547
|
${pageInfoFragment}
|
|
2355
2548
|
`
|
|
2356
2549
|
);
|
|
2550
|
+
const query = graphqlQuery || defaultQuery;
|
|
2357
2551
|
const variables = {
|
|
2358
2552
|
blogHandle,
|
|
2359
2553
|
first,
|
|
@@ -2361,23 +2555,129 @@ async function fetchAllPages5(client, options, afterCursor) {
|
|
|
2361
2555
|
sortKey,
|
|
2362
2556
|
reverse
|
|
2363
2557
|
};
|
|
2364
|
-
|
|
2365
|
-
variables
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2558
|
+
const data = await client.query(query, {
|
|
2559
|
+
...variables,
|
|
2560
|
+
...constructMetafieldIdentifiersQueryParams(
|
|
2561
|
+
metafieldIdentifiers,
|
|
2562
|
+
client.getConfig().getMetafieldNamespacePrefix()
|
|
2563
|
+
)
|
|
2564
|
+
});
|
|
2369
2565
|
if (!data || !data.blog || !data.blog.articles) {
|
|
2370
2566
|
return [];
|
|
2371
2567
|
}
|
|
2372
2568
|
const articles = data.blog.articles.edges?.map((edge) => normalizeArticle(edge.node)) || [];
|
|
2373
2569
|
if (data.blog.articles.pageInfo.hasNextPage) {
|
|
2374
|
-
const nextArticles = await
|
|
2570
|
+
const nextArticles = await fetchArticlesInBlog(
|
|
2571
|
+
client,
|
|
2572
|
+
options,
|
|
2573
|
+
data.blog.articles.pageInfo.endCursor
|
|
2574
|
+
);
|
|
2375
2575
|
return [...articles, ...nextArticles];
|
|
2376
2576
|
}
|
|
2377
2577
|
return articles;
|
|
2378
2578
|
}
|
|
2379
2579
|
async function getArticlesInBlog(client, options) {
|
|
2380
|
-
return
|
|
2580
|
+
return fetchArticlesInBlog(client, options);
|
|
2581
|
+
}
|
|
2582
|
+
|
|
2583
|
+
// src/api/page/normalize.ts
|
|
2584
|
+
function normalizePage(page) {
|
|
2585
|
+
return {
|
|
2586
|
+
id: page.id,
|
|
2587
|
+
handle: page.handle,
|
|
2588
|
+
title: page.title,
|
|
2589
|
+
body: page.body,
|
|
2590
|
+
bodySummary: page.bodySummary,
|
|
2591
|
+
createdAt: page.createdAt,
|
|
2592
|
+
updatedAt: page.updatedAt,
|
|
2593
|
+
seo: page.seo ? {
|
|
2594
|
+
...page.seo
|
|
2595
|
+
} : void 0,
|
|
2596
|
+
metafields: normalizeMetafields(page.metafields)
|
|
2597
|
+
};
|
|
2598
|
+
}
|
|
2599
|
+
|
|
2600
|
+
// src/api/page/get-page.ts
|
|
2601
|
+
async function getPage(client, options) {
|
|
2602
|
+
const { handle, graphqlQuery, metafieldIdentifiers } = options;
|
|
2603
|
+
const hasMetafields = !!metafieldIdentifiers?.page?.length;
|
|
2604
|
+
const fragment = hasMetafields ? pageWithMetafieldsFragment : pageFragment;
|
|
2605
|
+
const defaultQuery = (
|
|
2606
|
+
/* GraphQL */
|
|
2607
|
+
`
|
|
2608
|
+
query getPage(
|
|
2609
|
+
$handle: String!
|
|
2610
|
+
${hasMetafields ? "$pageMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
|
|
2611
|
+
) {
|
|
2612
|
+
page(handle: $handle) {
|
|
2613
|
+
...${hasMetafields ? "pageWithMetafields" : "page"}
|
|
2614
|
+
}
|
|
2615
|
+
}
|
|
2616
|
+
${fragment}
|
|
2617
|
+
`
|
|
2618
|
+
);
|
|
2619
|
+
const query = graphqlQuery || defaultQuery;
|
|
2620
|
+
const variables = { handle };
|
|
2621
|
+
if (hasMetafields) {
|
|
2622
|
+
variables.pageMetafieldIdentifiers = metafieldIdentifiers;
|
|
2623
|
+
}
|
|
2624
|
+
const data = await client.query(query, {
|
|
2625
|
+
...variables,
|
|
2626
|
+
...constructMetafieldIdentifiersQueryParams(
|
|
2627
|
+
metafieldIdentifiers,
|
|
2628
|
+
client.getConfig().getMetafieldNamespacePrefix()
|
|
2629
|
+
)
|
|
2630
|
+
});
|
|
2631
|
+
if (!data || !data.page) {
|
|
2632
|
+
return void 0;
|
|
2633
|
+
}
|
|
2634
|
+
return normalizePage(data.page);
|
|
2635
|
+
}
|
|
2636
|
+
|
|
2637
|
+
// src/api/shop/normalize.ts
|
|
2638
|
+
function normalizeShop(shop) {
|
|
2639
|
+
return {
|
|
2640
|
+
name: shop.name,
|
|
2641
|
+
description: shop.description || "",
|
|
2642
|
+
moneyFormat: shop.moneyFormat,
|
|
2643
|
+
paymentSettings: shop.paymentSettings,
|
|
2644
|
+
primaryDomain: shop.primaryDomain,
|
|
2645
|
+
brand: shop.brand || void 0,
|
|
2646
|
+
metafields: normalizeMetafields(shop.metafields)
|
|
2647
|
+
};
|
|
2648
|
+
}
|
|
2649
|
+
|
|
2650
|
+
// src/api/shop/get-shop.ts
|
|
2651
|
+
async function getShop(client, options) {
|
|
2652
|
+
const { graphqlQuery, metafieldIdentifiers } = options;
|
|
2653
|
+
const hasMetafields = !!metafieldIdentifiers?.shop?.length;
|
|
2654
|
+
const fragment = hasMetafields ? shopWithMetafieldsFragment : shopFragment;
|
|
2655
|
+
const defaultQuery = (
|
|
2656
|
+
/* GraphQL */
|
|
2657
|
+
`
|
|
2658
|
+
query getShop(
|
|
2659
|
+
${hasMetafields ? "$shopMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
|
|
2660
|
+
) {
|
|
2661
|
+
shop {
|
|
2662
|
+
...${hasMetafields ? "shopWithMetafields" : "shop"}
|
|
2663
|
+
}
|
|
2664
|
+
}
|
|
2665
|
+
${fragment}
|
|
2666
|
+
`
|
|
2667
|
+
);
|
|
2668
|
+
const query = graphqlQuery || defaultQuery;
|
|
2669
|
+
const variables = {};
|
|
2670
|
+
const data = await client.query(query, {
|
|
2671
|
+
...variables,
|
|
2672
|
+
...constructMetafieldIdentifiersQueryParams(
|
|
2673
|
+
metafieldIdentifiers,
|
|
2674
|
+
client.getConfig().getMetafieldNamespacePrefix()
|
|
2675
|
+
)
|
|
2676
|
+
});
|
|
2677
|
+
if (!data || !data.shop) {
|
|
2678
|
+
return void 0;
|
|
2679
|
+
}
|
|
2680
|
+
return normalizeShop(data.shop);
|
|
2381
2681
|
}
|
|
2382
2682
|
|
|
2383
2683
|
exports.ShopifyClient = ShopifyClient;
|
|
@@ -2406,12 +2706,14 @@ exports.getCollection = getCollection;
|
|
|
2406
2706
|
exports.getCollections = getCollections;
|
|
2407
2707
|
exports.getCollectionsByHandles = getCollectionsByHandles;
|
|
2408
2708
|
exports.getCollectionsByHandlesQuery = getCollectionsByHandlesQuery;
|
|
2709
|
+
exports.getPage = getPage;
|
|
2409
2710
|
exports.getProduct = getProduct;
|
|
2410
2711
|
exports.getProductQuery = getProductQuery;
|
|
2411
2712
|
exports.getProducts = getProducts;
|
|
2412
2713
|
exports.getProductsByHandles = getProductsByHandles;
|
|
2413
2714
|
exports.getProductsByHandlesQuery = getProductsByHandlesQuery;
|
|
2414
2715
|
exports.getProductsQuery = getProductsQuery;
|
|
2716
|
+
exports.getShop = getShop;
|
|
2415
2717
|
exports.imageFragment = imageFragment;
|
|
2416
2718
|
exports.metafieldFragment = metafieldFragment;
|
|
2417
2719
|
exports.metafieldFragmentStr = metafieldFragmentStr;
|
|
@@ -2420,12 +2722,18 @@ exports.normalizeBlog = normalizeBlog;
|
|
|
2420
2722
|
exports.normalizeCart = normalizeCart;
|
|
2421
2723
|
exports.normalizeCollection = normalizeCollection;
|
|
2422
2724
|
exports.normalizeLineItem = normalizeLineItem;
|
|
2725
|
+
exports.normalizePage = normalizePage;
|
|
2423
2726
|
exports.normalizeProduct = normalizeProduct;
|
|
2727
|
+
exports.normalizeShop = normalizeShop;
|
|
2728
|
+
exports.pageFragment = pageFragment;
|
|
2424
2729
|
exports.pageInfoFragment = pageInfoFragment;
|
|
2730
|
+
exports.pageWithMetafieldsFragment = pageWithMetafieldsFragment;
|
|
2425
2731
|
exports.productFragment = productFragment;
|
|
2426
2732
|
exports.removeCartItemsMutation = removeCartItemsMutation;
|
|
2427
2733
|
exports.removeCartLines = removeCartLines;
|
|
2428
2734
|
exports.seoFragment = seoFragment;
|
|
2735
|
+
exports.shopFragment = shopFragment;
|
|
2736
|
+
exports.shopWithMetafieldsFragment = shopWithMetafieldsFragment;
|
|
2429
2737
|
exports.updateBuyerIdentity = updateBuyerIdentity;
|
|
2430
2738
|
exports.updateBuyerIdentityMutation = updateBuyerIdentityMutation;
|
|
2431
2739
|
exports.updateCartAttributes = updateCartAttributes;
|