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