@wpnuxt/core 2.0.0-beta.6 → 2.0.0

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/module.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@wpnuxt/core",
3
- "version": "2.0.0-beta.6",
3
+ "version": "2.0.0",
4
4
  "configKey": "wpNuxt",
5
5
  "compatibility": {
6
- "nuxt": ">=3.17.0"
6
+ "nuxt": ">=4.0.0"
7
7
  },
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.2",
package/dist/module.mjs CHANGED
@@ -8,7 +8,7 @@ import { parse, GraphQLError, visit, print } from 'graphql';
8
8
  import { execSync } from 'node:child_process';
9
9
  import { consola } from 'consola';
10
10
 
11
- const version = "2.0.0-beta.6";
11
+ const version = "2.0.0";
12
12
 
13
13
  function createModuleError(module, message) {
14
14
  return new Error(formatErrorMessage(module, message));
@@ -71,9 +71,42 @@ async function mergeQueries(nuxt, wpNuxtConfig, resolver) {
71
71
  logger.debug("Extending queries:", userQueryPath);
72
72
  copyGraphqlFiles(userQueryPath, queryOutputPath);
73
73
  }
74
+ await addCustomFragmentsToNodeQuery(queryOutputPath, userQueryPath, logger);
74
75
  logger.debug("Merged queries folder:", queryOutputPath);
75
76
  return queryOutputPath;
76
77
  }
78
+ const FRAGMENT_DEF_PATTERN = /fragment\s+(\w+)\s+on\s+(\w+)/;
79
+ async function addCustomFragmentsToNodeQuery(queryOutputPath, userQueryPath, logger) {
80
+ const userFragmentsDir = join(userQueryPath, "fragments");
81
+ if (!existsSync(userFragmentsDir)) return;
82
+ const customFragments = [];
83
+ for (const file of readdirSync(userFragmentsDir)) {
84
+ if (!file.endsWith(".gql") && !file.endsWith(".graphql")) continue;
85
+ const content = await promises.readFile(join(userFragmentsDir, file), "utf-8");
86
+ const match = content.match(FRAGMENT_DEF_PATTERN);
87
+ if (!match) continue;
88
+ const name = match[1];
89
+ const type = match[2];
90
+ if (name && type && name === type) {
91
+ customFragments.push({ name, type });
92
+ }
93
+ }
94
+ if (customFragments.length === 0) return;
95
+ const nodeGqlPath = join(queryOutputPath, "Node.gql");
96
+ if (!existsSync(nodeGqlPath)) return;
97
+ let nodeGql = await promises.readFile(nodeGqlPath, "utf-8");
98
+ const spreads = customFragments.map((f) => ` ... on ${f.type} { ...${f.name} }`).join("\n");
99
+ nodeGql = nodeGql.replace(
100
+ /(\s+\.\.\.Post)\n(\s+\}\n\})/,
101
+ `$1
102
+ ${spreads}
103
+ $2`
104
+ );
105
+ await promises.writeFile(nodeGqlPath, nodeGql, "utf-8");
106
+ logger.debug(
107
+ `Added custom content type fragments to NodeByUri: ${customFragments.map((f) => f.name).join(", ")}`
108
+ );
109
+ }
77
110
  function findConflicts(userQueryPath, outputPath) {
78
111
  const conflicts = [];
79
112
  function walk(dir) {
@@ -771,7 +804,7 @@ const module$1 = defineNuxtModule({
771
804
  version,
772
805
  configKey: "wpNuxt",
773
806
  compatibility: {
774
- nuxt: ">=3.17.0"
807
+ nuxt: ">=4.0.0"
775
808
  }
776
809
  },
777
810
  defaults: {
@@ -53,11 +53,12 @@ export const useWPContent = (queryName, nodes, fixImagePaths, params, options) =
53
53
  }
54
54
  }
55
55
  };
56
- const { data, pending, refresh, execute, clear, error, status } = useAsyncGraphqlQuery(
56
+ const asyncResult = useAsyncGraphqlQuery(
57
57
  String(queryName),
58
58
  normalizedParams ?? {},
59
59
  asyncDataOptions
60
60
  );
61
+ const { data, pending, refresh, execute, clear, error, status } = asyncResult;
61
62
  const transformError = ref(null);
62
63
  if (timeoutId !== void 0) {
63
64
  vueWatch(pending, (isPending) => {
@@ -118,7 +119,7 @@ See: https://wpnuxt.com/guide/menus`
118
119
  return void 0;
119
120
  }
120
121
  });
121
- return {
122
+ const returnValue = {
122
123
  data: transformedData,
123
124
  pending,
124
125
  refresh,
@@ -133,4 +134,9 @@ See: https://wpnuxt.com/guide/menus`
133
134
  /** Whether a retry is currently in progress */
134
135
  isRetrying
135
136
  };
137
+ const thenable = asyncResult;
138
+ return Object.assign(
139
+ thenable.then(() => returnValue),
140
+ returnValue
141
+ );
136
142
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wpnuxt/core",
3
- "version": "2.0.0-beta.6",
3
+ "version": "2.0.0",
4
4
  "description": "Nuxt module for WordPress integration via GraphQL (WPGraphQL)",
5
5
  "keywords": [
6
6
  "nuxt",
@@ -65,7 +65,7 @@
65
65
  "vue-tsc": "^3.2.5"
66
66
  },
67
67
  "peerDependencies": {
68
- "nuxt": ">=3.17.0"
68
+ "nuxt": ">=4.0.0"
69
69
  },
70
70
  "scripts": {
71
71
  "build": "nuxt-module-build build",