@anker-in/shopify-sdk 1.2.0-beta.1 → 1.2.0-beta.10
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/index.d.mts +70 -3
- package/dist/index.d.ts +70 -3
- package/dist/index.js +172 -47
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +171 -48
- package/dist/index.mjs.map +1 -1
- package/dist/queries/index.d.mts +6 -1
- package/dist/queries/index.d.ts +6 -1
- package/dist/queries/index.js +75 -0
- package/dist/queries/index.js.map +1 -1
- package/dist/queries/index.mjs +75 -1
- package/dist/queries/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -928,6 +928,59 @@ var getCartQuery = (
|
|
|
928
928
|
`
|
|
929
929
|
);
|
|
930
930
|
|
|
931
|
+
// src/queries/collection/get-collections-by-handles.ts
|
|
932
|
+
var getCollectionsByHandlesQuery = (handles) => (
|
|
933
|
+
/* GraphQL */
|
|
934
|
+
`
|
|
935
|
+
${collectionFragment}
|
|
936
|
+
${productFragment}
|
|
937
|
+
${variantFragment}
|
|
938
|
+
${metafieldFragment}
|
|
939
|
+
${imageFragment}
|
|
940
|
+
${seoFragment}
|
|
941
|
+
|
|
942
|
+
query GetCollectionsByHandles(
|
|
943
|
+
$collectionMetafieldIdentifiers: [HasMetafieldsIdentifier!] = []
|
|
944
|
+
$productMetafieldIdentifiers: [HasMetafieldsIdentifier!] = []
|
|
945
|
+
$variantMetafieldIdentifiers: [HasMetafieldsIdentifier!] = []
|
|
946
|
+
) {
|
|
947
|
+
${handles.map(
|
|
948
|
+
(handle, index) => (
|
|
949
|
+
/* GraphQL */
|
|
950
|
+
`
|
|
951
|
+
collection_${index}: collection(handle: "${handle}") {
|
|
952
|
+
...collection
|
|
953
|
+
metafields(identifiers: $collectionMetafieldIdentifiers) {
|
|
954
|
+
...metafield
|
|
955
|
+
}
|
|
956
|
+
products(first: 9) {
|
|
957
|
+
edges {
|
|
958
|
+
node {
|
|
959
|
+
...product
|
|
960
|
+
metafields(identifiers: $productMetafieldIdentifiers) {
|
|
961
|
+
...metafield
|
|
962
|
+
}
|
|
963
|
+
variants(first: 10) {
|
|
964
|
+
edges {
|
|
965
|
+
node {
|
|
966
|
+
...variant
|
|
967
|
+
metafields(identifiers: $variantMetafieldIdentifiers) {
|
|
968
|
+
...metafield
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
`
|
|
978
|
+
)
|
|
979
|
+
).join("\n")}
|
|
980
|
+
}
|
|
981
|
+
`
|
|
982
|
+
);
|
|
983
|
+
|
|
931
984
|
// src/mutations/cart/create-cart.ts
|
|
932
985
|
var createCartMutation = (
|
|
933
986
|
/* GraphQL */
|
|
@@ -1250,13 +1303,14 @@ var getProductQuery2 = (
|
|
|
1250
1303
|
`
|
|
1251
1304
|
);
|
|
1252
1305
|
async function getProduct(client, options) {
|
|
1253
|
-
const { handle, metafieldIdentifiers } = options;
|
|
1306
|
+
const { handle, graphqlQuery, metafieldIdentifiers } = options;
|
|
1307
|
+
const query = graphqlQuery || getProductQuery2;
|
|
1254
1308
|
const variables = { handle };
|
|
1255
1309
|
if (metafieldIdentifiers) {
|
|
1256
1310
|
variables.productMetafieldIdentifiers = metafieldIdentifiers;
|
|
1257
1311
|
variables.variantMetafieldIdentifiers = metafieldIdentifiers;
|
|
1258
1312
|
}
|
|
1259
|
-
const data = await client.query(
|
|
1313
|
+
const data = await client.query(query, variables);
|
|
1260
1314
|
if (!data?.product) {
|
|
1261
1315
|
return void 0;
|
|
1262
1316
|
}
|
|
@@ -1311,7 +1365,8 @@ var getAllProductsQuery = (
|
|
|
1311
1365
|
`
|
|
1312
1366
|
);
|
|
1313
1367
|
async function fetchAllPages(client, options, afterCursor) {
|
|
1314
|
-
const { first = 250, query, sortKey, reverse, metafieldIdentifiers } = options;
|
|
1368
|
+
const { first = 250, query, graphqlQuery, sortKey, reverse, metafieldIdentifiers } = options;
|
|
1369
|
+
const queryString = graphqlQuery || getAllProductsQuery;
|
|
1315
1370
|
const variables = {
|
|
1316
1371
|
first,
|
|
1317
1372
|
after: afterCursor,
|
|
@@ -1323,7 +1378,7 @@ async function fetchAllPages(client, options, afterCursor) {
|
|
|
1323
1378
|
variables.productMetafieldIdentifiers = metafieldIdentifiers;
|
|
1324
1379
|
variables.variantMetafieldIdentifiers = metafieldIdentifiers;
|
|
1325
1380
|
}
|
|
1326
|
-
const data = await client.query(
|
|
1381
|
+
const data = await client.query(queryString, variables);
|
|
1327
1382
|
if (!data || !data.products) {
|
|
1328
1383
|
return [];
|
|
1329
1384
|
}
|
|
@@ -1338,7 +1393,8 @@ async function getAllProducts(client, options) {
|
|
|
1338
1393
|
return fetchAllPages(client, options);
|
|
1339
1394
|
}
|
|
1340
1395
|
async function getProducts(client, options) {
|
|
1341
|
-
const { first = 250, after, query, sortKey, reverse, metafieldIdentifiers } = options;
|
|
1396
|
+
const { first = 250, after, query, graphqlQuery, sortKey, reverse, metafieldIdentifiers } = options;
|
|
1397
|
+
const queryString = graphqlQuery || getAllProductsQuery;
|
|
1342
1398
|
const variables = {
|
|
1343
1399
|
first,
|
|
1344
1400
|
after,
|
|
@@ -1350,7 +1406,7 @@ async function getProducts(client, options) {
|
|
|
1350
1406
|
variables.productMetafieldIdentifiers = metafieldIdentifiers;
|
|
1351
1407
|
variables.variantMetafieldIdentifiers = metafieldIdentifiers;
|
|
1352
1408
|
}
|
|
1353
|
-
const data = await client.query(
|
|
1409
|
+
const data = await client.query(queryString, variables);
|
|
1354
1410
|
if (!data || !data.products) {
|
|
1355
1411
|
return {
|
|
1356
1412
|
products: [],
|
|
@@ -1400,11 +1456,11 @@ function buildProductsByHandlesQuery(handles) {
|
|
|
1400
1456
|
);
|
|
1401
1457
|
}
|
|
1402
1458
|
async function getProductsByHandles(client, options) {
|
|
1403
|
-
const { handles, metafieldIdentifiers } = options;
|
|
1459
|
+
const { handles, graphqlQuery, metafieldIdentifiers } = options;
|
|
1404
1460
|
if (!handles || handles.length === 0) {
|
|
1405
1461
|
return [];
|
|
1406
1462
|
}
|
|
1407
|
-
const query = buildProductsByHandlesQuery(handles);
|
|
1463
|
+
const query = graphqlQuery || buildProductsByHandlesQuery(handles);
|
|
1408
1464
|
const data = await client.query(query, {
|
|
1409
1465
|
handles,
|
|
1410
1466
|
// 请勿删除,这个参数虽然没有在 query 中使用,但方便在 chrome dev tools 中查看请求参数
|
|
@@ -1416,7 +1472,12 @@ async function getProductsByHandles(client, options) {
|
|
|
1416
1472
|
if (!data) {
|
|
1417
1473
|
return [];
|
|
1418
1474
|
}
|
|
1419
|
-
return Object.
|
|
1475
|
+
return Object.values(data).map((item) => {
|
|
1476
|
+
if (item) {
|
|
1477
|
+
return normalizeProduct(item);
|
|
1478
|
+
}
|
|
1479
|
+
return void 0;
|
|
1480
|
+
});
|
|
1420
1481
|
}
|
|
1421
1482
|
|
|
1422
1483
|
// src/api/cart/normalize.ts
|
|
@@ -1520,7 +1581,8 @@ function normalizeCart(cart) {
|
|
|
1520
1581
|
|
|
1521
1582
|
// src/api/cart/get-cart.ts
|
|
1522
1583
|
async function getCart(client, options) {
|
|
1523
|
-
const { id, cookieAdapter, metafieldIdentifiers } = options;
|
|
1584
|
+
const { id, cookieAdapter, graphqlQuery, metafieldIdentifiers } = options;
|
|
1585
|
+
const query = graphqlQuery || getCartQuery;
|
|
1524
1586
|
const locale = client.getLocale();
|
|
1525
1587
|
const cartId = id || cookieAdapter?.getCartId(locale);
|
|
1526
1588
|
console.log("cartId", cartId);
|
|
@@ -1528,7 +1590,7 @@ async function getCart(client, options) {
|
|
|
1528
1590
|
return void 0;
|
|
1529
1591
|
}
|
|
1530
1592
|
try {
|
|
1531
|
-
const data = await client.query(
|
|
1593
|
+
const data = await client.query(query, {
|
|
1532
1594
|
cartId,
|
|
1533
1595
|
...constructMetafieldIdentifiersQueryParams(
|
|
1534
1596
|
metafieldIdentifiers,
|
|
@@ -1563,12 +1625,14 @@ async function createCart(client, options = {}) {
|
|
|
1563
1625
|
buyerIdentity,
|
|
1564
1626
|
discountCodes,
|
|
1565
1627
|
customAttributes,
|
|
1628
|
+
graphqlQuery,
|
|
1566
1629
|
metafieldIdentifiers,
|
|
1567
1630
|
updateCookie = false
|
|
1568
1631
|
} = options;
|
|
1632
|
+
const query = graphqlQuery || createCartMutation;
|
|
1569
1633
|
const locale = client.getLocale();
|
|
1570
1634
|
try {
|
|
1571
|
-
const data = await client.query(
|
|
1635
|
+
const data = await client.query(query, {
|
|
1572
1636
|
lines,
|
|
1573
1637
|
buyerIdentity,
|
|
1574
1638
|
discountCodes,
|
|
@@ -1598,7 +1662,8 @@ async function createCart(client, options = {}) {
|
|
|
1598
1662
|
|
|
1599
1663
|
// src/api/cart/add-cart-lines.ts
|
|
1600
1664
|
async function addCartLines(client, options) {
|
|
1601
|
-
const { cartId: providedCartId, lines, cookieAdapter, metafieldIdentifiers } = options;
|
|
1665
|
+
const { cartId: providedCartId, lines, cookieAdapter, graphqlQuery, metafieldIdentifiers } = options;
|
|
1666
|
+
const query = graphqlQuery || addCartItemsMutation;
|
|
1602
1667
|
const locale = client.getLocale();
|
|
1603
1668
|
const cartId = providedCartId || cookieAdapter?.getCartId(locale);
|
|
1604
1669
|
if (!cartId) {
|
|
@@ -1609,7 +1674,7 @@ async function addCartLines(client, options) {
|
|
|
1609
1674
|
client.getConfig().getMetafieldNamespacePrefix()
|
|
1610
1675
|
);
|
|
1611
1676
|
try {
|
|
1612
|
-
const data = await client.query(
|
|
1677
|
+
const data = await client.query(query, {
|
|
1613
1678
|
cartId,
|
|
1614
1679
|
lines,
|
|
1615
1680
|
...normalizedMetafieldIdentifiers
|
|
@@ -1634,7 +1699,8 @@ async function addCartLines(client, options) {
|
|
|
1634
1699
|
|
|
1635
1700
|
// src/api/cart/update-cart-lines.ts
|
|
1636
1701
|
async function updateCartLines(client, options) {
|
|
1637
|
-
const { cartId: providedCartId, lines, cookieAdapter, metafieldIdentifiers } = options;
|
|
1702
|
+
const { cartId: providedCartId, lines, cookieAdapter, graphqlQuery, metafieldIdentifiers } = options;
|
|
1703
|
+
const query = graphqlQuery || updateCartItemsMutation;
|
|
1638
1704
|
const locale = client.getLocale();
|
|
1639
1705
|
const cartId = providedCartId || cookieAdapter?.getCartId(locale);
|
|
1640
1706
|
if (!cartId) {
|
|
@@ -1647,7 +1713,7 @@ async function updateCartLines(client, options) {
|
|
|
1647
1713
|
console.log("update-cart-lines metafieldIdentifiers:", metafieldIdentifiers);
|
|
1648
1714
|
console.log("update-cart-lines metafieldParams:", metafieldParams);
|
|
1649
1715
|
try {
|
|
1650
|
-
const data = await client.query(
|
|
1716
|
+
const data = await client.query(query, {
|
|
1651
1717
|
cartId,
|
|
1652
1718
|
lines,
|
|
1653
1719
|
...metafieldParams
|
|
@@ -1681,14 +1747,15 @@ async function updateCartLines(client, options) {
|
|
|
1681
1747
|
|
|
1682
1748
|
// src/api/cart/remove-cart-lines.ts
|
|
1683
1749
|
async function removeCartLines(client, options) {
|
|
1684
|
-
const { cartId: providedCartId, lineIds, cookieAdapter, metafieldIdentifiers } = options;
|
|
1750
|
+
const { cartId: providedCartId, lineIds, cookieAdapter, graphqlQuery, metafieldIdentifiers } = options;
|
|
1751
|
+
const query = graphqlQuery || removeCartItemsMutation;
|
|
1685
1752
|
const locale = client.getLocale();
|
|
1686
1753
|
const cartId = providedCartId || cookieAdapter?.getCartId(locale);
|
|
1687
1754
|
if (!cartId) {
|
|
1688
1755
|
throw new Error("Invalid input used for this operation: Miss cartId");
|
|
1689
1756
|
}
|
|
1690
1757
|
try {
|
|
1691
|
-
const data = await client.query(
|
|
1758
|
+
const data = await client.query(query, {
|
|
1692
1759
|
cartId,
|
|
1693
1760
|
lineIds,
|
|
1694
1761
|
...constructMetafieldIdentifiersQueryParams(
|
|
@@ -1715,14 +1782,15 @@ async function removeCartLines(client, options) {
|
|
|
1715
1782
|
|
|
1716
1783
|
// src/api/cart/update-cart-codes.ts
|
|
1717
1784
|
async function updateCartCodes(client, options) {
|
|
1718
|
-
const { cartId: providedCartId, discountCodes, cookieAdapter, metafieldIdentifiers } = options;
|
|
1785
|
+
const { cartId: providedCartId, discountCodes, cookieAdapter, graphqlQuery, metafieldIdentifiers } = options;
|
|
1786
|
+
const query = graphqlQuery || updateCartDiscountCodeMutation;
|
|
1719
1787
|
const locale = client.getLocale();
|
|
1720
1788
|
const cartId = providedCartId || cookieAdapter?.getCartId(locale);
|
|
1721
1789
|
if (!cartId) {
|
|
1722
1790
|
throw new Error("Invalid input used for this operation: Miss cartId");
|
|
1723
1791
|
}
|
|
1724
1792
|
try {
|
|
1725
|
-
const data = await client.query(
|
|
1793
|
+
const data = await client.query(query, {
|
|
1726
1794
|
cartId,
|
|
1727
1795
|
discountCodes,
|
|
1728
1796
|
...constructMetafieldIdentifiersQueryParams(
|
|
@@ -1746,14 +1814,15 @@ async function updateCartCodes(client, options) {
|
|
|
1746
1814
|
|
|
1747
1815
|
// src/api/cart/update-cart-attributes.ts
|
|
1748
1816
|
async function updateCartAttributes(client, options) {
|
|
1749
|
-
const { cartId: providedCartId, attributes, cookieAdapter, metafieldIdentifiers } = options;
|
|
1817
|
+
const { cartId: providedCartId, attributes, cookieAdapter, graphqlQuery, metafieldIdentifiers } = options;
|
|
1818
|
+
const query = graphqlQuery || updateCartAttributesMutation;
|
|
1750
1819
|
const locale = client.getLocale();
|
|
1751
1820
|
const cartId = providedCartId || cookieAdapter?.getCartId(locale);
|
|
1752
1821
|
if (!cartId) {
|
|
1753
1822
|
throw new Error("Invalid input used for this operation: Miss cartId");
|
|
1754
1823
|
}
|
|
1755
1824
|
try {
|
|
1756
|
-
const data = await client.query(
|
|
1825
|
+
const data = await client.query(query, {
|
|
1757
1826
|
cartId,
|
|
1758
1827
|
attributes,
|
|
1759
1828
|
...constructMetafieldIdentifiersQueryParams(
|
|
@@ -1780,14 +1849,15 @@ async function updateCartAttributes(client, options) {
|
|
|
1780
1849
|
|
|
1781
1850
|
// src/api/cart/update-cart-delivery-options.ts
|
|
1782
1851
|
async function updateCartDeliveryOptions(client, options) {
|
|
1783
|
-
const { cartId: providedCartId, selectedDeliveryOptions, cookieAdapter, metafieldIdentifiers } = options;
|
|
1852
|
+
const { cartId: providedCartId, selectedDeliveryOptions, cookieAdapter, graphqlQuery, metafieldIdentifiers } = options;
|
|
1853
|
+
const query = graphqlQuery || updateCartDeliveryOptionsMutation;
|
|
1784
1854
|
const locale = client.getLocale();
|
|
1785
1855
|
const cartId = providedCartId || cookieAdapter?.getCartId(locale);
|
|
1786
1856
|
if (!cartId) {
|
|
1787
1857
|
throw new Error("Invalid input used for this operation: Miss cartId");
|
|
1788
1858
|
}
|
|
1789
1859
|
try {
|
|
1790
|
-
const data = await client.query(
|
|
1860
|
+
const data = await client.query(query, {
|
|
1791
1861
|
cartId,
|
|
1792
1862
|
selectedDeliveryOptions,
|
|
1793
1863
|
...constructMetafieldIdentifiersQueryParams(
|
|
@@ -1814,14 +1884,15 @@ async function updateCartDeliveryOptions(client, options) {
|
|
|
1814
1884
|
|
|
1815
1885
|
// src/api/cart/update-buyer-identity.ts
|
|
1816
1886
|
async function updateBuyerIdentity(client, options) {
|
|
1817
|
-
const { cartId: providedCartId, buyerIdentity, cookieAdapter, metafieldIdentifiers } = options;
|
|
1887
|
+
const { cartId: providedCartId, buyerIdentity, cookieAdapter, graphqlQuery, metafieldIdentifiers } = options;
|
|
1888
|
+
const query = graphqlQuery || updateBuyerIdentityMutation;
|
|
1818
1889
|
const locale = client.getLocale();
|
|
1819
1890
|
const cartId = providedCartId || cookieAdapter?.getCartId(locale);
|
|
1820
1891
|
if (!cartId) {
|
|
1821
1892
|
throw new Error("Invalid input used for this operation: Miss cartId");
|
|
1822
1893
|
}
|
|
1823
1894
|
try {
|
|
1824
|
-
const data = await client.query(
|
|
1895
|
+
const data = await client.query(query, {
|
|
1825
1896
|
cartId,
|
|
1826
1897
|
buyerIdentity,
|
|
1827
1898
|
...constructMetafieldIdentifiersQueryParams(
|
|
@@ -1892,12 +1963,13 @@ var getCollectionQuery = (
|
|
|
1892
1963
|
`
|
|
1893
1964
|
);
|
|
1894
1965
|
async function getCollection(client, options) {
|
|
1895
|
-
const { handle, metafieldIdentifiers } = options;
|
|
1966
|
+
const { handle, graphqlQuery, metafieldIdentifiers } = options;
|
|
1967
|
+
const query = graphqlQuery || getCollectionQuery;
|
|
1896
1968
|
const variables = { handle };
|
|
1897
1969
|
if (metafieldIdentifiers) {
|
|
1898
1970
|
variables.metafieldIdentifiers = metafieldIdentifiers;
|
|
1899
1971
|
}
|
|
1900
|
-
const data = await client.query(
|
|
1972
|
+
const data = await client.query(query, variables);
|
|
1901
1973
|
if (!data?.collection) {
|
|
1902
1974
|
return void 0;
|
|
1903
1975
|
}
|
|
@@ -1940,7 +2012,8 @@ var getAllCollectionsQuery = (
|
|
|
1940
2012
|
`
|
|
1941
2013
|
);
|
|
1942
2014
|
async function fetchAllPages2(client, options, afterCursor) {
|
|
1943
|
-
const { first = 250, query, sortKey, reverse, metafieldIdentifiers } = options;
|
|
2015
|
+
const { first = 250, query, graphqlQuery, sortKey, reverse, metafieldIdentifiers } = options;
|
|
2016
|
+
const queryString = graphqlQuery || getAllCollectionsQuery;
|
|
1944
2017
|
const variables = {
|
|
1945
2018
|
first,
|
|
1946
2019
|
after: afterCursor,
|
|
@@ -1951,7 +2024,7 @@ async function fetchAllPages2(client, options, afterCursor) {
|
|
|
1951
2024
|
if (metafieldIdentifiers) {
|
|
1952
2025
|
variables.metafieldIdentifiers = metafieldIdentifiers;
|
|
1953
2026
|
}
|
|
1954
|
-
const data = await client.query(
|
|
2027
|
+
const data = await client.query(queryString, variables);
|
|
1955
2028
|
if (!data || !data.collections) {
|
|
1956
2029
|
return [];
|
|
1957
2030
|
}
|
|
@@ -1966,7 +2039,8 @@ async function getAllCollections(client, options) {
|
|
|
1966
2039
|
return fetchAllPages2(client, options);
|
|
1967
2040
|
}
|
|
1968
2041
|
async function getCollections(client, options) {
|
|
1969
|
-
const { first = 250, after, query, sortKey, reverse, metafieldIdentifiers } = options;
|
|
2042
|
+
const { first = 250, after, query, graphqlQuery, sortKey, reverse, metafieldIdentifiers } = options;
|
|
2043
|
+
const queryString = graphqlQuery || getAllCollectionsQuery;
|
|
1970
2044
|
const variables = {
|
|
1971
2045
|
first,
|
|
1972
2046
|
after,
|
|
@@ -1977,7 +2051,7 @@ async function getCollections(client, options) {
|
|
|
1977
2051
|
if (metafieldIdentifiers) {
|
|
1978
2052
|
variables.metafieldIdentifiers = metafieldIdentifiers;
|
|
1979
2053
|
}
|
|
1980
|
-
const data = await client.query(
|
|
2054
|
+
const data = await client.query(queryString, variables);
|
|
1981
2055
|
if (!data || !data.collections) {
|
|
1982
2056
|
return {
|
|
1983
2057
|
collections: [],
|
|
@@ -1994,6 +2068,36 @@ async function getCollections(client, options) {
|
|
|
1994
2068
|
};
|
|
1995
2069
|
}
|
|
1996
2070
|
|
|
2071
|
+
// src/api/collection/get-collections-by-handles.ts
|
|
2072
|
+
var getCollectionsByHandles = async ({
|
|
2073
|
+
client,
|
|
2074
|
+
options
|
|
2075
|
+
}) => {
|
|
2076
|
+
const { handles, graphqlQuery, metafieldIdentifiers } = options;
|
|
2077
|
+
if (handles.length === 0) {
|
|
2078
|
+
return [];
|
|
2079
|
+
}
|
|
2080
|
+
const query = graphqlQuery || getCollectionsByHandlesQuery(handles);
|
|
2081
|
+
const data = await client.query(query, {
|
|
2082
|
+
handles,
|
|
2083
|
+
// 请勿删除,这个参数虽然没有在 query 中使用,但方便在 chrome dev tools 中查看请求参数
|
|
2084
|
+
...constructMetafieldIdentifiersQueryParams(
|
|
2085
|
+
metafieldIdentifiers,
|
|
2086
|
+
client.getConfig().getMetafieldNamespacePrefix()
|
|
2087
|
+
)
|
|
2088
|
+
});
|
|
2089
|
+
if (!data) {
|
|
2090
|
+
return [];
|
|
2091
|
+
}
|
|
2092
|
+
const collections = Object.values(data).map((item) => {
|
|
2093
|
+
if (!item) {
|
|
2094
|
+
return void 0;
|
|
2095
|
+
}
|
|
2096
|
+
return normalizeCollection(item);
|
|
2097
|
+
});
|
|
2098
|
+
return collections;
|
|
2099
|
+
};
|
|
2100
|
+
|
|
1997
2101
|
// src/api/blog/normalize.ts
|
|
1998
2102
|
function normalizeBlog(blog) {
|
|
1999
2103
|
return {
|
|
@@ -2038,16 +2142,16 @@ function normalizeMetafields2(metafields) {
|
|
|
2038
2142
|
|
|
2039
2143
|
// src/api/blog/get-blog.ts
|
|
2040
2144
|
async function getBlog(client, options) {
|
|
2041
|
-
const { handle, metafieldIdentifiers } = options;
|
|
2145
|
+
const { handle, graphqlQuery, metafieldIdentifiers } = options;
|
|
2042
2146
|
const hasMetafields = metafieldIdentifiers && metafieldIdentifiers.length > 0;
|
|
2043
2147
|
const fragment = hasMetafields ? blogWithMetafieldsFragment : blogFragment;
|
|
2044
|
-
const
|
|
2148
|
+
const defaultQuery = (
|
|
2045
2149
|
/* GraphQL */
|
|
2046
2150
|
`
|
|
2047
2151
|
query getBlog(
|
|
2048
2152
|
$handle: String!
|
|
2049
2153
|
${hasMetafields ? "$blogMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
|
|
2050
|
-
)
|
|
2154
|
+
) {
|
|
2051
2155
|
blog(handle: $handle) {
|
|
2052
2156
|
...${hasMetafields ? "blogWithMetafields" : "blog"}
|
|
2053
2157
|
}
|
|
@@ -2055,6 +2159,7 @@ async function getBlog(client, options) {
|
|
|
2055
2159
|
${fragment}
|
|
2056
2160
|
`
|
|
2057
2161
|
);
|
|
2162
|
+
const query = graphqlQuery || defaultQuery;
|
|
2058
2163
|
const variables = { handle };
|
|
2059
2164
|
if (hasMetafields) {
|
|
2060
2165
|
variables.blogMetafieldIdentifiers = metafieldIdentifiers;
|
|
@@ -2068,10 +2173,10 @@ async function getBlog(client, options) {
|
|
|
2068
2173
|
|
|
2069
2174
|
// src/api/blog/get-all-blogs.ts
|
|
2070
2175
|
async function fetchAllPages3(client, options, afterCursor) {
|
|
2071
|
-
const { first = 250, query, metafieldIdentifiers } = options;
|
|
2176
|
+
const { first = 250, query, graphqlQuery, metafieldIdentifiers } = options;
|
|
2072
2177
|
const hasMetafields = metafieldIdentifiers && metafieldIdentifiers.length > 0;
|
|
2073
2178
|
const fragment = hasMetafields ? blogWithMetafieldsFragment : blogFragment;
|
|
2074
|
-
const
|
|
2179
|
+
const defaultQueryString = (
|
|
2075
2180
|
/* GraphQL */
|
|
2076
2181
|
`
|
|
2077
2182
|
query getAllBlogs(
|
|
@@ -2079,7 +2184,7 @@ async function fetchAllPages3(client, options, afterCursor) {
|
|
|
2079
2184
|
$after: String
|
|
2080
2185
|
${query ? "$query: String!" : ""}
|
|
2081
2186
|
${hasMetafields ? "$blogMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
|
|
2082
|
-
)
|
|
2187
|
+
) {
|
|
2083
2188
|
blogs(
|
|
2084
2189
|
first: $first
|
|
2085
2190
|
after: $after
|
|
@@ -2099,6 +2204,7 @@ async function fetchAllPages3(client, options, afterCursor) {
|
|
|
2099
2204
|
${pageInfoFragment}
|
|
2100
2205
|
`
|
|
2101
2206
|
);
|
|
2207
|
+
const queryString = graphqlQuery || defaultQueryString;
|
|
2102
2208
|
const variables = { first, after: afterCursor };
|
|
2103
2209
|
if (query) {
|
|
2104
2210
|
variables.query = query;
|
|
@@ -2123,11 +2229,11 @@ async function getAllBlogs(client, options) {
|
|
|
2123
2229
|
|
|
2124
2230
|
// src/api/blog/get-article.ts
|
|
2125
2231
|
async function getArticle(client, options) {
|
|
2126
|
-
const { blogHandle, articleHandle, metafieldIdentifiers } = options;
|
|
2232
|
+
const { blogHandle, articleHandle, graphqlQuery, metafieldIdentifiers } = options;
|
|
2127
2233
|
const hasMetafields = metafieldIdentifiers && metafieldIdentifiers.length > 0;
|
|
2128
2234
|
const articleFrag = hasMetafields ? articleWithMetafieldsFragment : articleFragment;
|
|
2129
2235
|
const blogFrag = hasMetafields ? blogWithMetafieldsFragment : blogFragment;
|
|
2130
|
-
const
|
|
2236
|
+
const defaultQuery = (
|
|
2131
2237
|
/* GraphQL */
|
|
2132
2238
|
`
|
|
2133
2239
|
query getArticle(
|
|
@@ -2135,7 +2241,7 @@ async function getArticle(client, options) {
|
|
|
2135
2241
|
$articleHandle: String!
|
|
2136
2242
|
${hasMetafields ? "$blogMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
|
|
2137
2243
|
${hasMetafields ? "$articleMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
|
|
2138
|
-
)
|
|
2244
|
+
) {
|
|
2139
2245
|
blog(handle: $blogHandle) {
|
|
2140
2246
|
...${hasMetafields ? "blogWithMetafields" : "blog"}
|
|
2141
2247
|
articleByHandle(handle: $articleHandle) {
|
|
@@ -2150,6 +2256,7 @@ async function getArticle(client, options) {
|
|
|
2150
2256
|
${blogFrag}
|
|
2151
2257
|
`
|
|
2152
2258
|
);
|
|
2259
|
+
const query = graphqlQuery || defaultQuery;
|
|
2153
2260
|
const variables = { blogHandle, articleHandle };
|
|
2154
2261
|
if (hasMetafields) {
|
|
2155
2262
|
variables.blogMetafieldIdentifiers = metafieldIdentifiers;
|
|
@@ -2164,10 +2271,17 @@ async function getArticle(client, options) {
|
|
|
2164
2271
|
|
|
2165
2272
|
// src/api/blog/get-articles.ts
|
|
2166
2273
|
async function fetchAllPages4(client, options, afterCursor) {
|
|
2167
|
-
const {
|
|
2274
|
+
const {
|
|
2275
|
+
first = 250,
|
|
2276
|
+
query,
|
|
2277
|
+
graphqlQuery,
|
|
2278
|
+
sortKey = "PUBLISHED_AT",
|
|
2279
|
+
reverse = false,
|
|
2280
|
+
metafieldIdentifiers
|
|
2281
|
+
} = options;
|
|
2168
2282
|
const hasMetafields = metafieldIdentifiers && metafieldIdentifiers.length > 0;
|
|
2169
2283
|
const fragment = hasMetafields ? articleWithMetafieldsFragment : articleFragment;
|
|
2170
|
-
const
|
|
2284
|
+
const defaultQueryString = (
|
|
2171
2285
|
/* GraphQL */
|
|
2172
2286
|
`
|
|
2173
2287
|
query getArticles(
|
|
@@ -2177,7 +2291,7 @@ async function fetchAllPages4(client, options, afterCursor) {
|
|
|
2177
2291
|
$sortKey: ArticleSortKeys!
|
|
2178
2292
|
$reverse: Boolean!
|
|
2179
2293
|
${hasMetafields ? "$articleMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
|
|
2180
|
-
)
|
|
2294
|
+
) {
|
|
2181
2295
|
articles(
|
|
2182
2296
|
first: $first
|
|
2183
2297
|
after: $after
|
|
@@ -2199,6 +2313,7 @@ async function fetchAllPages4(client, options, afterCursor) {
|
|
|
2199
2313
|
${pageInfoFragment}
|
|
2200
2314
|
`
|
|
2201
2315
|
);
|
|
2316
|
+
const queryString = graphqlQuery || defaultQueryString;
|
|
2202
2317
|
const variables = {
|
|
2203
2318
|
first,
|
|
2204
2319
|
after: afterCursor,
|
|
@@ -2228,11 +2343,18 @@ async function getArticles(client, options) {
|
|
|
2228
2343
|
|
|
2229
2344
|
// src/api/blog/get-articles-in-blog.ts
|
|
2230
2345
|
async function fetchAllPages5(client, options, afterCursor) {
|
|
2231
|
-
const {
|
|
2346
|
+
const {
|
|
2347
|
+
blogHandle,
|
|
2348
|
+
first = 250,
|
|
2349
|
+
graphqlQuery,
|
|
2350
|
+
sortKey = "PUBLISHED_AT",
|
|
2351
|
+
reverse = false,
|
|
2352
|
+
metafieldIdentifiers
|
|
2353
|
+
} = options;
|
|
2232
2354
|
const hasMetafields = metafieldIdentifiers && metafieldIdentifiers.length > 0;
|
|
2233
2355
|
const articleFrag = hasMetafields ? articleWithMetafieldsFragment : articleFragment;
|
|
2234
2356
|
const blogFrag = hasMetafields ? blogWithMetafieldsFragment : blogFragment;
|
|
2235
|
-
const
|
|
2357
|
+
const defaultQuery = (
|
|
2236
2358
|
/* GraphQL */
|
|
2237
2359
|
`
|
|
2238
2360
|
query getArticlesInBlog(
|
|
@@ -2243,7 +2365,7 @@ async function fetchAllPages5(client, options, afterCursor) {
|
|
|
2243
2365
|
$reverse: Boolean!
|
|
2244
2366
|
${hasMetafields ? "$blogMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
|
|
2245
2367
|
${hasMetafields ? "$articleMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
|
|
2246
|
-
)
|
|
2368
|
+
) {
|
|
2247
2369
|
blog(handle: $blogHandle) {
|
|
2248
2370
|
...${hasMetafields ? "blogWithMetafields" : "blog"}
|
|
2249
2371
|
articles(
|
|
@@ -2268,6 +2390,7 @@ async function fetchAllPages5(client, options, afterCursor) {
|
|
|
2268
2390
|
${pageInfoFragment}
|
|
2269
2391
|
`
|
|
2270
2392
|
);
|
|
2393
|
+
const query = graphqlQuery || defaultQuery;
|
|
2271
2394
|
const variables = {
|
|
2272
2395
|
blogHandle,
|
|
2273
2396
|
first,
|
|
@@ -2318,6 +2441,8 @@ exports.getCart = getCart;
|
|
|
2318
2441
|
exports.getCartQuery = getCartQuery;
|
|
2319
2442
|
exports.getCollection = getCollection;
|
|
2320
2443
|
exports.getCollections = getCollections;
|
|
2444
|
+
exports.getCollectionsByHandles = getCollectionsByHandles;
|
|
2445
|
+
exports.getCollectionsByHandlesQuery = getCollectionsByHandlesQuery;
|
|
2321
2446
|
exports.getProduct = getProduct;
|
|
2322
2447
|
exports.getProductQuery = getProductQuery;
|
|
2323
2448
|
exports.getProducts = getProducts;
|