@szymonpiatek/nextwordpress 0.0.1 → 0.0.2
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 +1026 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +416 -27
- package/dist/index.d.ts +416 -27
- package/dist/index.js +1016 -29
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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,7 @@ function createPagesQueries(fetcher) {
|
|
|
327
329
|
return { getAllPages, getPageById, getPageBySlug };
|
|
328
330
|
}
|
|
329
331
|
|
|
330
|
-
// src/integrations/
|
|
332
|
+
// src/integrations/restApi/core/index.ts
|
|
331
333
|
function createWordPressClient(config) {
|
|
332
334
|
const fetcher = createFetcher(config);
|
|
333
335
|
return {
|
|
@@ -340,7 +342,7 @@ function createWordPressClient(config) {
|
|
|
340
342
|
};
|
|
341
343
|
}
|
|
342
344
|
|
|
343
|
-
// src/integrations/woocommerce/omnibus/queries.ts
|
|
345
|
+
// src/integrations/restApi/woocommerce/omnibus/queries.ts
|
|
344
346
|
var META_KEY_LOWEST_PRICE = "wpo_lowest_price";
|
|
345
347
|
var META_KEY_PRICE_HISTORY = "_alg_wc_price_history";
|
|
346
348
|
function extractMetaValue(meta_data, key) {
|
|
@@ -369,7 +371,7 @@ function withOmnibusVariation(variation) {
|
|
|
369
371
|
};
|
|
370
372
|
}
|
|
371
373
|
|
|
372
|
-
// src/integrations/woocommerce/client/fetcher.ts
|
|
374
|
+
// src/integrations/restApi/woocommerce/client/fetcher.ts
|
|
373
375
|
var USER_AGENT2 = "NextWordpress WooCommerce Client";
|
|
374
376
|
var DEFAULT_CACHE_TTL = 3600;
|
|
375
377
|
function toQueryString(params) {
|
|
@@ -451,7 +453,7 @@ function createWooCommerceFetcher(config) {
|
|
|
451
453
|
return { wcFetch, wcFetchGraceful, wcFetchPaginated, wcFetchPaginatedGraceful, wcMutate };
|
|
452
454
|
}
|
|
453
455
|
|
|
454
|
-
// src/integrations/woocommerce/products/queries.ts
|
|
456
|
+
// src/integrations/restApi/woocommerce/products/queries.ts
|
|
455
457
|
function buildProductQuery(base, filterParams) {
|
|
456
458
|
const query = { ...base };
|
|
457
459
|
if (!filterParams) return query;
|
|
@@ -578,7 +580,7 @@ function createProductsQueries(fetcher) {
|
|
|
578
580
|
};
|
|
579
581
|
}
|
|
580
582
|
|
|
581
|
-
// src/integrations/woocommerce/categories/queries.ts
|
|
583
|
+
// src/integrations/restApi/woocommerce/categories/queries.ts
|
|
582
584
|
function createCategoriesQueries2(fetcher) {
|
|
583
585
|
const { wcFetch, wcFetchGraceful } = fetcher;
|
|
584
586
|
async function getAllProductCategories() {
|
|
@@ -627,7 +629,7 @@ function createCategoriesQueries2(fetcher) {
|
|
|
627
629
|
};
|
|
628
630
|
}
|
|
629
631
|
|
|
630
|
-
// src/integrations/woocommerce/tags/queries.ts
|
|
632
|
+
// src/integrations/restApi/woocommerce/tags/queries.ts
|
|
631
633
|
function createTagsQueries2(fetcher) {
|
|
632
634
|
const { wcFetch, wcFetchGraceful } = fetcher;
|
|
633
635
|
async function getAllProductTags() {
|
|
@@ -660,7 +662,7 @@ function createTagsQueries2(fetcher) {
|
|
|
660
662
|
};
|
|
661
663
|
}
|
|
662
664
|
|
|
663
|
-
// src/integrations/woocommerce/orders/queries.ts
|
|
665
|
+
// src/integrations/restApi/woocommerce/orders/queries.ts
|
|
664
666
|
function createOrdersQueries(fetcher) {
|
|
665
667
|
const { wcFetch, wcFetchGraceful, wcMutate } = fetcher;
|
|
666
668
|
async function createOrder(input) {
|
|
@@ -692,7 +694,7 @@ function createOrdersQueries(fetcher) {
|
|
|
692
694
|
};
|
|
693
695
|
}
|
|
694
696
|
|
|
695
|
-
// src/integrations/woocommerce/coupons/queries.ts
|
|
697
|
+
// src/integrations/restApi/woocommerce/coupons/queries.ts
|
|
696
698
|
function createCouponsQueries(fetcher) {
|
|
697
699
|
const { wcFetchGraceful } = fetcher;
|
|
698
700
|
async function getCouponByCode(code) {
|
|
@@ -722,7 +724,7 @@ function createCouponsQueries(fetcher) {
|
|
|
722
724
|
};
|
|
723
725
|
}
|
|
724
726
|
|
|
725
|
-
// src/integrations/woocommerce/customers/queries.ts
|
|
727
|
+
// src/integrations/restApi/woocommerce/customers/queries.ts
|
|
726
728
|
function createCustomersQueries(fetcher) {
|
|
727
729
|
const { wcFetch, wcFetchGraceful } = fetcher;
|
|
728
730
|
async function getCustomerById(id) {
|
|
@@ -770,7 +772,7 @@ function createCustomersQueries(fetcher) {
|
|
|
770
772
|
};
|
|
771
773
|
}
|
|
772
774
|
|
|
773
|
-
// src/integrations/woocommerce/index.ts
|
|
775
|
+
// src/integrations/restApi/woocommerce/index.ts
|
|
774
776
|
function createWooCommerceClient(config) {
|
|
775
777
|
const fetcher = createWooCommerceFetcher(config);
|
|
776
778
|
return {
|
|
@@ -783,6 +785,991 @@ function createWooCommerceClient(config) {
|
|
|
783
785
|
};
|
|
784
786
|
}
|
|
785
787
|
|
|
786
|
-
|
|
788
|
+
// src/integrations/wpGraphQL/client/types.ts
|
|
789
|
+
var WPGraphQLError = class extends Error {
|
|
790
|
+
constructor(message, status, endpoint, gqlErrors) {
|
|
791
|
+
super(message);
|
|
792
|
+
__publicField(this, "status", status);
|
|
793
|
+
__publicField(this, "endpoint", endpoint);
|
|
794
|
+
__publicField(this, "gqlErrors", gqlErrors);
|
|
795
|
+
this.name = "WPGraphQLError";
|
|
796
|
+
}
|
|
797
|
+
};
|
|
798
|
+
|
|
799
|
+
// src/integrations/wpGraphQL/client/fetcher.ts
|
|
800
|
+
var USER_AGENT3 = "NextWordpress WPGraphQL Client";
|
|
801
|
+
var CACHE_TTL = 300;
|
|
802
|
+
function createWPGraphQLFetcher(config) {
|
|
803
|
+
const url = `${resolveBaseUrl(config)}/graphql`;
|
|
804
|
+
async function gqlFetch(document, variables, tags = ["wpgraphql"]) {
|
|
805
|
+
const response = await fetch(url, {
|
|
806
|
+
method: "POST",
|
|
807
|
+
headers: {
|
|
808
|
+
"Content-Type": "application/json",
|
|
809
|
+
"User-Agent": USER_AGENT3
|
|
810
|
+
},
|
|
811
|
+
body: JSON.stringify({ query: document, variables }),
|
|
812
|
+
next: { tags, revalidate: CACHE_TTL }
|
|
813
|
+
});
|
|
814
|
+
if (!response.ok) {
|
|
815
|
+
throw new WPGraphQLError(
|
|
816
|
+
`WPGraphQL request failed: ${response.statusText}`,
|
|
817
|
+
response.status,
|
|
818
|
+
url
|
|
819
|
+
);
|
|
820
|
+
}
|
|
821
|
+
const parsed = await response.json();
|
|
822
|
+
if (parsed.errors && parsed.errors.length > 0) {
|
|
823
|
+
throw new WPGraphQLError(
|
|
824
|
+
parsed.errors[0].message,
|
|
825
|
+
200,
|
|
826
|
+
url,
|
|
827
|
+
parsed.errors
|
|
828
|
+
);
|
|
829
|
+
}
|
|
830
|
+
if (parsed.data === void 0) {
|
|
831
|
+
throw new WPGraphQLError("No data returned from WPGraphQL", 200, url);
|
|
832
|
+
}
|
|
833
|
+
return parsed.data;
|
|
834
|
+
}
|
|
835
|
+
async function gqlFetchGraceful(document, fallback, variables, tags = ["wpgraphql"]) {
|
|
836
|
+
try {
|
|
837
|
+
return await gqlFetch(document, variables, tags);
|
|
838
|
+
} catch {
|
|
839
|
+
console.warn(`WPGraphQL fetch failed for query`);
|
|
840
|
+
return fallback;
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
return { gqlFetch, gqlFetchGraceful };
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
// src/integrations/wpGraphQL/core/posts/queries.ts
|
|
847
|
+
var DEFAULT_FIRST = 10;
|
|
848
|
+
var BATCH_FIRST = 100;
|
|
849
|
+
var POST_FIELDS = `
|
|
850
|
+
id
|
|
851
|
+
databaseId
|
|
852
|
+
slug
|
|
853
|
+
title
|
|
854
|
+
excerpt
|
|
855
|
+
date
|
|
856
|
+
modified
|
|
857
|
+
status
|
|
858
|
+
uri
|
|
859
|
+
author {
|
|
860
|
+
node {
|
|
861
|
+
databaseId
|
|
862
|
+
name
|
|
863
|
+
slug
|
|
864
|
+
avatar { url }
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
featuredImage {
|
|
868
|
+
node {
|
|
869
|
+
sourceUrl
|
|
870
|
+
altText
|
|
871
|
+
mediaDetails { width height }
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
categories {
|
|
875
|
+
nodes { databaseId name slug }
|
|
876
|
+
}
|
|
877
|
+
tags {
|
|
878
|
+
nodes { databaseId name slug }
|
|
879
|
+
}
|
|
880
|
+
`;
|
|
881
|
+
var POST_FIELDS_WITH_CONTENT = `
|
|
882
|
+
${POST_FIELDS}
|
|
883
|
+
content
|
|
884
|
+
`;
|
|
885
|
+
var GQL_GET_POSTS = `
|
|
886
|
+
query GetPosts($first: Int, $after: String, $where: RootQueryToPostConnectionWhereArgs) {
|
|
887
|
+
posts(first: $first, after: $after, where: $where) {
|
|
888
|
+
nodes { ${POST_FIELDS} }
|
|
889
|
+
pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
`;
|
|
893
|
+
var GQL_GET_POST_BY_SLUG = `
|
|
894
|
+
query GetPostBySlug($slug: ID!) {
|
|
895
|
+
post(id: $slug, idType: SLUG) { ${POST_FIELDS_WITH_CONTENT} }
|
|
896
|
+
}
|
|
897
|
+
`;
|
|
898
|
+
var GQL_GET_POST_BY_DATABASE_ID = `
|
|
899
|
+
query GetPostByDatabaseId($id: ID!) {
|
|
900
|
+
post(id: $id, idType: DATABASE_ID) { ${POST_FIELDS_WITH_CONTENT} }
|
|
901
|
+
}
|
|
902
|
+
`;
|
|
903
|
+
var GQL_GET_ALL_POST_SLUGS = `
|
|
904
|
+
query GetAllPostSlugs($first: Int, $after: String) {
|
|
905
|
+
posts(first: $first, after: $after) {
|
|
906
|
+
nodes { slug }
|
|
907
|
+
pageInfo { hasNextPage endCursor }
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
`;
|
|
911
|
+
var GQL_GET_ALL_POSTS_FOR_SITEMAP = `
|
|
912
|
+
query GetAllPostsForSitemap($first: Int, $after: String) {
|
|
913
|
+
posts(first: $first, after: $after) {
|
|
914
|
+
nodes { slug modified }
|
|
915
|
+
pageInfo { hasNextPage endCursor }
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
`;
|
|
919
|
+
function createPostsQueries2(fetcher) {
|
|
920
|
+
const { gqlFetch, gqlFetchGraceful } = fetcher;
|
|
921
|
+
async function getPosts(first = DEFAULT_FIRST, after, filter) {
|
|
922
|
+
const where = {};
|
|
923
|
+
if (filter?.authorName) where["authorName"] = filter.authorName;
|
|
924
|
+
if (filter?.categoryName) where["categoryName"] = filter.categoryName;
|
|
925
|
+
if (filter?.tag) where["tag"] = filter.tag;
|
|
926
|
+
if (filter?.search) where["search"] = filter.search;
|
|
927
|
+
if (filter?.status) where["status"] = filter.status;
|
|
928
|
+
const data = await gqlFetchGraceful(
|
|
929
|
+
GQL_GET_POSTS,
|
|
930
|
+
{ posts: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
|
|
931
|
+
{ first, after, where: Object.keys(where).length > 0 ? where : void 0 },
|
|
932
|
+
["wpgraphql", "gql-posts"]
|
|
933
|
+
);
|
|
934
|
+
return data.posts;
|
|
935
|
+
}
|
|
936
|
+
async function getPostBySlug(slug) {
|
|
937
|
+
const data = await gqlFetchGraceful(
|
|
938
|
+
GQL_GET_POST_BY_SLUG,
|
|
939
|
+
{ post: null },
|
|
940
|
+
{ slug },
|
|
941
|
+
["wpgraphql", "gql-posts", `gql-post-${slug}`]
|
|
942
|
+
);
|
|
943
|
+
return data.post;
|
|
944
|
+
}
|
|
945
|
+
async function getPostByDatabaseId(id) {
|
|
946
|
+
const data = await gqlFetchGraceful(
|
|
947
|
+
GQL_GET_POST_BY_DATABASE_ID,
|
|
948
|
+
{ post: null },
|
|
949
|
+
{ id: String(id) },
|
|
950
|
+
["wpgraphql", "gql-posts", `gql-post-id-${id}`]
|
|
951
|
+
);
|
|
952
|
+
return data.post;
|
|
953
|
+
}
|
|
954
|
+
async function getRecentPosts(first = DEFAULT_FIRST) {
|
|
955
|
+
const connection = await getPosts(first);
|
|
956
|
+
return connection.nodes;
|
|
957
|
+
}
|
|
958
|
+
async function getAllPostSlugs() {
|
|
959
|
+
try {
|
|
960
|
+
const all = [];
|
|
961
|
+
let after = void 0;
|
|
962
|
+
let hasNextPage = true;
|
|
963
|
+
while (hasNextPage) {
|
|
964
|
+
const data = await gqlFetch(GQL_GET_ALL_POST_SLUGS, { first: BATCH_FIRST, after }, ["wpgraphql"]);
|
|
965
|
+
all.push(...data.posts.nodes);
|
|
966
|
+
hasNextPage = data.posts.pageInfo.hasNextPage;
|
|
967
|
+
after = data.posts.pageInfo.endCursor;
|
|
968
|
+
}
|
|
969
|
+
return all;
|
|
970
|
+
} catch {
|
|
971
|
+
console.warn("WPGraphQL unavailable, skipping static generation for posts");
|
|
972
|
+
return [];
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
async function getAllPostsForSitemap() {
|
|
976
|
+
try {
|
|
977
|
+
const all = [];
|
|
978
|
+
let after = void 0;
|
|
979
|
+
let hasNextPage = true;
|
|
980
|
+
while (hasNextPage) {
|
|
981
|
+
const data = await gqlFetch(
|
|
982
|
+
GQL_GET_ALL_POSTS_FOR_SITEMAP,
|
|
983
|
+
{ first: BATCH_FIRST, after },
|
|
984
|
+
["wpgraphql"]
|
|
985
|
+
);
|
|
986
|
+
all.push(...data.posts.nodes);
|
|
987
|
+
hasNextPage = data.posts.pageInfo.hasNextPage;
|
|
988
|
+
after = data.posts.pageInfo.endCursor;
|
|
989
|
+
}
|
|
990
|
+
return all;
|
|
991
|
+
} catch {
|
|
992
|
+
console.warn("WPGraphQL unavailable, skipping sitemap generation");
|
|
993
|
+
return [];
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
return {
|
|
997
|
+
getPosts,
|
|
998
|
+
getPostBySlug,
|
|
999
|
+
getPostByDatabaseId,
|
|
1000
|
+
getRecentPosts,
|
|
1001
|
+
getAllPostSlugs,
|
|
1002
|
+
getAllPostsForSitemap
|
|
1003
|
+
};
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
// src/integrations/wpGraphQL/core/pages/queries.ts
|
|
1007
|
+
var DEFAULT_FIRST2 = 10;
|
|
1008
|
+
var BATCH_FIRST2 = 100;
|
|
1009
|
+
var PAGE_FIELDS = `
|
|
1010
|
+
id
|
|
1011
|
+
databaseId
|
|
1012
|
+
slug
|
|
1013
|
+
title
|
|
1014
|
+
content
|
|
1015
|
+
date
|
|
1016
|
+
modified
|
|
1017
|
+
status
|
|
1018
|
+
uri
|
|
1019
|
+
featuredImage {
|
|
1020
|
+
node {
|
|
1021
|
+
sourceUrl
|
|
1022
|
+
altText
|
|
1023
|
+
mediaDetails { width height }
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
`;
|
|
1027
|
+
var GQL_GET_PAGES = `
|
|
1028
|
+
query GetPages($first: Int, $after: String) {
|
|
1029
|
+
pages(first: $first, after: $after) {
|
|
1030
|
+
nodes { ${PAGE_FIELDS} }
|
|
1031
|
+
pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
`;
|
|
1035
|
+
var GQL_GET_PAGE_BY_SLUG = `
|
|
1036
|
+
query GetPageBySlug($uri: ID!) {
|
|
1037
|
+
page(id: $uri, idType: URI) { ${PAGE_FIELDS} }
|
|
1038
|
+
}
|
|
1039
|
+
`;
|
|
1040
|
+
var GQL_GET_PAGE_BY_URI = `
|
|
1041
|
+
query GetPageByUri($uri: ID!) {
|
|
1042
|
+
page(id: $uri, idType: URI) { ${PAGE_FIELDS} }
|
|
1043
|
+
}
|
|
1044
|
+
`;
|
|
1045
|
+
var GQL_GET_ALL_PAGE_URIS = `
|
|
1046
|
+
query GetAllPageUris($first: Int, $after: String) {
|
|
1047
|
+
pages(first: $first, after: $after) {
|
|
1048
|
+
nodes { uri }
|
|
1049
|
+
pageInfo { hasNextPage endCursor }
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
`;
|
|
1053
|
+
function createPagesQueries2(fetcher) {
|
|
1054
|
+
const { gqlFetch, gqlFetchGraceful } = fetcher;
|
|
1055
|
+
async function getPages(first = DEFAULT_FIRST2, after) {
|
|
1056
|
+
const data = await gqlFetchGraceful(
|
|
1057
|
+
GQL_GET_PAGES,
|
|
1058
|
+
{ pages: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
|
|
1059
|
+
{ first, after },
|
|
1060
|
+
["wpgraphql", "gql-pages"]
|
|
1061
|
+
);
|
|
1062
|
+
return data.pages;
|
|
1063
|
+
}
|
|
1064
|
+
async function getPageBySlug(slug) {
|
|
1065
|
+
const data = await gqlFetchGraceful(
|
|
1066
|
+
GQL_GET_PAGE_BY_SLUG,
|
|
1067
|
+
{ page: null },
|
|
1068
|
+
{ uri: `/${slug}/` },
|
|
1069
|
+
["wpgraphql", "gql-pages", `gql-page-${slug}`]
|
|
1070
|
+
);
|
|
1071
|
+
return data.page;
|
|
1072
|
+
}
|
|
1073
|
+
async function getPageByUri(uri) {
|
|
1074
|
+
const data = await gqlFetchGraceful(
|
|
1075
|
+
GQL_GET_PAGE_BY_URI,
|
|
1076
|
+
{ page: null },
|
|
1077
|
+
{ uri },
|
|
1078
|
+
["wpgraphql", "gql-pages", `gql-page-uri-${uri.replace(/\//g, "-")}`]
|
|
1079
|
+
);
|
|
1080
|
+
return data.page;
|
|
1081
|
+
}
|
|
1082
|
+
async function getAllPageUris() {
|
|
1083
|
+
try {
|
|
1084
|
+
const all = [];
|
|
1085
|
+
let after = void 0;
|
|
1086
|
+
let hasNextPage = true;
|
|
1087
|
+
while (hasNextPage) {
|
|
1088
|
+
const data = await gqlFetch(GQL_GET_ALL_PAGE_URIS, { first: BATCH_FIRST2, after }, ["wpgraphql"]);
|
|
1089
|
+
all.push(...data.pages.nodes);
|
|
1090
|
+
hasNextPage = data.pages.pageInfo.hasNextPage;
|
|
1091
|
+
after = data.pages.pageInfo.endCursor;
|
|
1092
|
+
}
|
|
1093
|
+
return all;
|
|
1094
|
+
} catch {
|
|
1095
|
+
console.warn("WPGraphQL unavailable, skipping static generation for pages");
|
|
1096
|
+
return [];
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
return { getPages, getPageBySlug, getPageByUri, getAllPageUris };
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
// src/integrations/wpGraphQL/core/categories/queries.ts
|
|
1103
|
+
var DEFAULT_FIRST3 = 100;
|
|
1104
|
+
var CATEGORY_FIELDS = `
|
|
1105
|
+
id
|
|
1106
|
+
databaseId
|
|
1107
|
+
name
|
|
1108
|
+
slug
|
|
1109
|
+
description
|
|
1110
|
+
count
|
|
1111
|
+
uri
|
|
1112
|
+
parent {
|
|
1113
|
+
node { databaseId name slug }
|
|
1114
|
+
}
|
|
1115
|
+
`;
|
|
1116
|
+
var GQL_GET_CATEGORIES = `
|
|
1117
|
+
query GetCategories($first: Int, $after: String) {
|
|
1118
|
+
categories(first: $first, after: $after) {
|
|
1119
|
+
nodes { ${CATEGORY_FIELDS} }
|
|
1120
|
+
pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
`;
|
|
1124
|
+
var GQL_GET_CATEGORY_BY_SLUG = `
|
|
1125
|
+
query GetCategoryBySlug($slug: ID!) {
|
|
1126
|
+
category(id: $slug, idType: SLUG) { ${CATEGORY_FIELDS} }
|
|
1127
|
+
}
|
|
1128
|
+
`;
|
|
1129
|
+
var GQL_GET_CATEGORY_BY_DATABASE_ID = `
|
|
1130
|
+
query GetCategoryByDatabaseId($id: ID!) {
|
|
1131
|
+
category(id: $id, idType: DATABASE_ID) { ${CATEGORY_FIELDS} }
|
|
1132
|
+
}
|
|
1133
|
+
`;
|
|
1134
|
+
function createCategoriesQueries3(fetcher) {
|
|
1135
|
+
const { gqlFetchGraceful } = fetcher;
|
|
1136
|
+
async function getCategories(first = DEFAULT_FIRST3, after) {
|
|
1137
|
+
const data = await gqlFetchGraceful(
|
|
1138
|
+
GQL_GET_CATEGORIES,
|
|
1139
|
+
{ categories: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
|
|
1140
|
+
{ first, after },
|
|
1141
|
+
["wpgraphql", "gql-categories"]
|
|
1142
|
+
);
|
|
1143
|
+
return data.categories;
|
|
1144
|
+
}
|
|
1145
|
+
async function getCategoryBySlug(slug) {
|
|
1146
|
+
const data = await gqlFetchGraceful(
|
|
1147
|
+
GQL_GET_CATEGORY_BY_SLUG,
|
|
1148
|
+
{ category: null },
|
|
1149
|
+
{ slug },
|
|
1150
|
+
["wpgraphql", "gql-categories", `gql-category-${slug}`]
|
|
1151
|
+
);
|
|
1152
|
+
return data.category;
|
|
1153
|
+
}
|
|
1154
|
+
async function getCategoryByDatabaseId(id) {
|
|
1155
|
+
const data = await gqlFetchGraceful(
|
|
1156
|
+
GQL_GET_CATEGORY_BY_DATABASE_ID,
|
|
1157
|
+
{ category: null },
|
|
1158
|
+
{ id: String(id) },
|
|
1159
|
+
["wpgraphql", "gql-categories", `gql-category-id-${id}`]
|
|
1160
|
+
);
|
|
1161
|
+
return data.category;
|
|
1162
|
+
}
|
|
1163
|
+
return { getCategories, getCategoryBySlug, getCategoryByDatabaseId };
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
// src/integrations/wpGraphQL/core/tags/queries.ts
|
|
1167
|
+
var DEFAULT_FIRST4 = 100;
|
|
1168
|
+
var TAG_FIELDS = `
|
|
1169
|
+
id
|
|
1170
|
+
databaseId
|
|
1171
|
+
name
|
|
1172
|
+
slug
|
|
1173
|
+
description
|
|
1174
|
+
count
|
|
1175
|
+
uri
|
|
1176
|
+
`;
|
|
1177
|
+
var GQL_GET_TAGS = `
|
|
1178
|
+
query GetTags($first: Int, $after: String) {
|
|
1179
|
+
tags(first: $first, after: $after) {
|
|
1180
|
+
nodes { ${TAG_FIELDS} }
|
|
1181
|
+
pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
`;
|
|
1185
|
+
var GQL_GET_TAG_BY_SLUG = `
|
|
1186
|
+
query GetTagBySlug($slug: ID!) {
|
|
1187
|
+
tag(id: $slug, idType: SLUG) { ${TAG_FIELDS} }
|
|
1188
|
+
}
|
|
1189
|
+
`;
|
|
1190
|
+
function createTagsQueries3(fetcher) {
|
|
1191
|
+
const { gqlFetchGraceful } = fetcher;
|
|
1192
|
+
async function getTags(first = DEFAULT_FIRST4, after) {
|
|
1193
|
+
const data = await gqlFetchGraceful(
|
|
1194
|
+
GQL_GET_TAGS,
|
|
1195
|
+
{ tags: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
|
|
1196
|
+
{ first, after },
|
|
1197
|
+
["wpgraphql", "gql-tags"]
|
|
1198
|
+
);
|
|
1199
|
+
return data.tags;
|
|
1200
|
+
}
|
|
1201
|
+
async function getTagBySlug(slug) {
|
|
1202
|
+
const data = await gqlFetchGraceful(
|
|
1203
|
+
GQL_GET_TAG_BY_SLUG,
|
|
1204
|
+
{ tag: null },
|
|
1205
|
+
{ slug },
|
|
1206
|
+
["wpgraphql", "gql-tags", `gql-tag-${slug}`]
|
|
1207
|
+
);
|
|
1208
|
+
return data.tag;
|
|
1209
|
+
}
|
|
1210
|
+
return { getTags, getTagBySlug };
|
|
1211
|
+
}
|
|
1212
|
+
|
|
1213
|
+
// src/integrations/wpGraphQL/core/authors/queries.ts
|
|
1214
|
+
var DEFAULT_FIRST5 = 100;
|
|
1215
|
+
var AUTHOR_FIELDS = `
|
|
1216
|
+
id
|
|
1217
|
+
databaseId
|
|
1218
|
+
name
|
|
1219
|
+
slug
|
|
1220
|
+
description
|
|
1221
|
+
email
|
|
1222
|
+
uri
|
|
1223
|
+
avatar { url width height }
|
|
1224
|
+
`;
|
|
1225
|
+
var GQL_GET_AUTHORS = `
|
|
1226
|
+
query GetAuthors($first: Int, $after: String) {
|
|
1227
|
+
users(first: $first, after: $after) {
|
|
1228
|
+
nodes { ${AUTHOR_FIELDS} }
|
|
1229
|
+
pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
`;
|
|
1233
|
+
var GQL_GET_AUTHOR_BY_SLUG = `
|
|
1234
|
+
query GetAuthorBySlug($slug: String!) {
|
|
1235
|
+
users(where: { login: $slug }) {
|
|
1236
|
+
nodes { ${AUTHOR_FIELDS} }
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
`;
|
|
1240
|
+
function createAuthorsQueries2(fetcher) {
|
|
1241
|
+
const { gqlFetchGraceful } = fetcher;
|
|
1242
|
+
async function getAuthors(first = DEFAULT_FIRST5, after) {
|
|
1243
|
+
const data = await gqlFetchGraceful(
|
|
1244
|
+
GQL_GET_AUTHORS,
|
|
1245
|
+
{ users: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
|
|
1246
|
+
{ first, after },
|
|
1247
|
+
["wpgraphql", "gql-authors"]
|
|
1248
|
+
);
|
|
1249
|
+
return data.users;
|
|
1250
|
+
}
|
|
1251
|
+
async function getAuthorBySlug(slug) {
|
|
1252
|
+
const data = await gqlFetchGraceful(
|
|
1253
|
+
GQL_GET_AUTHOR_BY_SLUG,
|
|
1254
|
+
{ users: { nodes: [] } },
|
|
1255
|
+
{ slug },
|
|
1256
|
+
["wpgraphql", "gql-authors", `gql-author-${slug}`]
|
|
1257
|
+
);
|
|
1258
|
+
return data.users.nodes[0] ?? null;
|
|
1259
|
+
}
|
|
1260
|
+
return { getAuthors, getAuthorBySlug };
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1263
|
+
// src/integrations/wpGraphQL/core/index.ts
|
|
1264
|
+
function createWPGraphQLCoreClient(config) {
|
|
1265
|
+
const fetcher = createWPGraphQLFetcher(config);
|
|
1266
|
+
return {
|
|
1267
|
+
...createPostsQueries2(fetcher),
|
|
1268
|
+
...createPagesQueries2(fetcher),
|
|
1269
|
+
...createCategoriesQueries3(fetcher),
|
|
1270
|
+
...createTagsQueries3(fetcher),
|
|
1271
|
+
...createAuthorsQueries2(fetcher)
|
|
1272
|
+
};
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
// src/integrations/wpGraphQL/yoast/queries.ts
|
|
1276
|
+
var SEO_FIELDS = `
|
|
1277
|
+
seo {
|
|
1278
|
+
title
|
|
1279
|
+
metaDesc
|
|
1280
|
+
canonical
|
|
1281
|
+
opengraphTitle
|
|
1282
|
+
opengraphDescription
|
|
1283
|
+
opengraphImage { sourceUrl altText }
|
|
1284
|
+
twitterTitle
|
|
1285
|
+
twitterDescription
|
|
1286
|
+
twitterImage { sourceUrl }
|
|
1287
|
+
schema { raw }
|
|
1288
|
+
}
|
|
1289
|
+
`;
|
|
1290
|
+
var POST_FIELDS_WITH_SEO = `
|
|
1291
|
+
id
|
|
1292
|
+
databaseId
|
|
1293
|
+
slug
|
|
1294
|
+
title
|
|
1295
|
+
content
|
|
1296
|
+
excerpt
|
|
1297
|
+
date
|
|
1298
|
+
modified
|
|
1299
|
+
status
|
|
1300
|
+
uri
|
|
1301
|
+
author {
|
|
1302
|
+
node {
|
|
1303
|
+
databaseId
|
|
1304
|
+
name
|
|
1305
|
+
slug
|
|
1306
|
+
avatar { url }
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
featuredImage {
|
|
1310
|
+
node {
|
|
1311
|
+
sourceUrl
|
|
1312
|
+
altText
|
|
1313
|
+
mediaDetails { width height }
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
categories {
|
|
1317
|
+
nodes { databaseId name slug }
|
|
1318
|
+
}
|
|
1319
|
+
tags {
|
|
1320
|
+
nodes { databaseId name slug }
|
|
1321
|
+
}
|
|
1322
|
+
${SEO_FIELDS}
|
|
1323
|
+
`;
|
|
1324
|
+
var PAGE_FIELDS_WITH_SEO = `
|
|
1325
|
+
id
|
|
1326
|
+
databaseId
|
|
1327
|
+
slug
|
|
1328
|
+
title
|
|
1329
|
+
content
|
|
1330
|
+
date
|
|
1331
|
+
modified
|
|
1332
|
+
status
|
|
1333
|
+
uri
|
|
1334
|
+
featuredImage {
|
|
1335
|
+
node {
|
|
1336
|
+
sourceUrl
|
|
1337
|
+
altText
|
|
1338
|
+
mediaDetails { width height }
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
${SEO_FIELDS}
|
|
1342
|
+
`;
|
|
1343
|
+
var GQL_GET_POST_WITH_SEO = `
|
|
1344
|
+
query GetPostWithSEO($slug: ID!) {
|
|
1345
|
+
post(id: $slug, idType: SLUG) { ${POST_FIELDS_WITH_SEO} }
|
|
1346
|
+
}
|
|
1347
|
+
`;
|
|
1348
|
+
var GQL_GET_PAGE_WITH_SEO = `
|
|
1349
|
+
query GetPageWithSEO($slug: ID!) {
|
|
1350
|
+
page(id: $slug, idType: SLUG) { ${PAGE_FIELDS_WITH_SEO} }
|
|
1351
|
+
}
|
|
1352
|
+
`;
|
|
1353
|
+
var GQL_GET_PAGE_WITH_SEO_BY_URI = `
|
|
1354
|
+
query GetPageWithSEOByUri($uri: ID!) {
|
|
1355
|
+
page(id: $uri, idType: URI) { ${PAGE_FIELDS_WITH_SEO} }
|
|
1356
|
+
}
|
|
1357
|
+
`;
|
|
1358
|
+
function createYoastQueries(fetcher) {
|
|
1359
|
+
const { gqlFetchGraceful } = fetcher;
|
|
1360
|
+
async function getPostWithSEO(slug) {
|
|
1361
|
+
const data = await gqlFetchGraceful(
|
|
1362
|
+
GQL_GET_POST_WITH_SEO,
|
|
1363
|
+
{ post: null },
|
|
1364
|
+
{ slug },
|
|
1365
|
+
["wpgraphql", "gql-posts", "gql-yoast", `gql-post-${slug}`]
|
|
1366
|
+
);
|
|
1367
|
+
return data.post;
|
|
1368
|
+
}
|
|
1369
|
+
async function getPageWithSEO(slug) {
|
|
1370
|
+
const data = await gqlFetchGraceful(
|
|
1371
|
+
GQL_GET_PAGE_WITH_SEO,
|
|
1372
|
+
{ page: null },
|
|
1373
|
+
{ slug },
|
|
1374
|
+
["wpgraphql", "gql-pages", "gql-yoast", `gql-page-${slug}`]
|
|
1375
|
+
);
|
|
1376
|
+
return data.page;
|
|
1377
|
+
}
|
|
1378
|
+
async function getPageWithSEOByUri(uri) {
|
|
1379
|
+
const data = await gqlFetchGraceful(
|
|
1380
|
+
GQL_GET_PAGE_WITH_SEO_BY_URI,
|
|
1381
|
+
{ page: null },
|
|
1382
|
+
{ uri },
|
|
1383
|
+
["wpgraphql", "gql-pages", "gql-yoast", `gql-page-uri-${uri.replace(/\//g, "-")}`]
|
|
1384
|
+
);
|
|
1385
|
+
return data.page;
|
|
1386
|
+
}
|
|
1387
|
+
return { getPostWithSEO, getPageWithSEO, getPageWithSEOByUri };
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1390
|
+
// src/integrations/wpGraphQL/acf/helpers.ts
|
|
1391
|
+
var BASE_POST_FIELDS = `
|
|
1392
|
+
id databaseId slug title content excerpt date modified status uri
|
|
1393
|
+
author { node { databaseId name slug avatar { url } } }
|
|
1394
|
+
featuredImage { node { sourceUrl altText mediaDetails { width height } } }
|
|
1395
|
+
categories { nodes { databaseId name slug } }
|
|
1396
|
+
tags { nodes { databaseId name slug } }
|
|
1397
|
+
`;
|
|
1398
|
+
var BASE_PAGE_FIELDS = `
|
|
1399
|
+
id databaseId slug title content date modified status uri
|
|
1400
|
+
featuredImage { node { sourceUrl altText mediaDetails { width height } } }
|
|
1401
|
+
`;
|
|
1402
|
+
function buildACFFragment(fieldGroupName, fields) {
|
|
1403
|
+
return `${fieldGroupName} { ${fields.join(" ")} }`;
|
|
1404
|
+
}
|
|
1405
|
+
function buildPostWithACFQuery(fieldGroupName, fields) {
|
|
1406
|
+
return `
|
|
1407
|
+
query GetPostWithACF($slug: ID!) {
|
|
1408
|
+
post(id: $slug, idType: SLUG) {
|
|
1409
|
+
${BASE_POST_FIELDS}
|
|
1410
|
+
${buildACFFragment(fieldGroupName, fields)}
|
|
1411
|
+
}
|
|
1412
|
+
}
|
|
1413
|
+
`;
|
|
1414
|
+
}
|
|
1415
|
+
function buildPageWithACFQuery(fieldGroupName, fields) {
|
|
1416
|
+
return `
|
|
1417
|
+
query GetPageWithACF($slug: ID!) {
|
|
1418
|
+
page(id: $slug, idType: SLUG) {
|
|
1419
|
+
${BASE_PAGE_FIELDS}
|
|
1420
|
+
${buildACFFragment(fieldGroupName, fields)}
|
|
1421
|
+
}
|
|
1422
|
+
}
|
|
1423
|
+
`;
|
|
1424
|
+
}
|
|
1425
|
+
function buildPostsWithACFQuery(fieldGroupName, fields) {
|
|
1426
|
+
return `
|
|
1427
|
+
query GetPostsWithACF($first: Int, $after: String) {
|
|
1428
|
+
posts(first: $first, after: $after) {
|
|
1429
|
+
nodes {
|
|
1430
|
+
${BASE_POST_FIELDS}
|
|
1431
|
+
${buildACFFragment(fieldGroupName, fields)}
|
|
1432
|
+
}
|
|
1433
|
+
pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
`;
|
|
1437
|
+
}
|
|
1438
|
+
|
|
1439
|
+
// src/integrations/wpGraphQL/woocommerce/products/queries.ts
|
|
1440
|
+
var DEFAULT_FIRST6 = 10;
|
|
1441
|
+
var BATCH_FIRST3 = 100;
|
|
1442
|
+
var PRODUCT_FIELDS = `
|
|
1443
|
+
id
|
|
1444
|
+
databaseId
|
|
1445
|
+
slug
|
|
1446
|
+
name
|
|
1447
|
+
description
|
|
1448
|
+
shortDescription
|
|
1449
|
+
sku
|
|
1450
|
+
price
|
|
1451
|
+
regularPrice
|
|
1452
|
+
salePrice
|
|
1453
|
+
onSale
|
|
1454
|
+
stockStatus
|
|
1455
|
+
stockQuantity
|
|
1456
|
+
manageStock
|
|
1457
|
+
type
|
|
1458
|
+
featuredImage { node { sourceUrl altText } }
|
|
1459
|
+
galleryImages { nodes { sourceUrl altText } }
|
|
1460
|
+
productCategories { nodes { databaseId name slug } }
|
|
1461
|
+
productTags { nodes { databaseId name slug } }
|
|
1462
|
+
... on VariableProduct {
|
|
1463
|
+
variations {
|
|
1464
|
+
nodes {
|
|
1465
|
+
id
|
|
1466
|
+
databaseId
|
|
1467
|
+
slug
|
|
1468
|
+
sku
|
|
1469
|
+
price
|
|
1470
|
+
regularPrice
|
|
1471
|
+
salePrice
|
|
1472
|
+
onSale
|
|
1473
|
+
stockStatus
|
|
1474
|
+
stockQuantity
|
|
1475
|
+
image { sourceUrl altText }
|
|
1476
|
+
attributes { nodes { name value } }
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
}
|
|
1480
|
+
`;
|
|
1481
|
+
var GQL_GET_PRODUCTS = `
|
|
1482
|
+
query GetProducts($first: Int, $after: String, $where: RootQueryToProductConnectionWhereArgs) {
|
|
1483
|
+
products(first: $first, after: $after, where: $where) {
|
|
1484
|
+
nodes { ${PRODUCT_FIELDS} }
|
|
1485
|
+
pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
|
|
1486
|
+
}
|
|
1487
|
+
}
|
|
1488
|
+
`;
|
|
1489
|
+
var GQL_GET_PRODUCT_BY_SLUG = `
|
|
1490
|
+
query GetProductBySlug($slug: ID!) {
|
|
1491
|
+
product(id: $slug, idType: SLUG) { ${PRODUCT_FIELDS} }
|
|
1492
|
+
}
|
|
1493
|
+
`;
|
|
1494
|
+
var GQL_GET_PRODUCT_BY_DATABASE_ID = `
|
|
1495
|
+
query GetProductByDatabaseId($id: ID!) {
|
|
1496
|
+
product(id: $id, idType: DATABASE_ID) { ${PRODUCT_FIELDS} }
|
|
1497
|
+
}
|
|
1498
|
+
`;
|
|
1499
|
+
var GQL_GET_ALL_PRODUCT_SLUGS = `
|
|
1500
|
+
query GetAllProductSlugs($first: Int, $after: String) {
|
|
1501
|
+
products(first: $first, after: $after) {
|
|
1502
|
+
nodes { slug }
|
|
1503
|
+
pageInfo { hasNextPage endCursor }
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1506
|
+
`;
|
|
1507
|
+
function createProductsQueries2(fetcher) {
|
|
1508
|
+
const { gqlFetch, gqlFetchGraceful } = fetcher;
|
|
1509
|
+
async function getProducts(first = DEFAULT_FIRST6, after, filter) {
|
|
1510
|
+
const where = {};
|
|
1511
|
+
if (filter?.search) where["search"] = filter.search;
|
|
1512
|
+
if (filter?.onSale !== void 0) where["onSale"] = filter.onSale;
|
|
1513
|
+
if (filter?.featured !== void 0) where["featured"] = filter.featured;
|
|
1514
|
+
if (filter?.stockStatus) where["stockStatus"] = filter.stockStatus;
|
|
1515
|
+
if (filter?.minPrice) where["minPrice"] = filter.minPrice;
|
|
1516
|
+
if (filter?.maxPrice) where["maxPrice"] = filter.maxPrice;
|
|
1517
|
+
if (filter?.categoryId) where["categoryIdIn"] = [filter.categoryId];
|
|
1518
|
+
if (filter?.tagId) where["tagIdIn"] = [filter.tagId];
|
|
1519
|
+
const data = await gqlFetchGraceful(
|
|
1520
|
+
GQL_GET_PRODUCTS,
|
|
1521
|
+
{ products: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
|
|
1522
|
+
{ first, after, where: Object.keys(where).length > 0 ? where : void 0 },
|
|
1523
|
+
["wpgraphql", "gql-products"]
|
|
1524
|
+
);
|
|
1525
|
+
return data.products;
|
|
1526
|
+
}
|
|
1527
|
+
async function getProductBySlug(slug) {
|
|
1528
|
+
const data = await gqlFetchGraceful(
|
|
1529
|
+
GQL_GET_PRODUCT_BY_SLUG,
|
|
1530
|
+
{ product: null },
|
|
1531
|
+
{ slug },
|
|
1532
|
+
["wpgraphql", "gql-products", `gql-product-${slug}`]
|
|
1533
|
+
);
|
|
1534
|
+
return data.product;
|
|
1535
|
+
}
|
|
1536
|
+
async function getProductByDatabaseId(id) {
|
|
1537
|
+
const data = await gqlFetchGraceful(
|
|
1538
|
+
GQL_GET_PRODUCT_BY_DATABASE_ID,
|
|
1539
|
+
{ product: null },
|
|
1540
|
+
{ id: String(id) },
|
|
1541
|
+
["wpgraphql", "gql-products", `gql-product-id-${id}`]
|
|
1542
|
+
);
|
|
1543
|
+
return data.product;
|
|
1544
|
+
}
|
|
1545
|
+
async function getFeaturedProducts(first = DEFAULT_FIRST6) {
|
|
1546
|
+
const connection = await getProducts(first, void 0, { featured: true });
|
|
1547
|
+
return connection.nodes;
|
|
1548
|
+
}
|
|
1549
|
+
async function getOnSaleProducts(first = DEFAULT_FIRST6) {
|
|
1550
|
+
const connection = await getProducts(first, void 0, { onSale: true });
|
|
1551
|
+
return connection.nodes;
|
|
1552
|
+
}
|
|
1553
|
+
async function getAllProductSlugs() {
|
|
1554
|
+
try {
|
|
1555
|
+
const all = [];
|
|
1556
|
+
let after = void 0;
|
|
1557
|
+
let hasNextPage = true;
|
|
1558
|
+
while (hasNextPage) {
|
|
1559
|
+
const data = await gqlFetch(GQL_GET_ALL_PRODUCT_SLUGS, { first: BATCH_FIRST3, after }, ["wpgraphql"]);
|
|
1560
|
+
all.push(...data.products.nodes);
|
|
1561
|
+
hasNextPage = data.products.pageInfo.hasNextPage;
|
|
1562
|
+
after = data.products.pageInfo.endCursor;
|
|
1563
|
+
}
|
|
1564
|
+
return all;
|
|
1565
|
+
} catch {
|
|
1566
|
+
console.warn("WPGraphQL unavailable, skipping static generation for products");
|
|
1567
|
+
return [];
|
|
1568
|
+
}
|
|
1569
|
+
}
|
|
1570
|
+
return {
|
|
1571
|
+
getProducts,
|
|
1572
|
+
getProductBySlug,
|
|
1573
|
+
getProductByDatabaseId,
|
|
1574
|
+
getFeaturedProducts,
|
|
1575
|
+
getOnSaleProducts,
|
|
1576
|
+
getAllProductSlugs
|
|
1577
|
+
};
|
|
1578
|
+
}
|
|
1579
|
+
|
|
1580
|
+
// src/integrations/wpGraphQL/woocommerce/orders/queries.ts
|
|
1581
|
+
var DEFAULT_FIRST7 = 10;
|
|
1582
|
+
var ADDRESS_FIELDS = `
|
|
1583
|
+
firstName lastName address1 address2 city postcode country email phone
|
|
1584
|
+
`;
|
|
1585
|
+
var ORDER_FIELDS = `
|
|
1586
|
+
id
|
|
1587
|
+
databaseId
|
|
1588
|
+
orderNumber
|
|
1589
|
+
status
|
|
1590
|
+
date
|
|
1591
|
+
modified
|
|
1592
|
+
total
|
|
1593
|
+
subtotal
|
|
1594
|
+
totalTax
|
|
1595
|
+
shippingTotal
|
|
1596
|
+
currency
|
|
1597
|
+
billing { ${ADDRESS_FIELDS} }
|
|
1598
|
+
shipping { ${ADDRESS_FIELDS} }
|
|
1599
|
+
lineItems {
|
|
1600
|
+
nodes {
|
|
1601
|
+
productId
|
|
1602
|
+
variationId
|
|
1603
|
+
quantity
|
|
1604
|
+
subtotal
|
|
1605
|
+
total
|
|
1606
|
+
product { node { databaseId name slug } }
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
`;
|
|
1610
|
+
var GQL_GET_ORDER = `
|
|
1611
|
+
query GetOrder($id: ID!) {
|
|
1612
|
+
order(id: $id, idType: DATABASE_ID) { ${ORDER_FIELDS} }
|
|
1613
|
+
}
|
|
1614
|
+
`;
|
|
1615
|
+
var GQL_GET_MY_ORDERS = `
|
|
1616
|
+
query GetMyOrders($first: Int, $after: String) {
|
|
1617
|
+
orders(first: $first, after: $after) {
|
|
1618
|
+
nodes { ${ORDER_FIELDS} }
|
|
1619
|
+
pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
|
|
1620
|
+
}
|
|
1621
|
+
}
|
|
1622
|
+
`;
|
|
1623
|
+
function createOrdersQueries2(fetcher) {
|
|
1624
|
+
const { gqlFetchGraceful } = fetcher;
|
|
1625
|
+
async function getOrder(id) {
|
|
1626
|
+
const data = await gqlFetchGraceful(
|
|
1627
|
+
GQL_GET_ORDER,
|
|
1628
|
+
{ order: null },
|
|
1629
|
+
{ id: String(id) },
|
|
1630
|
+
["wpgraphql", "gql-orders", `gql-order-${id}`]
|
|
1631
|
+
);
|
|
1632
|
+
return data.order;
|
|
1633
|
+
}
|
|
1634
|
+
async function getMyOrders(first = DEFAULT_FIRST7, after) {
|
|
1635
|
+
const data = await gqlFetchGraceful(
|
|
1636
|
+
GQL_GET_MY_ORDERS,
|
|
1637
|
+
{ orders: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
|
|
1638
|
+
{ first, after },
|
|
1639
|
+
["wpgraphql", "gql-orders"]
|
|
1640
|
+
);
|
|
1641
|
+
return data.orders;
|
|
1642
|
+
}
|
|
1643
|
+
return { getOrder, getMyOrders };
|
|
1644
|
+
}
|
|
1645
|
+
|
|
1646
|
+
// src/integrations/wpGraphQL/woocommerce/customers/queries.ts
|
|
1647
|
+
var ADDRESS_FIELDS2 = `
|
|
1648
|
+
firstName lastName address1 address2 city postcode country
|
|
1649
|
+
`;
|
|
1650
|
+
var CUSTOMER_FIELDS = `
|
|
1651
|
+
id
|
|
1652
|
+
databaseId
|
|
1653
|
+
email
|
|
1654
|
+
firstName
|
|
1655
|
+
lastName
|
|
1656
|
+
username
|
|
1657
|
+
billing { ${ADDRESS_FIELDS2} phone }
|
|
1658
|
+
shipping { ${ADDRESS_FIELDS2} }
|
|
1659
|
+
`;
|
|
1660
|
+
var GQL_GET_CUSTOMER = `
|
|
1661
|
+
query GetCustomer {
|
|
1662
|
+
customer { ${CUSTOMER_FIELDS} }
|
|
1663
|
+
}
|
|
1664
|
+
`;
|
|
1665
|
+
var GQL_GET_CUSTOMER_BY_ID = `
|
|
1666
|
+
query GetCustomerById($id: ID!) {
|
|
1667
|
+
customer(customerId: $id) { ${CUSTOMER_FIELDS} }
|
|
1668
|
+
}
|
|
1669
|
+
`;
|
|
1670
|
+
function createCustomersQueries2(fetcher) {
|
|
1671
|
+
const { gqlFetchGraceful } = fetcher;
|
|
1672
|
+
async function getCustomer() {
|
|
1673
|
+
const data = await gqlFetchGraceful(
|
|
1674
|
+
GQL_GET_CUSTOMER,
|
|
1675
|
+
{ customer: null },
|
|
1676
|
+
void 0,
|
|
1677
|
+
["wpgraphql", "gql-customer"]
|
|
1678
|
+
);
|
|
1679
|
+
return data.customer;
|
|
1680
|
+
}
|
|
1681
|
+
async function getCustomerById(id) {
|
|
1682
|
+
const data = await gqlFetchGraceful(
|
|
1683
|
+
GQL_GET_CUSTOMER_BY_ID,
|
|
1684
|
+
{ customer: null },
|
|
1685
|
+
{ id: String(id) },
|
|
1686
|
+
["wpgraphql", "gql-customer", `gql-customer-${id}`]
|
|
1687
|
+
);
|
|
1688
|
+
return data.customer;
|
|
1689
|
+
}
|
|
1690
|
+
return { getCustomer, getCustomerById };
|
|
1691
|
+
}
|
|
1692
|
+
|
|
1693
|
+
// src/integrations/wpGraphQL/woocommerce/index.ts
|
|
1694
|
+
function createWPGraphQLWooCommerceClient(config) {
|
|
1695
|
+
const fetcher = createWPGraphQLFetcher(config);
|
|
1696
|
+
return {
|
|
1697
|
+
...createProductsQueries2(fetcher),
|
|
1698
|
+
...createOrdersQueries2(fetcher),
|
|
1699
|
+
...createCustomersQueries2(fetcher)
|
|
1700
|
+
};
|
|
1701
|
+
}
|
|
1702
|
+
|
|
1703
|
+
// src/integrations/wpGraphQL/cpt/queries.ts
|
|
1704
|
+
var DEFAULT_FIRST8 = 10;
|
|
1705
|
+
var BATCH_FIRST4 = 100;
|
|
1706
|
+
var BASE_CPT_FIELDS = `
|
|
1707
|
+
id databaseId slug title date modified status uri
|
|
1708
|
+
`;
|
|
1709
|
+
function createCPTQueries(fetcher, typeName, singularTypeName, extraFields) {
|
|
1710
|
+
const { gqlFetch, gqlFetchGraceful } = fetcher;
|
|
1711
|
+
const fields = extraFields ? `${BASE_CPT_FIELDS} ${extraFields}` : BASE_CPT_FIELDS;
|
|
1712
|
+
const GQL_GET_ITEMS = `
|
|
1713
|
+
query GetCPT_${typeName}($first: Int, $after: String) {
|
|
1714
|
+
${typeName}(first: $first, after: $after) {
|
|
1715
|
+
nodes { ${fields} }
|
|
1716
|
+
pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
|
|
1717
|
+
}
|
|
1718
|
+
}
|
|
1719
|
+
`;
|
|
1720
|
+
const GQL_GET_ITEM_BY_SLUG = `
|
|
1721
|
+
query GetCPT_${singularTypeName}BySlug($slug: ID!) {
|
|
1722
|
+
${singularTypeName}(id: $slug, idType: SLUG) { ${fields} }
|
|
1723
|
+
}
|
|
1724
|
+
`;
|
|
1725
|
+
const GQL_GET_ALL_SLUGS = `
|
|
1726
|
+
query GetAllCPT_${typeName}Slugs($first: Int, $after: String) {
|
|
1727
|
+
${typeName}(first: $first, after: $after) {
|
|
1728
|
+
nodes { slug }
|
|
1729
|
+
pageInfo { hasNextPage endCursor }
|
|
1730
|
+
}
|
|
1731
|
+
}
|
|
1732
|
+
`;
|
|
1733
|
+
async function getItems(first = DEFAULT_FIRST8, after) {
|
|
1734
|
+
const data = await gqlFetchGraceful(
|
|
1735
|
+
GQL_GET_ITEMS,
|
|
1736
|
+
{ [typeName]: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
|
|
1737
|
+
{ first, after },
|
|
1738
|
+
["wpgraphql", `gql-${typeName}`]
|
|
1739
|
+
);
|
|
1740
|
+
return data[typeName] ?? { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } };
|
|
1741
|
+
}
|
|
1742
|
+
async function getItemBySlug(slug) {
|
|
1743
|
+
const data = await gqlFetchGraceful(
|
|
1744
|
+
GQL_GET_ITEM_BY_SLUG,
|
|
1745
|
+
{ [singularTypeName]: null },
|
|
1746
|
+
{ slug },
|
|
1747
|
+
["wpgraphql", `gql-${typeName}`, `gql-${singularTypeName}-${slug}`]
|
|
1748
|
+
);
|
|
1749
|
+
return data[singularTypeName] ?? null;
|
|
1750
|
+
}
|
|
1751
|
+
async function getAllSlugs() {
|
|
1752
|
+
try {
|
|
1753
|
+
const all = [];
|
|
1754
|
+
let after = void 0;
|
|
1755
|
+
let hasNextPage = true;
|
|
1756
|
+
while (hasNextPage) {
|
|
1757
|
+
const data = await gqlFetch(GQL_GET_ALL_SLUGS, { first: BATCH_FIRST4, after }, ["wpgraphql"]);
|
|
1758
|
+
const connection = data[typeName];
|
|
1759
|
+
if (!connection) break;
|
|
1760
|
+
all.push(...connection.nodes);
|
|
1761
|
+
hasNextPage = connection.pageInfo.hasNextPage;
|
|
1762
|
+
after = connection.pageInfo.endCursor;
|
|
1763
|
+
}
|
|
1764
|
+
return all;
|
|
1765
|
+
} catch {
|
|
1766
|
+
console.warn(`WPGraphQL unavailable, skipping static generation for ${typeName}`);
|
|
1767
|
+
return [];
|
|
1768
|
+
}
|
|
1769
|
+
}
|
|
1770
|
+
return { getItems, getItemBySlug, getAllSlugs };
|
|
1771
|
+
}
|
|
1772
|
+
|
|
1773
|
+
export { WPGraphQLError, buildACFFragment, buildPageWithACFQuery, buildPostWithACFQuery, buildPostsWithACFQuery, createCPTQueries, createWPGraphQLCoreClient as createWPGraphQLClient, createWPGraphQLCoreClient, createWPGraphQLFetcher, createWPGraphQLWooCommerceClient, createWooCommerceClient, createWooCommerceFetcher, createWordPressClient, createYoastQueries, extractOmnibusData, resolveBaseUrl, withOmnibus, withOmnibusVariation };
|
|
787
1774
|
//# sourceMappingURL=index.js.map
|
|
788
1775
|
//# sourceMappingURL=index.js.map
|