@szymonpiatek/nextwordpress 0.0.1 → 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 +1322 -31
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +571 -27
- package/dist/index.d.ts +571 -27
- package/dist/index.js +1312 -30
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -2,10 +2,22 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
4
|
|
|
5
|
-
// src/
|
|
5
|
+
// src/shared/url.ts
|
|
6
6
|
function resolveBaseUrl(config) {
|
|
7
7
|
return typeof window === "undefined" ? config.serverURL : config.clientURL;
|
|
8
8
|
}
|
|
9
|
+
|
|
10
|
+
// src/integrations/restApi/core/client/types.ts
|
|
11
|
+
var WordPressAPIError = class extends Error {
|
|
12
|
+
constructor(message, status, endpoint) {
|
|
13
|
+
super(message);
|
|
14
|
+
__publicField(this, "status", status);
|
|
15
|
+
__publicField(this, "endpoint", endpoint);
|
|
16
|
+
this.name = "WordPressAPIError";
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// src/integrations/restApi/core/client/url.ts
|
|
9
21
|
function buildUrl(config, path, query) {
|
|
10
22
|
const base = resolveBaseUrl(config);
|
|
11
23
|
if (!query) return `${base}${path}`;
|
|
@@ -19,17 +31,7 @@ function buildUrl(config, path, query) {
|
|
|
19
31
|
return qs ? `${base}${path}?${qs}` : `${base}${path}`;
|
|
20
32
|
}
|
|
21
33
|
|
|
22
|
-
// src/client/
|
|
23
|
-
var WordPressAPIError = class extends Error {
|
|
24
|
-
constructor(message, status, endpoint) {
|
|
25
|
-
super(message);
|
|
26
|
-
__publicField(this, "status", status);
|
|
27
|
-
__publicField(this, "endpoint", endpoint);
|
|
28
|
-
this.name = "WordPressAPIError";
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
// src/client/fetcher/fetcher.ts
|
|
34
|
+
// src/integrations/restApi/core/client/fetcher.ts
|
|
33
35
|
var USER_AGENT = "NextWordpress Client";
|
|
34
36
|
async function doFetch(url, init = {}) {
|
|
35
37
|
const response = await fetch(url, init);
|
|
@@ -99,7 +101,7 @@ function createFetcher(config) {
|
|
|
99
101
|
return { wpFetch, wpFetchGraceful, wpFetchPaginated, wpFetchPaginatedGraceful, wpMutate };
|
|
100
102
|
}
|
|
101
103
|
|
|
102
|
-
// src/integrations/
|
|
104
|
+
// src/integrations/restApi/core/posts/queries.ts
|
|
103
105
|
function createPostsQueries(fetcher) {
|
|
104
106
|
const { wpFetch, wpFetchGraceful, wpFetchPaginated, wpFetchPaginatedGraceful } = fetcher;
|
|
105
107
|
async function getPostsPaginated(page = 1, perPage = 9, filterParams) {
|
|
@@ -227,7 +229,7 @@ function createPostsQueries(fetcher) {
|
|
|
227
229
|
};
|
|
228
230
|
}
|
|
229
231
|
|
|
230
|
-
// src/integrations/
|
|
232
|
+
// src/integrations/restApi/core/categories/queries.ts
|
|
231
233
|
function createCategoriesQueries(fetcher) {
|
|
232
234
|
const { wpFetch, wpFetchGraceful } = fetcher;
|
|
233
235
|
async function getAllCategories() {
|
|
@@ -252,7 +254,7 @@ function createCategoriesQueries(fetcher) {
|
|
|
252
254
|
return { getAllCategories, getCategoryById, getCategoryBySlug, searchCategories };
|
|
253
255
|
}
|
|
254
256
|
|
|
255
|
-
// src/integrations/
|
|
257
|
+
// src/integrations/restApi/core/tags/queries.ts
|
|
256
258
|
function createTagsQueries(fetcher) {
|
|
257
259
|
const { wpFetch, wpFetchGraceful } = fetcher;
|
|
258
260
|
async function getAllTags() {
|
|
@@ -277,7 +279,7 @@ function createTagsQueries(fetcher) {
|
|
|
277
279
|
return { getAllTags, getTagById, getTagBySlug, getTagsByPost, searchTags };
|
|
278
280
|
}
|
|
279
281
|
|
|
280
|
-
// src/integrations/
|
|
282
|
+
// src/integrations/restApi/core/authors/queries.ts
|
|
281
283
|
function createAuthorsQueries(fetcher) {
|
|
282
284
|
const { wpFetch, wpFetchGraceful } = fetcher;
|
|
283
285
|
async function getAllAuthors() {
|
|
@@ -299,7 +301,7 @@ function createAuthorsQueries(fetcher) {
|
|
|
299
301
|
return { getAllAuthors, getAuthorById, getAuthorBySlug, searchAuthors };
|
|
300
302
|
}
|
|
301
303
|
|
|
302
|
-
// src/integrations/
|
|
304
|
+
// src/integrations/restApi/core/media/queries.ts
|
|
303
305
|
function createMediaQueries(fetcher) {
|
|
304
306
|
const { wpFetch } = fetcher;
|
|
305
307
|
async function getFeaturedMediaById(id) {
|
|
@@ -308,7 +310,7 @@ function createMediaQueries(fetcher) {
|
|
|
308
310
|
return { getFeaturedMediaById };
|
|
309
311
|
}
|
|
310
312
|
|
|
311
|
-
// src/integrations/
|
|
313
|
+
// src/integrations/restApi/core/pages/queries.ts
|
|
312
314
|
function createPagesQueries(fetcher) {
|
|
313
315
|
const { wpFetch, wpFetchGraceful } = fetcher;
|
|
314
316
|
async function getAllPages() {
|
|
@@ -327,7 +329,101 @@ function createPagesQueries(fetcher) {
|
|
|
327
329
|
return { getAllPages, getPageById, getPageBySlug };
|
|
328
330
|
}
|
|
329
331
|
|
|
330
|
-
// src/integrations/
|
|
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
|
+
|
|
426
|
+
// src/integrations/restApi/core/index.ts
|
|
331
427
|
function createWordPressClient(config) {
|
|
332
428
|
const fetcher = createFetcher(config);
|
|
333
429
|
return {
|
|
@@ -336,11 +432,13 @@ function createWordPressClient(config) {
|
|
|
336
432
|
...createTagsQueries(fetcher),
|
|
337
433
|
...createAuthorsQueries(fetcher),
|
|
338
434
|
...createMediaQueries(fetcher),
|
|
339
|
-
...createPagesQueries(fetcher)
|
|
435
|
+
...createPagesQueries(fetcher),
|
|
436
|
+
...createMenusQueries(fetcher),
|
|
437
|
+
...createCommentsQueries(fetcher)
|
|
340
438
|
};
|
|
341
439
|
}
|
|
342
440
|
|
|
343
|
-
// src/integrations/woocommerce/omnibus/queries.ts
|
|
441
|
+
// src/integrations/restApi/woocommerce/omnibus/queries.ts
|
|
344
442
|
var META_KEY_LOWEST_PRICE = "wpo_lowest_price";
|
|
345
443
|
var META_KEY_PRICE_HISTORY = "_alg_wc_price_history";
|
|
346
444
|
function extractMetaValue(meta_data, key) {
|
|
@@ -369,7 +467,7 @@ function withOmnibusVariation(variation) {
|
|
|
369
467
|
};
|
|
370
468
|
}
|
|
371
469
|
|
|
372
|
-
// src/integrations/woocommerce/client/fetcher.ts
|
|
470
|
+
// src/integrations/restApi/woocommerce/client/fetcher.ts
|
|
373
471
|
var USER_AGENT2 = "NextWordpress WooCommerce Client";
|
|
374
472
|
var DEFAULT_CACHE_TTL = 3600;
|
|
375
473
|
function toQueryString(params) {
|
|
@@ -451,7 +549,7 @@ function createWooCommerceFetcher(config) {
|
|
|
451
549
|
return { wcFetch, wcFetchGraceful, wcFetchPaginated, wcFetchPaginatedGraceful, wcMutate };
|
|
452
550
|
}
|
|
453
551
|
|
|
454
|
-
// src/integrations/woocommerce/products/queries.ts
|
|
552
|
+
// src/integrations/restApi/woocommerce/products/queries.ts
|
|
455
553
|
function buildProductQuery(base, filterParams) {
|
|
456
554
|
const query = { ...base };
|
|
457
555
|
if (!filterParams) return query;
|
|
@@ -578,7 +676,7 @@ function createProductsQueries(fetcher) {
|
|
|
578
676
|
};
|
|
579
677
|
}
|
|
580
678
|
|
|
581
|
-
// src/integrations/woocommerce/categories/queries.ts
|
|
679
|
+
// src/integrations/restApi/woocommerce/categories/queries.ts
|
|
582
680
|
function createCategoriesQueries2(fetcher) {
|
|
583
681
|
const { wcFetch, wcFetchGraceful } = fetcher;
|
|
584
682
|
async function getAllProductCategories() {
|
|
@@ -627,7 +725,7 @@ function createCategoriesQueries2(fetcher) {
|
|
|
627
725
|
};
|
|
628
726
|
}
|
|
629
727
|
|
|
630
|
-
// src/integrations/woocommerce/tags/queries.ts
|
|
728
|
+
// src/integrations/restApi/woocommerce/tags/queries.ts
|
|
631
729
|
function createTagsQueries2(fetcher) {
|
|
632
730
|
const { wcFetch, wcFetchGraceful } = fetcher;
|
|
633
731
|
async function getAllProductTags() {
|
|
@@ -660,7 +758,7 @@ function createTagsQueries2(fetcher) {
|
|
|
660
758
|
};
|
|
661
759
|
}
|
|
662
760
|
|
|
663
|
-
// src/integrations/woocommerce/orders/queries.ts
|
|
761
|
+
// src/integrations/restApi/woocommerce/orders/queries.ts
|
|
664
762
|
function createOrdersQueries(fetcher) {
|
|
665
763
|
const { wcFetch, wcFetchGraceful, wcMutate } = fetcher;
|
|
666
764
|
async function createOrder(input) {
|
|
@@ -692,7 +790,7 @@ function createOrdersQueries(fetcher) {
|
|
|
692
790
|
};
|
|
693
791
|
}
|
|
694
792
|
|
|
695
|
-
// src/integrations/woocommerce/coupons/queries.ts
|
|
793
|
+
// src/integrations/restApi/woocommerce/coupons/queries.ts
|
|
696
794
|
function createCouponsQueries(fetcher) {
|
|
697
795
|
const { wcFetchGraceful } = fetcher;
|
|
698
796
|
async function getCouponByCode(code) {
|
|
@@ -722,7 +820,7 @@ function createCouponsQueries(fetcher) {
|
|
|
722
820
|
};
|
|
723
821
|
}
|
|
724
822
|
|
|
725
|
-
// src/integrations/woocommerce/customers/queries.ts
|
|
823
|
+
// src/integrations/restApi/woocommerce/customers/queries.ts
|
|
726
824
|
function createCustomersQueries(fetcher) {
|
|
727
825
|
const { wcFetch, wcFetchGraceful } = fetcher;
|
|
728
826
|
async function getCustomerById(id) {
|
|
@@ -770,7 +868,7 @@ function createCustomersQueries(fetcher) {
|
|
|
770
868
|
};
|
|
771
869
|
}
|
|
772
870
|
|
|
773
|
-
// src/integrations/woocommerce/index.ts
|
|
871
|
+
// src/integrations/restApi/woocommerce/index.ts
|
|
774
872
|
function createWooCommerceClient(config) {
|
|
775
873
|
const fetcher = createWooCommerceFetcher(config);
|
|
776
874
|
return {
|
|
@@ -783,6 +881,1190 @@ function createWooCommerceClient(config) {
|
|
|
783
881
|
};
|
|
784
882
|
}
|
|
785
883
|
|
|
786
|
-
|
|
884
|
+
// src/integrations/wpGraphQL/client/types.ts
|
|
885
|
+
var WPGraphQLError = class extends Error {
|
|
886
|
+
constructor(message, status, endpoint, gqlErrors) {
|
|
887
|
+
super(message);
|
|
888
|
+
__publicField(this, "status", status);
|
|
889
|
+
__publicField(this, "endpoint", endpoint);
|
|
890
|
+
__publicField(this, "gqlErrors", gqlErrors);
|
|
891
|
+
this.name = "WPGraphQLError";
|
|
892
|
+
}
|
|
893
|
+
};
|
|
894
|
+
|
|
895
|
+
// src/integrations/wpGraphQL/client/fetcher.ts
|
|
896
|
+
var USER_AGENT3 = "NextWordpress WPGraphQL Client";
|
|
897
|
+
var CACHE_TTL = 300;
|
|
898
|
+
function createWPGraphQLFetcher(config) {
|
|
899
|
+
const url = `${resolveBaseUrl(config)}/graphql`;
|
|
900
|
+
async function gqlFetch(document, variables, tags = ["wpgraphql"]) {
|
|
901
|
+
const response = await fetch(url, {
|
|
902
|
+
method: "POST",
|
|
903
|
+
headers: {
|
|
904
|
+
"Content-Type": "application/json",
|
|
905
|
+
"User-Agent": USER_AGENT3
|
|
906
|
+
},
|
|
907
|
+
body: JSON.stringify({ query: document, variables }),
|
|
908
|
+
next: { tags, revalidate: CACHE_TTL }
|
|
909
|
+
});
|
|
910
|
+
if (!response.ok) {
|
|
911
|
+
throw new WPGraphQLError(
|
|
912
|
+
`WPGraphQL request failed: ${response.statusText}`,
|
|
913
|
+
response.status,
|
|
914
|
+
url
|
|
915
|
+
);
|
|
916
|
+
}
|
|
917
|
+
const parsed = await response.json();
|
|
918
|
+
if (parsed.errors && parsed.errors.length > 0) {
|
|
919
|
+
throw new WPGraphQLError(
|
|
920
|
+
parsed.errors[0].message,
|
|
921
|
+
200,
|
|
922
|
+
url,
|
|
923
|
+
parsed.errors
|
|
924
|
+
);
|
|
925
|
+
}
|
|
926
|
+
if (parsed.data === void 0) {
|
|
927
|
+
throw new WPGraphQLError("No data returned from WPGraphQL", 200, url);
|
|
928
|
+
}
|
|
929
|
+
return parsed.data;
|
|
930
|
+
}
|
|
931
|
+
async function gqlFetchGraceful(document, fallback, variables, tags = ["wpgraphql"]) {
|
|
932
|
+
try {
|
|
933
|
+
return await gqlFetch(document, variables, tags);
|
|
934
|
+
} catch {
|
|
935
|
+
console.warn(`WPGraphQL fetch failed for query`);
|
|
936
|
+
return fallback;
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
return { gqlFetch, gqlFetchGraceful };
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
// src/integrations/wpGraphQL/core/posts/queries.ts
|
|
943
|
+
var DEFAULT_FIRST = 10;
|
|
944
|
+
var BATCH_FIRST = 100;
|
|
945
|
+
var POST_FIELDS = `
|
|
946
|
+
id
|
|
947
|
+
databaseId
|
|
948
|
+
slug
|
|
949
|
+
title
|
|
950
|
+
excerpt
|
|
951
|
+
date
|
|
952
|
+
modified
|
|
953
|
+
status
|
|
954
|
+
uri
|
|
955
|
+
author {
|
|
956
|
+
node {
|
|
957
|
+
databaseId
|
|
958
|
+
name
|
|
959
|
+
slug
|
|
960
|
+
avatar { url }
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
featuredImage {
|
|
964
|
+
node {
|
|
965
|
+
sourceUrl
|
|
966
|
+
altText
|
|
967
|
+
mediaDetails { width height }
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
categories {
|
|
971
|
+
nodes { databaseId name slug }
|
|
972
|
+
}
|
|
973
|
+
tags {
|
|
974
|
+
nodes { databaseId name slug }
|
|
975
|
+
}
|
|
976
|
+
`;
|
|
977
|
+
var POST_FIELDS_WITH_CONTENT = `
|
|
978
|
+
${POST_FIELDS}
|
|
979
|
+
content
|
|
980
|
+
`;
|
|
981
|
+
var GQL_GET_POSTS = `
|
|
982
|
+
query GetPosts($first: Int, $after: String, $where: RootQueryToPostConnectionWhereArgs) {
|
|
983
|
+
posts(first: $first, after: $after, where: $where) {
|
|
984
|
+
nodes { ${POST_FIELDS} }
|
|
985
|
+
pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
`;
|
|
989
|
+
var GQL_GET_POST_BY_SLUG = `
|
|
990
|
+
query GetPostBySlug($slug: ID!) {
|
|
991
|
+
post(id: $slug, idType: SLUG) { ${POST_FIELDS_WITH_CONTENT} }
|
|
992
|
+
}
|
|
993
|
+
`;
|
|
994
|
+
var GQL_GET_POST_BY_DATABASE_ID = `
|
|
995
|
+
query GetPostByDatabaseId($id: ID!) {
|
|
996
|
+
post(id: $id, idType: DATABASE_ID) { ${POST_FIELDS_WITH_CONTENT} }
|
|
997
|
+
}
|
|
998
|
+
`;
|
|
999
|
+
var GQL_GET_ALL_POST_SLUGS = `
|
|
1000
|
+
query GetAllPostSlugs($first: Int, $after: String) {
|
|
1001
|
+
posts(first: $first, after: $after) {
|
|
1002
|
+
nodes { slug }
|
|
1003
|
+
pageInfo { hasNextPage endCursor }
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
`;
|
|
1007
|
+
var GQL_GET_ALL_POSTS_FOR_SITEMAP = `
|
|
1008
|
+
query GetAllPostsForSitemap($first: Int, $after: String) {
|
|
1009
|
+
posts(first: $first, after: $after) {
|
|
1010
|
+
nodes { slug modified }
|
|
1011
|
+
pageInfo { hasNextPage endCursor }
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
`;
|
|
1015
|
+
function createPostsQueries2(fetcher) {
|
|
1016
|
+
const { gqlFetch, gqlFetchGraceful } = fetcher;
|
|
1017
|
+
async function getPosts(first = DEFAULT_FIRST, after, filter) {
|
|
1018
|
+
const where = {};
|
|
1019
|
+
if (filter?.authorName) where["authorName"] = filter.authorName;
|
|
1020
|
+
if (filter?.categoryName) where["categoryName"] = filter.categoryName;
|
|
1021
|
+
if (filter?.tag) where["tag"] = filter.tag;
|
|
1022
|
+
if (filter?.search) where["search"] = filter.search;
|
|
1023
|
+
if (filter?.status) where["status"] = filter.status;
|
|
1024
|
+
const data = await gqlFetchGraceful(
|
|
1025
|
+
GQL_GET_POSTS,
|
|
1026
|
+
{ posts: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
|
|
1027
|
+
{ first, after, where: Object.keys(where).length > 0 ? where : void 0 },
|
|
1028
|
+
["wpgraphql", "gql-posts"]
|
|
1029
|
+
);
|
|
1030
|
+
return data.posts;
|
|
1031
|
+
}
|
|
1032
|
+
async function getPostBySlug(slug) {
|
|
1033
|
+
const data = await gqlFetchGraceful(
|
|
1034
|
+
GQL_GET_POST_BY_SLUG,
|
|
1035
|
+
{ post: null },
|
|
1036
|
+
{ slug },
|
|
1037
|
+
["wpgraphql", "gql-posts", `gql-post-${slug}`]
|
|
1038
|
+
);
|
|
1039
|
+
return data.post;
|
|
1040
|
+
}
|
|
1041
|
+
async function getPostByDatabaseId(id) {
|
|
1042
|
+
const data = await gqlFetchGraceful(
|
|
1043
|
+
GQL_GET_POST_BY_DATABASE_ID,
|
|
1044
|
+
{ post: null },
|
|
1045
|
+
{ id: String(id) },
|
|
1046
|
+
["wpgraphql", "gql-posts", `gql-post-id-${id}`]
|
|
1047
|
+
);
|
|
1048
|
+
return data.post;
|
|
1049
|
+
}
|
|
1050
|
+
async function getRecentPosts(first = DEFAULT_FIRST) {
|
|
1051
|
+
const connection = await getPosts(first);
|
|
1052
|
+
return connection.nodes;
|
|
1053
|
+
}
|
|
1054
|
+
async function getAllPostSlugs() {
|
|
1055
|
+
try {
|
|
1056
|
+
const all = [];
|
|
1057
|
+
let after = void 0;
|
|
1058
|
+
let hasNextPage = true;
|
|
1059
|
+
while (hasNextPage) {
|
|
1060
|
+
const data = await gqlFetch(GQL_GET_ALL_POST_SLUGS, { first: BATCH_FIRST, after }, ["wpgraphql"]);
|
|
1061
|
+
all.push(...data.posts.nodes);
|
|
1062
|
+
hasNextPage = data.posts.pageInfo.hasNextPage;
|
|
1063
|
+
after = data.posts.pageInfo.endCursor;
|
|
1064
|
+
}
|
|
1065
|
+
return all;
|
|
1066
|
+
} catch {
|
|
1067
|
+
console.warn("WPGraphQL unavailable, skipping static generation for posts");
|
|
1068
|
+
return [];
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
async function getAllPostsForSitemap() {
|
|
1072
|
+
try {
|
|
1073
|
+
const all = [];
|
|
1074
|
+
let after = void 0;
|
|
1075
|
+
let hasNextPage = true;
|
|
1076
|
+
while (hasNextPage) {
|
|
1077
|
+
const data = await gqlFetch(
|
|
1078
|
+
GQL_GET_ALL_POSTS_FOR_SITEMAP,
|
|
1079
|
+
{ first: BATCH_FIRST, after },
|
|
1080
|
+
["wpgraphql"]
|
|
1081
|
+
);
|
|
1082
|
+
all.push(...data.posts.nodes);
|
|
1083
|
+
hasNextPage = data.posts.pageInfo.hasNextPage;
|
|
1084
|
+
after = data.posts.pageInfo.endCursor;
|
|
1085
|
+
}
|
|
1086
|
+
return all;
|
|
1087
|
+
} catch {
|
|
1088
|
+
console.warn("WPGraphQL unavailable, skipping sitemap generation");
|
|
1089
|
+
return [];
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
return {
|
|
1093
|
+
getPosts,
|
|
1094
|
+
getPostBySlug,
|
|
1095
|
+
getPostByDatabaseId,
|
|
1096
|
+
getRecentPosts,
|
|
1097
|
+
getAllPostSlugs,
|
|
1098
|
+
getAllPostsForSitemap
|
|
1099
|
+
};
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
// src/integrations/wpGraphQL/core/pages/queries.ts
|
|
1103
|
+
var DEFAULT_FIRST2 = 10;
|
|
1104
|
+
var BATCH_FIRST2 = 100;
|
|
1105
|
+
var PAGE_FIELDS = `
|
|
1106
|
+
id
|
|
1107
|
+
databaseId
|
|
1108
|
+
slug
|
|
1109
|
+
title
|
|
1110
|
+
content
|
|
1111
|
+
date
|
|
1112
|
+
modified
|
|
1113
|
+
status
|
|
1114
|
+
uri
|
|
1115
|
+
featuredImage {
|
|
1116
|
+
node {
|
|
1117
|
+
sourceUrl
|
|
1118
|
+
altText
|
|
1119
|
+
mediaDetails { width height }
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1122
|
+
`;
|
|
1123
|
+
var GQL_GET_PAGES = `
|
|
1124
|
+
query GetPages($first: Int, $after: String) {
|
|
1125
|
+
pages(first: $first, after: $after) {
|
|
1126
|
+
nodes { ${PAGE_FIELDS} }
|
|
1127
|
+
pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
`;
|
|
1131
|
+
var GQL_GET_PAGE_BY_SLUG = `
|
|
1132
|
+
query GetPageBySlug($uri: ID!) {
|
|
1133
|
+
page(id: $uri, idType: URI) { ${PAGE_FIELDS} }
|
|
1134
|
+
}
|
|
1135
|
+
`;
|
|
1136
|
+
var GQL_GET_PAGE_BY_URI = `
|
|
1137
|
+
query GetPageByUri($uri: ID!) {
|
|
1138
|
+
page(id: $uri, idType: URI) { ${PAGE_FIELDS} }
|
|
1139
|
+
}
|
|
1140
|
+
`;
|
|
1141
|
+
var GQL_GET_ALL_PAGE_URIS = `
|
|
1142
|
+
query GetAllPageUris($first: Int, $after: String) {
|
|
1143
|
+
pages(first: $first, after: $after) {
|
|
1144
|
+
nodes { uri }
|
|
1145
|
+
pageInfo { hasNextPage endCursor }
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
`;
|
|
1149
|
+
function createPagesQueries2(fetcher) {
|
|
1150
|
+
const { gqlFetch, gqlFetchGraceful } = fetcher;
|
|
1151
|
+
async function getPages(first = DEFAULT_FIRST2, after) {
|
|
1152
|
+
const data = await gqlFetchGraceful(
|
|
1153
|
+
GQL_GET_PAGES,
|
|
1154
|
+
{ pages: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
|
|
1155
|
+
{ first, after },
|
|
1156
|
+
["wpgraphql", "gql-pages"]
|
|
1157
|
+
);
|
|
1158
|
+
return data.pages;
|
|
1159
|
+
}
|
|
1160
|
+
async function getPageBySlug(slug) {
|
|
1161
|
+
const data = await gqlFetchGraceful(
|
|
1162
|
+
GQL_GET_PAGE_BY_SLUG,
|
|
1163
|
+
{ page: null },
|
|
1164
|
+
{ uri: `/${slug}/` },
|
|
1165
|
+
["wpgraphql", "gql-pages", `gql-page-${slug}`]
|
|
1166
|
+
);
|
|
1167
|
+
return data.page;
|
|
1168
|
+
}
|
|
1169
|
+
async function getPageByUri(uri) {
|
|
1170
|
+
const data = await gqlFetchGraceful(
|
|
1171
|
+
GQL_GET_PAGE_BY_URI,
|
|
1172
|
+
{ page: null },
|
|
1173
|
+
{ uri },
|
|
1174
|
+
["wpgraphql", "gql-pages", `gql-page-uri-${uri.replace(/\//g, "-")}`]
|
|
1175
|
+
);
|
|
1176
|
+
return data.page;
|
|
1177
|
+
}
|
|
1178
|
+
async function getAllPageUris() {
|
|
1179
|
+
try {
|
|
1180
|
+
const all = [];
|
|
1181
|
+
let after = void 0;
|
|
1182
|
+
let hasNextPage = true;
|
|
1183
|
+
while (hasNextPage) {
|
|
1184
|
+
const data = await gqlFetch(GQL_GET_ALL_PAGE_URIS, { first: BATCH_FIRST2, after }, ["wpgraphql"]);
|
|
1185
|
+
all.push(...data.pages.nodes);
|
|
1186
|
+
hasNextPage = data.pages.pageInfo.hasNextPage;
|
|
1187
|
+
after = data.pages.pageInfo.endCursor;
|
|
1188
|
+
}
|
|
1189
|
+
return all;
|
|
1190
|
+
} catch {
|
|
1191
|
+
console.warn("WPGraphQL unavailable, skipping static generation for pages");
|
|
1192
|
+
return [];
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
return { getPages, getPageBySlug, getPageByUri, getAllPageUris };
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1198
|
+
// src/integrations/wpGraphQL/core/categories/queries.ts
|
|
1199
|
+
var DEFAULT_FIRST3 = 100;
|
|
1200
|
+
var CATEGORY_FIELDS = `
|
|
1201
|
+
id
|
|
1202
|
+
databaseId
|
|
1203
|
+
name
|
|
1204
|
+
slug
|
|
1205
|
+
description
|
|
1206
|
+
count
|
|
1207
|
+
uri
|
|
1208
|
+
parent {
|
|
1209
|
+
node { databaseId name slug }
|
|
1210
|
+
}
|
|
1211
|
+
`;
|
|
1212
|
+
var GQL_GET_CATEGORIES = `
|
|
1213
|
+
query GetCategories($first: Int, $after: String) {
|
|
1214
|
+
categories(first: $first, after: $after) {
|
|
1215
|
+
nodes { ${CATEGORY_FIELDS} }
|
|
1216
|
+
pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
`;
|
|
1220
|
+
var GQL_GET_CATEGORY_BY_SLUG = `
|
|
1221
|
+
query GetCategoryBySlug($slug: ID!) {
|
|
1222
|
+
category(id: $slug, idType: SLUG) { ${CATEGORY_FIELDS} }
|
|
1223
|
+
}
|
|
1224
|
+
`;
|
|
1225
|
+
var GQL_GET_CATEGORY_BY_DATABASE_ID = `
|
|
1226
|
+
query GetCategoryByDatabaseId($id: ID!) {
|
|
1227
|
+
category(id: $id, idType: DATABASE_ID) { ${CATEGORY_FIELDS} }
|
|
1228
|
+
}
|
|
1229
|
+
`;
|
|
1230
|
+
function createCategoriesQueries3(fetcher) {
|
|
1231
|
+
const { gqlFetchGraceful } = fetcher;
|
|
1232
|
+
async function getCategories(first = DEFAULT_FIRST3, after) {
|
|
1233
|
+
const data = await gqlFetchGraceful(
|
|
1234
|
+
GQL_GET_CATEGORIES,
|
|
1235
|
+
{ categories: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
|
|
1236
|
+
{ first, after },
|
|
1237
|
+
["wpgraphql", "gql-categories"]
|
|
1238
|
+
);
|
|
1239
|
+
return data.categories;
|
|
1240
|
+
}
|
|
1241
|
+
async function getCategoryBySlug(slug) {
|
|
1242
|
+
const data = await gqlFetchGraceful(
|
|
1243
|
+
GQL_GET_CATEGORY_BY_SLUG,
|
|
1244
|
+
{ category: null },
|
|
1245
|
+
{ slug },
|
|
1246
|
+
["wpgraphql", "gql-categories", `gql-category-${slug}`]
|
|
1247
|
+
);
|
|
1248
|
+
return data.category;
|
|
1249
|
+
}
|
|
1250
|
+
async function getCategoryByDatabaseId(id) {
|
|
1251
|
+
const data = await gqlFetchGraceful(
|
|
1252
|
+
GQL_GET_CATEGORY_BY_DATABASE_ID,
|
|
1253
|
+
{ category: null },
|
|
1254
|
+
{ id: String(id) },
|
|
1255
|
+
["wpgraphql", "gql-categories", `gql-category-id-${id}`]
|
|
1256
|
+
);
|
|
1257
|
+
return data.category;
|
|
1258
|
+
}
|
|
1259
|
+
return { getCategories, getCategoryBySlug, getCategoryByDatabaseId };
|
|
1260
|
+
}
|
|
1261
|
+
|
|
1262
|
+
// src/integrations/wpGraphQL/core/tags/queries.ts
|
|
1263
|
+
var DEFAULT_FIRST4 = 100;
|
|
1264
|
+
var TAG_FIELDS = `
|
|
1265
|
+
id
|
|
1266
|
+
databaseId
|
|
1267
|
+
name
|
|
1268
|
+
slug
|
|
1269
|
+
description
|
|
1270
|
+
count
|
|
1271
|
+
uri
|
|
1272
|
+
`;
|
|
1273
|
+
var GQL_GET_TAGS = `
|
|
1274
|
+
query GetTags($first: Int, $after: String) {
|
|
1275
|
+
tags(first: $first, after: $after) {
|
|
1276
|
+
nodes { ${TAG_FIELDS} }
|
|
1277
|
+
pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
`;
|
|
1281
|
+
var GQL_GET_TAG_BY_SLUG = `
|
|
1282
|
+
query GetTagBySlug($slug: ID!) {
|
|
1283
|
+
tag(id: $slug, idType: SLUG) { ${TAG_FIELDS} }
|
|
1284
|
+
}
|
|
1285
|
+
`;
|
|
1286
|
+
function createTagsQueries3(fetcher) {
|
|
1287
|
+
const { gqlFetchGraceful } = fetcher;
|
|
1288
|
+
async function getTags(first = DEFAULT_FIRST4, after) {
|
|
1289
|
+
const data = await gqlFetchGraceful(
|
|
1290
|
+
GQL_GET_TAGS,
|
|
1291
|
+
{ tags: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
|
|
1292
|
+
{ first, after },
|
|
1293
|
+
["wpgraphql", "gql-tags"]
|
|
1294
|
+
);
|
|
1295
|
+
return data.tags;
|
|
1296
|
+
}
|
|
1297
|
+
async function getTagBySlug(slug) {
|
|
1298
|
+
const data = await gqlFetchGraceful(
|
|
1299
|
+
GQL_GET_TAG_BY_SLUG,
|
|
1300
|
+
{ tag: null },
|
|
1301
|
+
{ slug },
|
|
1302
|
+
["wpgraphql", "gql-tags", `gql-tag-${slug}`]
|
|
1303
|
+
);
|
|
1304
|
+
return data.tag;
|
|
1305
|
+
}
|
|
1306
|
+
return { getTags, getTagBySlug };
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1309
|
+
// src/integrations/wpGraphQL/core/authors/queries.ts
|
|
1310
|
+
var DEFAULT_FIRST5 = 100;
|
|
1311
|
+
var AUTHOR_FIELDS = `
|
|
1312
|
+
id
|
|
1313
|
+
databaseId
|
|
1314
|
+
name
|
|
1315
|
+
slug
|
|
1316
|
+
description
|
|
1317
|
+
email
|
|
1318
|
+
uri
|
|
1319
|
+
avatar { url width height }
|
|
1320
|
+
`;
|
|
1321
|
+
var GQL_GET_AUTHORS = `
|
|
1322
|
+
query GetAuthors($first: Int, $after: String) {
|
|
1323
|
+
users(first: $first, after: $after) {
|
|
1324
|
+
nodes { ${AUTHOR_FIELDS} }
|
|
1325
|
+
pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
`;
|
|
1329
|
+
var GQL_GET_AUTHOR_BY_SLUG = `
|
|
1330
|
+
query GetAuthorBySlug($slug: String!) {
|
|
1331
|
+
users(where: { login: $slug }) {
|
|
1332
|
+
nodes { ${AUTHOR_FIELDS} }
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
`;
|
|
1336
|
+
function createAuthorsQueries2(fetcher) {
|
|
1337
|
+
const { gqlFetchGraceful } = fetcher;
|
|
1338
|
+
async function getAuthors(first = DEFAULT_FIRST5, after) {
|
|
1339
|
+
const data = await gqlFetchGraceful(
|
|
1340
|
+
GQL_GET_AUTHORS,
|
|
1341
|
+
{ users: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
|
|
1342
|
+
{ first, after },
|
|
1343
|
+
["wpgraphql", "gql-authors"]
|
|
1344
|
+
);
|
|
1345
|
+
return data.users;
|
|
1346
|
+
}
|
|
1347
|
+
async function getAuthorBySlug(slug) {
|
|
1348
|
+
const data = await gqlFetchGraceful(
|
|
1349
|
+
GQL_GET_AUTHOR_BY_SLUG,
|
|
1350
|
+
{ users: { nodes: [] } },
|
|
1351
|
+
{ slug },
|
|
1352
|
+
["wpgraphql", "gql-authors", `gql-author-${slug}`]
|
|
1353
|
+
);
|
|
1354
|
+
return data.users.nodes[0] ?? null;
|
|
1355
|
+
}
|
|
1356
|
+
return { getAuthors, getAuthorBySlug };
|
|
1357
|
+
}
|
|
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
|
+
|
|
1547
|
+
// src/integrations/wpGraphQL/core/index.ts
|
|
1548
|
+
function createWPGraphQLCoreClient(config) {
|
|
1549
|
+
const fetcher = createWPGraphQLFetcher(config);
|
|
1550
|
+
return {
|
|
1551
|
+
...createPostsQueries2(fetcher),
|
|
1552
|
+
...createPagesQueries2(fetcher),
|
|
1553
|
+
...createCategoriesQueries3(fetcher),
|
|
1554
|
+
...createTagsQueries3(fetcher),
|
|
1555
|
+
...createAuthorsQueries2(fetcher),
|
|
1556
|
+
...createMenusQueries2(fetcher),
|
|
1557
|
+
...createCommentsQueries2(fetcher)
|
|
1558
|
+
};
|
|
1559
|
+
}
|
|
1560
|
+
|
|
1561
|
+
// src/integrations/wpGraphQL/yoast/queries.ts
|
|
1562
|
+
var SEO_FIELDS = `
|
|
1563
|
+
seo {
|
|
1564
|
+
title
|
|
1565
|
+
metaDesc
|
|
1566
|
+
canonical
|
|
1567
|
+
opengraphTitle
|
|
1568
|
+
opengraphDescription
|
|
1569
|
+
opengraphImage { sourceUrl altText }
|
|
1570
|
+
twitterTitle
|
|
1571
|
+
twitterDescription
|
|
1572
|
+
twitterImage { sourceUrl }
|
|
1573
|
+
schema { raw }
|
|
1574
|
+
}
|
|
1575
|
+
`;
|
|
1576
|
+
var POST_FIELDS_WITH_SEO = `
|
|
1577
|
+
id
|
|
1578
|
+
databaseId
|
|
1579
|
+
slug
|
|
1580
|
+
title
|
|
1581
|
+
content
|
|
1582
|
+
excerpt
|
|
1583
|
+
date
|
|
1584
|
+
modified
|
|
1585
|
+
status
|
|
1586
|
+
uri
|
|
1587
|
+
author {
|
|
1588
|
+
node {
|
|
1589
|
+
databaseId
|
|
1590
|
+
name
|
|
1591
|
+
slug
|
|
1592
|
+
avatar { url }
|
|
1593
|
+
}
|
|
1594
|
+
}
|
|
1595
|
+
featuredImage {
|
|
1596
|
+
node {
|
|
1597
|
+
sourceUrl
|
|
1598
|
+
altText
|
|
1599
|
+
mediaDetails { width height }
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
categories {
|
|
1603
|
+
nodes { databaseId name slug }
|
|
1604
|
+
}
|
|
1605
|
+
tags {
|
|
1606
|
+
nodes { databaseId name slug }
|
|
1607
|
+
}
|
|
1608
|
+
${SEO_FIELDS}
|
|
1609
|
+
`;
|
|
1610
|
+
var PAGE_FIELDS_WITH_SEO = `
|
|
1611
|
+
id
|
|
1612
|
+
databaseId
|
|
1613
|
+
slug
|
|
1614
|
+
title
|
|
1615
|
+
content
|
|
1616
|
+
date
|
|
1617
|
+
modified
|
|
1618
|
+
status
|
|
1619
|
+
uri
|
|
1620
|
+
featuredImage {
|
|
1621
|
+
node {
|
|
1622
|
+
sourceUrl
|
|
1623
|
+
altText
|
|
1624
|
+
mediaDetails { width height }
|
|
1625
|
+
}
|
|
1626
|
+
}
|
|
1627
|
+
${SEO_FIELDS}
|
|
1628
|
+
`;
|
|
1629
|
+
var GQL_GET_POST_WITH_SEO = `
|
|
1630
|
+
query GetPostWithSEO($slug: ID!) {
|
|
1631
|
+
post(id: $slug, idType: SLUG) { ${POST_FIELDS_WITH_SEO} }
|
|
1632
|
+
}
|
|
1633
|
+
`;
|
|
1634
|
+
var GQL_GET_PAGE_WITH_SEO = `
|
|
1635
|
+
query GetPageWithSEO($slug: ID!) {
|
|
1636
|
+
page(id: $slug, idType: SLUG) { ${PAGE_FIELDS_WITH_SEO} }
|
|
1637
|
+
}
|
|
1638
|
+
`;
|
|
1639
|
+
var GQL_GET_PAGE_WITH_SEO_BY_URI = `
|
|
1640
|
+
query GetPageWithSEOByUri($uri: ID!) {
|
|
1641
|
+
page(id: $uri, idType: URI) { ${PAGE_FIELDS_WITH_SEO} }
|
|
1642
|
+
}
|
|
1643
|
+
`;
|
|
1644
|
+
function createYoastQueries(fetcher) {
|
|
1645
|
+
const { gqlFetchGraceful } = fetcher;
|
|
1646
|
+
async function getPostWithSEO(slug) {
|
|
1647
|
+
const data = await gqlFetchGraceful(
|
|
1648
|
+
GQL_GET_POST_WITH_SEO,
|
|
1649
|
+
{ post: null },
|
|
1650
|
+
{ slug },
|
|
1651
|
+
["wpgraphql", "gql-posts", "gql-yoast", `gql-post-${slug}`]
|
|
1652
|
+
);
|
|
1653
|
+
return data.post;
|
|
1654
|
+
}
|
|
1655
|
+
async function getPageWithSEO(slug) {
|
|
1656
|
+
const data = await gqlFetchGraceful(
|
|
1657
|
+
GQL_GET_PAGE_WITH_SEO,
|
|
1658
|
+
{ page: null },
|
|
1659
|
+
{ slug },
|
|
1660
|
+
["wpgraphql", "gql-pages", "gql-yoast", `gql-page-${slug}`]
|
|
1661
|
+
);
|
|
1662
|
+
return data.page;
|
|
1663
|
+
}
|
|
1664
|
+
async function getPageWithSEOByUri(uri) {
|
|
1665
|
+
const data = await gqlFetchGraceful(
|
|
1666
|
+
GQL_GET_PAGE_WITH_SEO_BY_URI,
|
|
1667
|
+
{ page: null },
|
|
1668
|
+
{ uri },
|
|
1669
|
+
["wpgraphql", "gql-pages", "gql-yoast", `gql-page-uri-${uri.replace(/\//g, "-")}`]
|
|
1670
|
+
);
|
|
1671
|
+
return data.page;
|
|
1672
|
+
}
|
|
1673
|
+
return { getPostWithSEO, getPageWithSEO, getPageWithSEOByUri };
|
|
1674
|
+
}
|
|
1675
|
+
|
|
1676
|
+
// src/integrations/wpGraphQL/acf/helpers.ts
|
|
1677
|
+
var BASE_POST_FIELDS = `
|
|
1678
|
+
id databaseId slug title content excerpt date modified status uri
|
|
1679
|
+
author { node { databaseId name slug avatar { url } } }
|
|
1680
|
+
featuredImage { node { sourceUrl altText mediaDetails { width height } } }
|
|
1681
|
+
categories { nodes { databaseId name slug } }
|
|
1682
|
+
tags { nodes { databaseId name slug } }
|
|
1683
|
+
`;
|
|
1684
|
+
var BASE_PAGE_FIELDS = `
|
|
1685
|
+
id databaseId slug title content date modified status uri
|
|
1686
|
+
featuredImage { node { sourceUrl altText mediaDetails { width height } } }
|
|
1687
|
+
`;
|
|
1688
|
+
function buildACFFragment(fieldGroupName, fields) {
|
|
1689
|
+
return `${fieldGroupName} { ${fields.join(" ")} }`;
|
|
1690
|
+
}
|
|
1691
|
+
function buildPostWithACFQuery(fieldGroupName, fields) {
|
|
1692
|
+
return `
|
|
1693
|
+
query GetPostWithACF($slug: ID!) {
|
|
1694
|
+
post(id: $slug, idType: SLUG) {
|
|
1695
|
+
${BASE_POST_FIELDS}
|
|
1696
|
+
${buildACFFragment(fieldGroupName, fields)}
|
|
1697
|
+
}
|
|
1698
|
+
}
|
|
1699
|
+
`;
|
|
1700
|
+
}
|
|
1701
|
+
function buildPageWithACFQuery(fieldGroupName, fields) {
|
|
1702
|
+
return `
|
|
1703
|
+
query GetPageWithACF($slug: ID!) {
|
|
1704
|
+
page(id: $slug, idType: SLUG) {
|
|
1705
|
+
${BASE_PAGE_FIELDS}
|
|
1706
|
+
${buildACFFragment(fieldGroupName, fields)}
|
|
1707
|
+
}
|
|
1708
|
+
}
|
|
1709
|
+
`;
|
|
1710
|
+
}
|
|
1711
|
+
function buildPostsWithACFQuery(fieldGroupName, fields) {
|
|
1712
|
+
return `
|
|
1713
|
+
query GetPostsWithACF($first: Int, $after: String) {
|
|
1714
|
+
posts(first: $first, after: $after) {
|
|
1715
|
+
nodes {
|
|
1716
|
+
${BASE_POST_FIELDS}
|
|
1717
|
+
${buildACFFragment(fieldGroupName, fields)}
|
|
1718
|
+
}
|
|
1719
|
+
pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
|
|
1720
|
+
}
|
|
1721
|
+
}
|
|
1722
|
+
`;
|
|
1723
|
+
}
|
|
1724
|
+
|
|
1725
|
+
// src/integrations/wpGraphQL/woocommerce/products/queries.ts
|
|
1726
|
+
var DEFAULT_FIRST6 = 10;
|
|
1727
|
+
var BATCH_FIRST3 = 100;
|
|
1728
|
+
var PRODUCT_FIELDS = `
|
|
1729
|
+
id
|
|
1730
|
+
databaseId
|
|
1731
|
+
slug
|
|
1732
|
+
name
|
|
1733
|
+
status
|
|
1734
|
+
description
|
|
1735
|
+
shortDescription
|
|
1736
|
+
type
|
|
1737
|
+
onSale
|
|
1738
|
+
featuredImage { node { sourceUrl altText } }
|
|
1739
|
+
galleryImages { nodes { sourceUrl altText } }
|
|
1740
|
+
productCategories { nodes { databaseId name slug } }
|
|
1741
|
+
productTags { nodes { databaseId name slug } }
|
|
1742
|
+
... on SimpleProduct {
|
|
1743
|
+
sku
|
|
1744
|
+
price
|
|
1745
|
+
regularPrice
|
|
1746
|
+
salePrice
|
|
1747
|
+
stockStatus
|
|
1748
|
+
stockQuantity
|
|
1749
|
+
manageStock
|
|
1750
|
+
}
|
|
1751
|
+
... on VariableProduct {
|
|
1752
|
+
price
|
|
1753
|
+
regularPrice
|
|
1754
|
+
salePrice
|
|
1755
|
+
stockStatus
|
|
1756
|
+
stockQuantity
|
|
1757
|
+
manageStock
|
|
1758
|
+
variations {
|
|
1759
|
+
nodes {
|
|
1760
|
+
id
|
|
1761
|
+
databaseId
|
|
1762
|
+
slug
|
|
1763
|
+
sku
|
|
1764
|
+
price
|
|
1765
|
+
regularPrice
|
|
1766
|
+
salePrice
|
|
1767
|
+
onSale
|
|
1768
|
+
stockStatus
|
|
1769
|
+
stockQuantity
|
|
1770
|
+
image { sourceUrl altText }
|
|
1771
|
+
attributes { nodes { name value } }
|
|
1772
|
+
}
|
|
1773
|
+
}
|
|
1774
|
+
}
|
|
1775
|
+
`;
|
|
1776
|
+
var GQL_GET_PRODUCTS = `
|
|
1777
|
+
query GetProducts($first: Int, $after: String, $where: RootQueryToProductConnectionWhereArgs) {
|
|
1778
|
+
products(first: $first, after: $after, where: $where) {
|
|
1779
|
+
nodes { ${PRODUCT_FIELDS} }
|
|
1780
|
+
pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
|
|
1781
|
+
}
|
|
1782
|
+
}
|
|
1783
|
+
`;
|
|
1784
|
+
var GQL_GET_PRODUCT_BY_SLUG = `
|
|
1785
|
+
query GetProductBySlug($slug: ID!) {
|
|
1786
|
+
product(id: $slug, idType: SLUG) { ${PRODUCT_FIELDS} }
|
|
1787
|
+
}
|
|
1788
|
+
`;
|
|
1789
|
+
var GQL_GET_PRODUCT_BY_DATABASE_ID = `
|
|
1790
|
+
query GetProductByDatabaseId($id: ID!) {
|
|
1791
|
+
product(id: $id, idType: DATABASE_ID) { ${PRODUCT_FIELDS} }
|
|
1792
|
+
}
|
|
1793
|
+
`;
|
|
1794
|
+
var GQL_GET_ALL_PRODUCT_SLUGS = `
|
|
1795
|
+
query GetAllProductSlugs($first: Int, $after: String) {
|
|
1796
|
+
products(first: $first, after: $after) {
|
|
1797
|
+
nodes { slug }
|
|
1798
|
+
pageInfo { hasNextPage endCursor }
|
|
1799
|
+
}
|
|
1800
|
+
}
|
|
1801
|
+
`;
|
|
1802
|
+
function createProductsQueries2(fetcher) {
|
|
1803
|
+
const { gqlFetch, gqlFetchGraceful } = fetcher;
|
|
1804
|
+
async function getProducts(first = DEFAULT_FIRST6, after, filter) {
|
|
1805
|
+
const where = {};
|
|
1806
|
+
if (filter?.search) where["search"] = filter.search;
|
|
1807
|
+
if (filter?.onSale !== void 0) where["onSale"] = filter.onSale;
|
|
1808
|
+
if (filter?.featured !== void 0) where["featured"] = filter.featured;
|
|
1809
|
+
if (filter?.stockStatus) where["stockStatus"] = filter.stockStatus;
|
|
1810
|
+
if (filter?.minPrice) where["minPrice"] = filter.minPrice;
|
|
1811
|
+
if (filter?.maxPrice) where["maxPrice"] = filter.maxPrice;
|
|
1812
|
+
if (filter?.categoryId) where["categoryIdIn"] = [filter.categoryId];
|
|
1813
|
+
if (filter?.tagId) where["tagIdIn"] = [filter.tagId];
|
|
1814
|
+
const data = await gqlFetchGraceful(
|
|
1815
|
+
GQL_GET_PRODUCTS,
|
|
1816
|
+
{ products: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
|
|
1817
|
+
{ first, after, where: Object.keys(where).length > 0 ? where : void 0 },
|
|
1818
|
+
["wpgraphql", "gql-products"]
|
|
1819
|
+
);
|
|
1820
|
+
return data.products;
|
|
1821
|
+
}
|
|
1822
|
+
async function getProductBySlug(slug) {
|
|
1823
|
+
const data = await gqlFetchGraceful(
|
|
1824
|
+
GQL_GET_PRODUCT_BY_SLUG,
|
|
1825
|
+
{ product: null },
|
|
1826
|
+
{ slug },
|
|
1827
|
+
["wpgraphql", "gql-products", `gql-product-${slug}`]
|
|
1828
|
+
);
|
|
1829
|
+
return data.product;
|
|
1830
|
+
}
|
|
1831
|
+
async function getProductByDatabaseId(id) {
|
|
1832
|
+
const data = await gqlFetchGraceful(
|
|
1833
|
+
GQL_GET_PRODUCT_BY_DATABASE_ID,
|
|
1834
|
+
{ product: null },
|
|
1835
|
+
{ id: String(id) },
|
|
1836
|
+
["wpgraphql", "gql-products", `gql-product-id-${id}`]
|
|
1837
|
+
);
|
|
1838
|
+
return data.product;
|
|
1839
|
+
}
|
|
1840
|
+
async function getFeaturedProducts(first = DEFAULT_FIRST6) {
|
|
1841
|
+
const connection = await getProducts(first, void 0, { featured: true });
|
|
1842
|
+
return connection.nodes;
|
|
1843
|
+
}
|
|
1844
|
+
async function getOnSaleProducts(first = DEFAULT_FIRST6) {
|
|
1845
|
+
const connection = await getProducts(first, void 0, { onSale: true });
|
|
1846
|
+
return connection.nodes;
|
|
1847
|
+
}
|
|
1848
|
+
async function getAllProductSlugs() {
|
|
1849
|
+
try {
|
|
1850
|
+
const all = [];
|
|
1851
|
+
let after = void 0;
|
|
1852
|
+
let hasNextPage = true;
|
|
1853
|
+
while (hasNextPage) {
|
|
1854
|
+
const data = await gqlFetch(GQL_GET_ALL_PRODUCT_SLUGS, { first: BATCH_FIRST3, after }, ["wpgraphql"]);
|
|
1855
|
+
all.push(...data.products.nodes);
|
|
1856
|
+
hasNextPage = data.products.pageInfo.hasNextPage;
|
|
1857
|
+
after = data.products.pageInfo.endCursor;
|
|
1858
|
+
}
|
|
1859
|
+
return all;
|
|
1860
|
+
} catch {
|
|
1861
|
+
console.warn("WPGraphQL unavailable, skipping static generation for products");
|
|
1862
|
+
return [];
|
|
1863
|
+
}
|
|
1864
|
+
}
|
|
1865
|
+
return {
|
|
1866
|
+
getProducts,
|
|
1867
|
+
getProductBySlug,
|
|
1868
|
+
getProductByDatabaseId,
|
|
1869
|
+
getFeaturedProducts,
|
|
1870
|
+
getOnSaleProducts,
|
|
1871
|
+
getAllProductSlugs
|
|
1872
|
+
};
|
|
1873
|
+
}
|
|
1874
|
+
|
|
1875
|
+
// src/integrations/wpGraphQL/woocommerce/orders/queries.ts
|
|
1876
|
+
var DEFAULT_FIRST7 = 10;
|
|
1877
|
+
var ADDRESS_FIELDS = `
|
|
1878
|
+
firstName lastName address1 address2 city postcode country email phone
|
|
1879
|
+
`;
|
|
1880
|
+
var ORDER_FIELDS = `
|
|
1881
|
+
id
|
|
1882
|
+
databaseId
|
|
1883
|
+
orderNumber
|
|
1884
|
+
status
|
|
1885
|
+
date
|
|
1886
|
+
modified
|
|
1887
|
+
total
|
|
1888
|
+
subtotal
|
|
1889
|
+
totalTax
|
|
1890
|
+
shippingTotal
|
|
1891
|
+
currency
|
|
1892
|
+
billing { ${ADDRESS_FIELDS} }
|
|
1893
|
+
shipping { ${ADDRESS_FIELDS} }
|
|
1894
|
+
lineItems {
|
|
1895
|
+
nodes {
|
|
1896
|
+
productId
|
|
1897
|
+
variationId
|
|
1898
|
+
quantity
|
|
1899
|
+
subtotal
|
|
1900
|
+
total
|
|
1901
|
+
product { node { databaseId name slug } }
|
|
1902
|
+
}
|
|
1903
|
+
}
|
|
1904
|
+
`;
|
|
1905
|
+
var GQL_GET_ORDER = `
|
|
1906
|
+
query GetOrder($id: ID!) {
|
|
1907
|
+
order(id: $id, idType: DATABASE_ID) { ${ORDER_FIELDS} }
|
|
1908
|
+
}
|
|
1909
|
+
`;
|
|
1910
|
+
var GQL_GET_MY_ORDERS = `
|
|
1911
|
+
query GetMyOrders($first: Int, $after: String) {
|
|
1912
|
+
orders(first: $first, after: $after) {
|
|
1913
|
+
nodes { ${ORDER_FIELDS} }
|
|
1914
|
+
pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
|
|
1915
|
+
}
|
|
1916
|
+
}
|
|
1917
|
+
`;
|
|
1918
|
+
function createOrdersQueries2(fetcher) {
|
|
1919
|
+
const { gqlFetchGraceful } = fetcher;
|
|
1920
|
+
async function getOrder(id) {
|
|
1921
|
+
const data = await gqlFetchGraceful(
|
|
1922
|
+
GQL_GET_ORDER,
|
|
1923
|
+
{ order: null },
|
|
1924
|
+
{ id: String(id) },
|
|
1925
|
+
["wpgraphql", "gql-orders", `gql-order-${id}`]
|
|
1926
|
+
);
|
|
1927
|
+
return data.order;
|
|
1928
|
+
}
|
|
1929
|
+
async function getMyOrders(first = DEFAULT_FIRST7, after) {
|
|
1930
|
+
const data = await gqlFetchGraceful(
|
|
1931
|
+
GQL_GET_MY_ORDERS,
|
|
1932
|
+
{ orders: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
|
|
1933
|
+
{ first, after },
|
|
1934
|
+
["wpgraphql", "gql-orders"]
|
|
1935
|
+
);
|
|
1936
|
+
return data.orders;
|
|
1937
|
+
}
|
|
1938
|
+
return { getOrder, getMyOrders };
|
|
1939
|
+
}
|
|
1940
|
+
|
|
1941
|
+
// src/integrations/wpGraphQL/woocommerce/customers/queries.ts
|
|
1942
|
+
var ADDRESS_FIELDS2 = `
|
|
1943
|
+
firstName lastName address1 address2 city postcode country
|
|
1944
|
+
`;
|
|
1945
|
+
var CUSTOMER_FIELDS = `
|
|
1946
|
+
id
|
|
1947
|
+
databaseId
|
|
1948
|
+
email
|
|
1949
|
+
firstName
|
|
1950
|
+
lastName
|
|
1951
|
+
username
|
|
1952
|
+
billing { ${ADDRESS_FIELDS2} phone }
|
|
1953
|
+
shipping { ${ADDRESS_FIELDS2} }
|
|
1954
|
+
`;
|
|
1955
|
+
var GQL_GET_CUSTOMER = `
|
|
1956
|
+
query GetCustomer {
|
|
1957
|
+
customer { ${CUSTOMER_FIELDS} }
|
|
1958
|
+
}
|
|
1959
|
+
`;
|
|
1960
|
+
var GQL_GET_CUSTOMER_BY_ID = `
|
|
1961
|
+
query GetCustomerById($id: ID!) {
|
|
1962
|
+
customer(customerId: $id) { ${CUSTOMER_FIELDS} }
|
|
1963
|
+
}
|
|
1964
|
+
`;
|
|
1965
|
+
function createCustomersQueries2(fetcher) {
|
|
1966
|
+
const { gqlFetchGraceful } = fetcher;
|
|
1967
|
+
async function getCustomer() {
|
|
1968
|
+
const data = await gqlFetchGraceful(
|
|
1969
|
+
GQL_GET_CUSTOMER,
|
|
1970
|
+
{ customer: null },
|
|
1971
|
+
void 0,
|
|
1972
|
+
["wpgraphql", "gql-customer"]
|
|
1973
|
+
);
|
|
1974
|
+
return data.customer;
|
|
1975
|
+
}
|
|
1976
|
+
async function getCustomerById(id) {
|
|
1977
|
+
const data = await gqlFetchGraceful(
|
|
1978
|
+
GQL_GET_CUSTOMER_BY_ID,
|
|
1979
|
+
{ customer: null },
|
|
1980
|
+
{ id: String(id) },
|
|
1981
|
+
["wpgraphql", "gql-customer", `gql-customer-${id}`]
|
|
1982
|
+
);
|
|
1983
|
+
return data.customer;
|
|
1984
|
+
}
|
|
1985
|
+
return { getCustomer, getCustomerById };
|
|
1986
|
+
}
|
|
1987
|
+
|
|
1988
|
+
// src/integrations/wpGraphQL/woocommerce/index.ts
|
|
1989
|
+
function createWPGraphQLWooCommerceClient(config) {
|
|
1990
|
+
const fetcher = createWPGraphQLFetcher(config);
|
|
1991
|
+
return {
|
|
1992
|
+
...createProductsQueries2(fetcher),
|
|
1993
|
+
...createOrdersQueries2(fetcher),
|
|
1994
|
+
...createCustomersQueries2(fetcher)
|
|
1995
|
+
};
|
|
1996
|
+
}
|
|
1997
|
+
|
|
1998
|
+
// src/integrations/wpGraphQL/cpt/queries.ts
|
|
1999
|
+
var DEFAULT_FIRST8 = 10;
|
|
2000
|
+
var BATCH_FIRST4 = 100;
|
|
2001
|
+
var BASE_CPT_FIELDS = `
|
|
2002
|
+
id databaseId slug title date modified status uri
|
|
2003
|
+
`;
|
|
2004
|
+
function createCPTQueries(fetcher, typeName, singularTypeName, extraFields) {
|
|
2005
|
+
const { gqlFetch, gqlFetchGraceful } = fetcher;
|
|
2006
|
+
const fields = extraFields ? `${BASE_CPT_FIELDS} ${extraFields}` : BASE_CPT_FIELDS;
|
|
2007
|
+
const GQL_GET_ITEMS = `
|
|
2008
|
+
query GetCPT_${typeName}($first: Int, $after: String) {
|
|
2009
|
+
${typeName}(first: $first, after: $after) {
|
|
2010
|
+
nodes { ${fields} }
|
|
2011
|
+
pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
|
|
2012
|
+
}
|
|
2013
|
+
}
|
|
2014
|
+
`;
|
|
2015
|
+
const GQL_GET_ITEM_BY_SLUG = `
|
|
2016
|
+
query GetCPT_${singularTypeName}BySlug($slug: ID!) {
|
|
2017
|
+
${singularTypeName}(id: $slug, idType: SLUG) { ${fields} }
|
|
2018
|
+
}
|
|
2019
|
+
`;
|
|
2020
|
+
const GQL_GET_ALL_SLUGS = `
|
|
2021
|
+
query GetAllCPT_${typeName}Slugs($first: Int, $after: String) {
|
|
2022
|
+
${typeName}(first: $first, after: $after) {
|
|
2023
|
+
nodes { slug }
|
|
2024
|
+
pageInfo { hasNextPage endCursor }
|
|
2025
|
+
}
|
|
2026
|
+
}
|
|
2027
|
+
`;
|
|
2028
|
+
async function getItems(first = DEFAULT_FIRST8, after) {
|
|
2029
|
+
const data = await gqlFetchGraceful(
|
|
2030
|
+
GQL_GET_ITEMS,
|
|
2031
|
+
{ [typeName]: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
|
|
2032
|
+
{ first, after },
|
|
2033
|
+
["wpgraphql", `gql-${typeName}`]
|
|
2034
|
+
);
|
|
2035
|
+
return data[typeName] ?? { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } };
|
|
2036
|
+
}
|
|
2037
|
+
async function getItemBySlug(slug) {
|
|
2038
|
+
const data = await gqlFetchGraceful(
|
|
2039
|
+
GQL_GET_ITEM_BY_SLUG,
|
|
2040
|
+
{ [singularTypeName]: null },
|
|
2041
|
+
{ slug },
|
|
2042
|
+
["wpgraphql", `gql-${typeName}`, `gql-${singularTypeName}-${slug}`]
|
|
2043
|
+
);
|
|
2044
|
+
return data[singularTypeName] ?? null;
|
|
2045
|
+
}
|
|
2046
|
+
async function getAllSlugs() {
|
|
2047
|
+
try {
|
|
2048
|
+
const all = [];
|
|
2049
|
+
let after = void 0;
|
|
2050
|
+
let hasNextPage = true;
|
|
2051
|
+
while (hasNextPage) {
|
|
2052
|
+
const data = await gqlFetch(GQL_GET_ALL_SLUGS, { first: BATCH_FIRST4, after }, ["wpgraphql"]);
|
|
2053
|
+
const connection = data[typeName];
|
|
2054
|
+
if (!connection) break;
|
|
2055
|
+
all.push(...connection.nodes);
|
|
2056
|
+
hasNextPage = connection.pageInfo.hasNextPage;
|
|
2057
|
+
after = connection.pageInfo.endCursor;
|
|
2058
|
+
}
|
|
2059
|
+
return all;
|
|
2060
|
+
} catch {
|
|
2061
|
+
console.warn(`WPGraphQL unavailable, skipping static generation for ${typeName}`);
|
|
2062
|
+
return [];
|
|
2063
|
+
}
|
|
2064
|
+
}
|
|
2065
|
+
return { getItems, getItemBySlug, getAllSlugs };
|
|
2066
|
+
}
|
|
2067
|
+
|
|
2068
|
+
export { WPGraphQLError, buildACFFragment, buildPageWithACFQuery, buildPostWithACFQuery, buildPostsWithACFQuery, createCPTQueries, createWPGraphQLCoreClient as createWPGraphQLClient, createWPGraphQLCoreClient, createWPGraphQLFetcher, createWPGraphQLWooCommerceClient, createWooCommerceClient, createWooCommerceFetcher, createWordPressClient, createYoastQueries, extractOmnibusData, resolveBaseUrl, withOmnibus, withOmnibusVariation };
|
|
787
2069
|
//# sourceMappingURL=index.js.map
|
|
788
2070
|
//# sourceMappingURL=index.js.map
|