@szymonpiatek/nextwordpress 0.0.2 → 0.0.3
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.cjs +305 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +165 -10
- package/dist/index.d.ts +165 -10
- package/dist/index.js +305 -10
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -329,6 +329,100 @@ function createPagesQueries(fetcher) {
|
|
|
329
329
|
return { getAllPages, getPageById, getPageBySlug };
|
|
330
330
|
}
|
|
331
331
|
|
|
332
|
+
// src/integrations/restApi/core/menus/queries.ts
|
|
333
|
+
function createMenusQueries(fetcher) {
|
|
334
|
+
const { wpFetch, wpFetchGraceful } = fetcher;
|
|
335
|
+
async function getMenus() {
|
|
336
|
+
return wpFetchGraceful("/wp-json/wp/v2/menus", [], void 0, ["wordpress", "menus"]);
|
|
337
|
+
}
|
|
338
|
+
async function getMenuById(id) {
|
|
339
|
+
return wpFetch(`/wp-json/wp/v2/menus/${id}`, void 0, ["wordpress", "menus", `menu-${id}`]);
|
|
340
|
+
}
|
|
341
|
+
async function getMenuBySlug(slug) {
|
|
342
|
+
const menus = await wpFetchGraceful("/wp-json/wp/v2/menus", [], { slug }, ["wordpress", "menus"]);
|
|
343
|
+
return menus[0];
|
|
344
|
+
}
|
|
345
|
+
async function getMenuItemsByMenuId(menuId) {
|
|
346
|
+
return wpFetchGraceful(
|
|
347
|
+
"/wp-json/wp/v2/menu-items",
|
|
348
|
+
[],
|
|
349
|
+
{ menus: menuId, per_page: 100, orderby: "menu_order", order: "asc" },
|
|
350
|
+
["wordpress", "menus", `menu-items-${menuId}`]
|
|
351
|
+
);
|
|
352
|
+
}
|
|
353
|
+
async function getMenuLocations() {
|
|
354
|
+
return wpFetchGraceful(
|
|
355
|
+
"/wp-json/wp/v2/menu-locations",
|
|
356
|
+
{},
|
|
357
|
+
void 0,
|
|
358
|
+
["wordpress", "menus", "menu-locations"]
|
|
359
|
+
);
|
|
360
|
+
}
|
|
361
|
+
async function getMenuByLocation(location) {
|
|
362
|
+
const locations = await getMenuLocations();
|
|
363
|
+
const loc = locations[location];
|
|
364
|
+
if (!loc || !loc.menu) return void 0;
|
|
365
|
+
const [menu, items] = await Promise.all([
|
|
366
|
+
getMenuById(loc.menu),
|
|
367
|
+
getMenuItemsByMenuId(loc.menu)
|
|
368
|
+
]);
|
|
369
|
+
return { menu, items };
|
|
370
|
+
}
|
|
371
|
+
return {
|
|
372
|
+
getMenus,
|
|
373
|
+
getMenuById,
|
|
374
|
+
getMenuBySlug,
|
|
375
|
+
getMenuItemsByMenuId,
|
|
376
|
+
getMenuLocations,
|
|
377
|
+
getMenuByLocation
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
// src/integrations/restApi/core/comments/queries.ts
|
|
382
|
+
function createCommentsQueries(fetcher) {
|
|
383
|
+
const { wpFetch, wpFetchGraceful, wpFetchPaginatedGraceful, wpMutate } = fetcher;
|
|
384
|
+
async function getCommentsByPostId(postId, page = 1, perPage = 10) {
|
|
385
|
+
return wpFetchPaginatedGraceful(
|
|
386
|
+
"/wp-json/wp/v2/comments",
|
|
387
|
+
{ post: postId, per_page: perPage, page, status: "approve" },
|
|
388
|
+
["wordpress", "comments", `comments-post-${postId}`]
|
|
389
|
+
);
|
|
390
|
+
}
|
|
391
|
+
async function getAllCommentsByPostId(postId) {
|
|
392
|
+
return wpFetchGraceful(
|
|
393
|
+
"/wp-json/wp/v2/comments",
|
|
394
|
+
[],
|
|
395
|
+
{ post: postId, per_page: 100, status: "approve" },
|
|
396
|
+
["wordpress", "comments", `comments-post-${postId}`]
|
|
397
|
+
);
|
|
398
|
+
}
|
|
399
|
+
async function getCommentById(id) {
|
|
400
|
+
return wpFetch(`/wp-json/wp/v2/comments/${id}`, void 0, [
|
|
401
|
+
"wordpress",
|
|
402
|
+
"comments",
|
|
403
|
+
`comment-${id}`
|
|
404
|
+
]);
|
|
405
|
+
}
|
|
406
|
+
async function getCommentReplies(parentId) {
|
|
407
|
+
return wpFetchGraceful(
|
|
408
|
+
"/wp-json/wp/v2/comments",
|
|
409
|
+
[],
|
|
410
|
+
{ parent: parentId, per_page: 100, status: "approve" },
|
|
411
|
+
["wordpress", "comments", `comments-parent-${parentId}`]
|
|
412
|
+
);
|
|
413
|
+
}
|
|
414
|
+
async function createComment(input) {
|
|
415
|
+
return wpMutate("/wp-json/wp/v2/comments", input, "POST");
|
|
416
|
+
}
|
|
417
|
+
return {
|
|
418
|
+
getCommentsByPostId,
|
|
419
|
+
getAllCommentsByPostId,
|
|
420
|
+
getCommentById,
|
|
421
|
+
getCommentReplies,
|
|
422
|
+
createComment
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
|
|
332
426
|
// src/integrations/restApi/core/index.ts
|
|
333
427
|
function createWordPressClient(config) {
|
|
334
428
|
const fetcher = createFetcher(config);
|
|
@@ -338,7 +432,9 @@ function createWordPressClient(config) {
|
|
|
338
432
|
...createTagsQueries(fetcher),
|
|
339
433
|
...createAuthorsQueries(fetcher),
|
|
340
434
|
...createMediaQueries(fetcher),
|
|
341
|
-
...createPagesQueries(fetcher)
|
|
435
|
+
...createPagesQueries(fetcher),
|
|
436
|
+
...createMenusQueries(fetcher),
|
|
437
|
+
...createCommentsQueries(fetcher)
|
|
342
438
|
};
|
|
343
439
|
}
|
|
344
440
|
|
|
@@ -1260,6 +1356,194 @@ function createAuthorsQueries2(fetcher) {
|
|
|
1260
1356
|
return { getAuthors, getAuthorBySlug };
|
|
1261
1357
|
}
|
|
1262
1358
|
|
|
1359
|
+
// src/integrations/wpGraphQL/core/menus/queries.ts
|
|
1360
|
+
var MENU_ITEM_FIELDS = `
|
|
1361
|
+
id
|
|
1362
|
+
databaseId
|
|
1363
|
+
label
|
|
1364
|
+
url
|
|
1365
|
+
parentId
|
|
1366
|
+
order
|
|
1367
|
+
target
|
|
1368
|
+
cssClasses
|
|
1369
|
+
description
|
|
1370
|
+
connectedNode {
|
|
1371
|
+
node {
|
|
1372
|
+
__typename
|
|
1373
|
+
... on Page { id databaseId slug }
|
|
1374
|
+
... on Post { id databaseId slug }
|
|
1375
|
+
... on Category { id databaseId slug }
|
|
1376
|
+
... on Tag { id databaseId slug }
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
`;
|
|
1380
|
+
var MENU_FIELDS = `
|
|
1381
|
+
id
|
|
1382
|
+
databaseId
|
|
1383
|
+
name
|
|
1384
|
+
slug
|
|
1385
|
+
locations
|
|
1386
|
+
menuItems(first: 100) {
|
|
1387
|
+
nodes { ${MENU_ITEM_FIELDS} }
|
|
1388
|
+
}
|
|
1389
|
+
`;
|
|
1390
|
+
var GQL_GET_MENUS = `
|
|
1391
|
+
query GetMenus {
|
|
1392
|
+
menus(first: 100) {
|
|
1393
|
+
nodes { ${MENU_FIELDS} }
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
1396
|
+
`;
|
|
1397
|
+
var GQL_GET_MENU_BY_ID = `
|
|
1398
|
+
query GetMenuById($id: ID!) {
|
|
1399
|
+
menu(id: $id, idType: DATABASE_ID) { ${MENU_FIELDS} }
|
|
1400
|
+
}
|
|
1401
|
+
`;
|
|
1402
|
+
var GQL_GET_MENU_BY_SLUG = `
|
|
1403
|
+
query GetMenuBySlug($id: ID!) {
|
|
1404
|
+
menu(id: $id, idType: SLUG) { ${MENU_FIELDS} }
|
|
1405
|
+
}
|
|
1406
|
+
`;
|
|
1407
|
+
var GQL_GET_MENUS_BY_LOCATION = `
|
|
1408
|
+
query GetMenusByLocation($location: MenuLocationEnum!) {
|
|
1409
|
+
menus(where: { location: $location }, first: 1) {
|
|
1410
|
+
nodes { ${MENU_FIELDS} }
|
|
1411
|
+
}
|
|
1412
|
+
}
|
|
1413
|
+
`;
|
|
1414
|
+
function createMenusQueries2(fetcher) {
|
|
1415
|
+
const { gqlFetch, gqlFetchGraceful } = fetcher;
|
|
1416
|
+
async function getMenus() {
|
|
1417
|
+
const data = await gqlFetchGraceful(
|
|
1418
|
+
GQL_GET_MENUS,
|
|
1419
|
+
{ menus: { nodes: [] } },
|
|
1420
|
+
void 0,
|
|
1421
|
+
["wpgraphql", "gql-menus"]
|
|
1422
|
+
);
|
|
1423
|
+
return data.menus.nodes;
|
|
1424
|
+
}
|
|
1425
|
+
async function getMenuById(id) {
|
|
1426
|
+
const data = await gqlFetchGraceful(
|
|
1427
|
+
GQL_GET_MENU_BY_ID,
|
|
1428
|
+
{ menu: null },
|
|
1429
|
+
{ id: String(id) },
|
|
1430
|
+
["wpgraphql", "gql-menus", `gql-menu-${id}`]
|
|
1431
|
+
);
|
|
1432
|
+
return data.menu;
|
|
1433
|
+
}
|
|
1434
|
+
async function getMenuBySlug(slug) {
|
|
1435
|
+
const data = await gqlFetchGraceful(
|
|
1436
|
+
GQL_GET_MENU_BY_SLUG,
|
|
1437
|
+
{ menu: null },
|
|
1438
|
+
{ id: slug },
|
|
1439
|
+
["wpgraphql", "gql-menus", `gql-menu-${slug}`]
|
|
1440
|
+
);
|
|
1441
|
+
return data.menu;
|
|
1442
|
+
}
|
|
1443
|
+
async function getMenuByLocation(location) {
|
|
1444
|
+
const data = await gqlFetch(
|
|
1445
|
+
GQL_GET_MENUS_BY_LOCATION,
|
|
1446
|
+
{ location: location.toUpperCase() },
|
|
1447
|
+
["wpgraphql", "gql-menus", `gql-menu-location-${location}`]
|
|
1448
|
+
);
|
|
1449
|
+
return data.menus.nodes[0] ?? null;
|
|
1450
|
+
}
|
|
1451
|
+
async function getMenuItems(menuSlug) {
|
|
1452
|
+
const menu = await getMenuBySlug(menuSlug);
|
|
1453
|
+
return menu?.menuItems?.nodes ?? [];
|
|
1454
|
+
}
|
|
1455
|
+
return {
|
|
1456
|
+
getMenus,
|
|
1457
|
+
getMenuById,
|
|
1458
|
+
getMenuBySlug,
|
|
1459
|
+
getMenuByLocation,
|
|
1460
|
+
getMenuItems
|
|
1461
|
+
};
|
|
1462
|
+
}
|
|
1463
|
+
|
|
1464
|
+
// src/integrations/wpGraphQL/core/comments/queries.ts
|
|
1465
|
+
var COMMENT_AUTHOR_FIELDS = `
|
|
1466
|
+
name
|
|
1467
|
+
url
|
|
1468
|
+
avatar { url width height }
|
|
1469
|
+
`;
|
|
1470
|
+
var COMMENT_FIELDS = `
|
|
1471
|
+
id
|
|
1472
|
+
databaseId
|
|
1473
|
+
content(format: RENDERED)
|
|
1474
|
+
date
|
|
1475
|
+
parentId
|
|
1476
|
+
status
|
|
1477
|
+
author { node { ${COMMENT_AUTHOR_FIELDS} } }
|
|
1478
|
+
`;
|
|
1479
|
+
var GQL_GET_COMMENTS_BY_POST = `
|
|
1480
|
+
query GetCommentsByPost($contentId: ID!, $first: Int, $after: String) {
|
|
1481
|
+
comments(
|
|
1482
|
+
first: $first
|
|
1483
|
+
after: $after
|
|
1484
|
+
where: { contentId: $contentId, status: "approve", parent: 0 }
|
|
1485
|
+
) {
|
|
1486
|
+
nodes {
|
|
1487
|
+
${COMMENT_FIELDS}
|
|
1488
|
+
replies(first: 100) {
|
|
1489
|
+
nodes { ${COMMENT_FIELDS} }
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
pageInfo { hasNextPage endCursor }
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
`;
|
|
1496
|
+
var GQL_GET_ALL_COMMENTS_BY_POST = `
|
|
1497
|
+
query GetAllCommentsByPost($contentId: ID!) {
|
|
1498
|
+
comments(
|
|
1499
|
+
first: 100
|
|
1500
|
+
where: { contentId: $contentId, status: "approve" }
|
|
1501
|
+
) {
|
|
1502
|
+
nodes { ${COMMENT_FIELDS} }
|
|
1503
|
+
}
|
|
1504
|
+
}
|
|
1505
|
+
`;
|
|
1506
|
+
var GQL_GET_COMMENT_BY_ID = `
|
|
1507
|
+
query GetCommentById($id: ID!) {
|
|
1508
|
+
comment(id: $id, idType: DATABASE_ID) { ${COMMENT_FIELDS} }
|
|
1509
|
+
}
|
|
1510
|
+
`;
|
|
1511
|
+
function createCommentsQueries2(fetcher) {
|
|
1512
|
+
const { gqlFetchGraceful } = fetcher;
|
|
1513
|
+
async function getCommentsByPostId(postId, first = 10, after) {
|
|
1514
|
+
const data = await gqlFetchGraceful(
|
|
1515
|
+
GQL_GET_COMMENTS_BY_POST,
|
|
1516
|
+
{ comments: { nodes: [], pageInfo: { hasNextPage: false } } },
|
|
1517
|
+
{ contentId: String(postId), first, after },
|
|
1518
|
+
["wpgraphql", "gql-comments", `gql-comments-post-${postId}`]
|
|
1519
|
+
);
|
|
1520
|
+
return data.comments;
|
|
1521
|
+
}
|
|
1522
|
+
async function getAllCommentsByPostId(postId) {
|
|
1523
|
+
const data = await gqlFetchGraceful(
|
|
1524
|
+
GQL_GET_ALL_COMMENTS_BY_POST,
|
|
1525
|
+
{ comments: { nodes: [] } },
|
|
1526
|
+
{ contentId: String(postId) },
|
|
1527
|
+
["wpgraphql", "gql-comments", `gql-comments-post-${postId}`]
|
|
1528
|
+
);
|
|
1529
|
+
return data.comments.nodes;
|
|
1530
|
+
}
|
|
1531
|
+
async function getCommentById(id) {
|
|
1532
|
+
const data = await gqlFetchGraceful(
|
|
1533
|
+
GQL_GET_COMMENT_BY_ID,
|
|
1534
|
+
{ comment: null },
|
|
1535
|
+
{ id: String(id) },
|
|
1536
|
+
["wpgraphql", "gql-comments", `gql-comment-${id}`]
|
|
1537
|
+
);
|
|
1538
|
+
return data.comment;
|
|
1539
|
+
}
|
|
1540
|
+
return {
|
|
1541
|
+
getCommentsByPostId,
|
|
1542
|
+
getAllCommentsByPostId,
|
|
1543
|
+
getCommentById
|
|
1544
|
+
};
|
|
1545
|
+
}
|
|
1546
|
+
|
|
1263
1547
|
// src/integrations/wpGraphQL/core/index.ts
|
|
1264
1548
|
function createWPGraphQLCoreClient(config) {
|
|
1265
1549
|
const fetcher = createWPGraphQLFetcher(config);
|
|
@@ -1268,7 +1552,9 @@ function createWPGraphQLCoreClient(config) {
|
|
|
1268
1552
|
...createPagesQueries2(fetcher),
|
|
1269
1553
|
...createCategoriesQueries3(fetcher),
|
|
1270
1554
|
...createTagsQueries3(fetcher),
|
|
1271
|
-
...createAuthorsQueries2(fetcher)
|
|
1555
|
+
...createAuthorsQueries2(fetcher),
|
|
1556
|
+
...createMenusQueries2(fetcher),
|
|
1557
|
+
...createCommentsQueries2(fetcher)
|
|
1272
1558
|
};
|
|
1273
1559
|
}
|
|
1274
1560
|
|
|
@@ -1444,22 +1730,31 @@ var PRODUCT_FIELDS = `
|
|
|
1444
1730
|
databaseId
|
|
1445
1731
|
slug
|
|
1446
1732
|
name
|
|
1733
|
+
status
|
|
1447
1734
|
description
|
|
1448
1735
|
shortDescription
|
|
1449
|
-
sku
|
|
1450
|
-
price
|
|
1451
|
-
regularPrice
|
|
1452
|
-
salePrice
|
|
1453
|
-
onSale
|
|
1454
|
-
stockStatus
|
|
1455
|
-
stockQuantity
|
|
1456
|
-
manageStock
|
|
1457
1736
|
type
|
|
1737
|
+
onSale
|
|
1458
1738
|
featuredImage { node { sourceUrl altText } }
|
|
1459
1739
|
galleryImages { nodes { sourceUrl altText } }
|
|
1460
1740
|
productCategories { nodes { databaseId name slug } }
|
|
1461
1741
|
productTags { nodes { databaseId name slug } }
|
|
1742
|
+
... on SimpleProduct {
|
|
1743
|
+
sku
|
|
1744
|
+
price
|
|
1745
|
+
regularPrice
|
|
1746
|
+
salePrice
|
|
1747
|
+
stockStatus
|
|
1748
|
+
stockQuantity
|
|
1749
|
+
manageStock
|
|
1750
|
+
}
|
|
1462
1751
|
... on VariableProduct {
|
|
1752
|
+
price
|
|
1753
|
+
regularPrice
|
|
1754
|
+
salePrice
|
|
1755
|
+
stockStatus
|
|
1756
|
+
stockQuantity
|
|
1757
|
+
manageStock
|
|
1463
1758
|
variations {
|
|
1464
1759
|
nodes {
|
|
1465
1760
|
id
|