@wpnuxt/core 2.2.0 → 2.2.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.
@@ -0,0 +1,28 @@
1
+ import { defineGraphqlClientOptions } from 'nuxt-graphql-middleware/client-options'
2
+ import { useRoute } from '#imports'
3
+
4
+ /**
5
+ * WPNuxt default client options for nuxt-graphql-middleware.
6
+ *
7
+ * This enables passing client context to the server for:
8
+ * - Preview mode (passes preview flag and token from URL query params)
9
+ *
10
+ * The context is available in serverFetchOptions via context.client
11
+ * All values must be strings (nuxt-graphql-middleware requirement)
12
+ *
13
+ * Users can customize by creating their own app/graphqlMiddleware.clientOptions.ts
14
+ */
15
+ export default defineGraphqlClientOptions<{
16
+ preview?: string
17
+ previewToken?: string
18
+ }>({
19
+ buildClientContext() {
20
+ const route = useRoute()
21
+
22
+ return {
23
+ // Context values must be strings - use 'true'/'false' instead of boolean
24
+ preview: route.query.preview === 'true' ? 'true' : undefined,
25
+ previewToken: route.query.token as string | undefined
26
+ }
27
+ }
28
+ })
package/dist/module.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wpnuxt/core",
3
- "version": "2.2.0",
3
+ "version": "2.2.2",
4
4
  "configKey": "wpNuxt",
5
5
  "compatibility": {
6
6
  "nuxt": ">=4.0.0"
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.2.0";
11
+ const version = "2.2.2";
12
12
 
13
13
  function createModuleError(module, message) {
14
14
  return new Error(formatErrorMessage(module, message));
@@ -891,8 +891,18 @@ const module$1 = defineNuxtModule({
891
891
  addPlugin(resolver.resolve("./runtime/plugins/sanitizeHtml"));
892
892
  configureTrailingSlash(nuxt, logger);
893
893
  const mergedQueriesFolder = await mergeQueries(nuxt, wpNuxtConfig, resolver);
894
- await setupServerOptions(nuxt, resolver, logger);
895
- await setupClientOptions(nuxt, resolver, logger);
894
+ const packageRoot = resolver.resolve("..");
895
+ nuxt.options._layers.push({
896
+ cwd: packageRoot,
897
+ configFile: "",
898
+ config: {
899
+ rootDir: packageRoot,
900
+ srcDir: packageRoot,
901
+ serverDir: join(packageRoot, "server"),
902
+ appDir: join(packageRoot, "app")
903
+ }
904
+ });
905
+ logger.debug("Registered WPNuxt layer for graphqlMiddleware options auto-discovery");
896
906
  const schemaPath = join(nuxt.options.rootDir, "schema.graphql");
897
907
  const schemaExists = existsSync(schemaPath);
898
908
  if (wpNuxtConfig.downloadSchema) {
@@ -1091,40 +1101,6 @@ async function loadConfig(options, nuxt) {
1091
1101
  }
1092
1102
  return config;
1093
1103
  }
1094
- async function setupServerOptions(nuxt, resolver, logger) {
1095
- const serverDir = nuxt.options.serverDir;
1096
- const targetPath = join(serverDir, "graphqlMiddleware.serverOptions.ts");
1097
- if (existsSync(targetPath)) {
1098
- logger.debug("Using existing graphqlMiddleware.serverOptions.ts from project");
1099
- return;
1100
- }
1101
- if (!existsSync(serverDir)) {
1102
- await mkdir(serverDir, { recursive: true });
1103
- }
1104
- const template = readFileSync(
1105
- resolver.resolve("./runtime/server/graphqlMiddleware.serverOptions.ts"),
1106
- "utf-8"
1107
- );
1108
- await writeFile(targetPath, template);
1109
- logger.debug("Created graphqlMiddleware.serverOptions.ts with WPNuxt defaults (cookie/auth forwarding)");
1110
- }
1111
- async function setupClientOptions(nuxt, resolver, logger) {
1112
- const appDir = nuxt.options.dir.app;
1113
- const targetPath = join(appDir, "graphqlMiddleware.clientOptions.ts");
1114
- if (existsSync(targetPath)) {
1115
- logger.debug("Using existing graphqlMiddleware.clientOptions.ts from project");
1116
- return;
1117
- }
1118
- if (!existsSync(appDir)) {
1119
- await mkdir(appDir, { recursive: true });
1120
- }
1121
- const template = readFileSync(
1122
- resolver.resolve("./runtime/app/graphqlMiddleware.clientOptions.ts"),
1123
- "utf-8"
1124
- );
1125
- await writeFile(targetPath, template);
1126
- logger.debug("Created graphqlMiddleware.clientOptions.ts with WPNuxt defaults (preview mode support)");
1127
- }
1128
1104
  function configureTrailingSlash(nuxt, logger) {
1129
1105
  const handlerPath = join(nuxt.options.buildDir, "wpnuxt", "trailing-slash-handler.ts").replace(/\\/g, "/");
1130
1106
  const handlerCode = `import { defineEventHandler, sendRedirect, getRequestURL } from 'h3'
@@ -4,7 +4,7 @@ const defaultGetCachedData = (key, app, ctx) => {
4
4
  if (app.isHydrating) {
5
5
  return app.payload.data[key];
6
6
  }
7
- if (ctx.cause === "refresh:manual" || ctx.cause === "refresh:hook") {
7
+ if (ctx.cause === "refresh:manual" || ctx.cause === "refresh:hook" || ctx.cause === "watch") {
8
8
  return void 0;
9
9
  }
10
10
  return app.static?.data?.[key] ?? app.payload.data[key] ?? app.$graphqlCache?.get(key);
@@ -1,5 +1,5 @@
1
- query Posts($limit: Int = 10) {
2
- posts(first: $limit) {
1
+ query Posts($limit: Int = 10, $order: OrderEnum = DESC, $orderField: PostObjectsConnectionOrderbyEnum = DATE) {
2
+ posts(first: $limit, where: { orderby: { field: $orderField, order: $order } }) {
3
3
  nodes {
4
4
  ...Post
5
5
  }
@@ -16,15 +16,15 @@ query PostById($id: ID!, $asPreview: Boolean = false) {
16
16
  }
17
17
  }
18
18
 
19
- query PostsByCategoryName($categoryName: String!, $limit: Int = 10) {
20
- posts(first: $limit, where: {categoryName: $categoryName}) {
19
+ query PostsByCategoryName($categoryName: String!, $limit: Int = 10, $order: OrderEnum = DESC, $orderField: PostObjectsConnectionOrderbyEnum = DATE) {
20
+ posts(first: $limit, where: {categoryName: $categoryName, orderby: { field: $orderField, order: $order }}) {
21
21
  nodes {
22
22
  ...Post
23
23
  }
24
24
  }
25
25
  }
26
- query PostsByCategoryId($categoryId: Int!, $limit: Int = 10) {
27
- posts(first: $limit, where: {categoryId: $categoryId}) {
26
+ query PostsByCategoryId($categoryId: Int!, $limit: Int = 10, $order: OrderEnum = DESC, $orderField: PostObjectsConnectionOrderbyEnum = DATE) {
27
+ posts(first: $limit, where: {categoryId: $categoryId, orderby: { field: $orderField, order: $order }}) {
28
28
  nodes {
29
29
  ...Post
30
30
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wpnuxt/core",
3
- "version": "2.2.0",
3
+ "version": "2.2.2",
4
4
  "description": "Nuxt module for WordPress integration via GraphQL (WPGraphQL)",
5
5
  "keywords": [
6
6
  "nuxt",
@@ -40,7 +40,9 @@
40
40
  "main": "./dist/module.mjs",
41
41
  "types": "./dist/types.d.mts",
42
42
  "files": [
43
- "dist"
43
+ "dist",
44
+ "server",
45
+ "app"
44
46
  ],
45
47
  "publishConfig": {
46
48
  "access": "public"
@@ -48,21 +50,21 @@
48
50
  "dependencies": {
49
51
  "@nuxt/kit": "4.4.2",
50
52
  "consola": "^3.4.2",
51
- "defu": "^6.1.4",
52
- "dompurify": "^3.3.3",
53
- "graphql": "^16.13.1",
54
- "nuxt-graphql-middleware": "5.3.2",
53
+ "defu": "^6.1.7",
54
+ "dompurify": "^3.4.0",
55
+ "graphql": "^16.13.2",
56
+ "nuxt-graphql-middleware": "5.4.0",
55
57
  "scule": "^1.3.0"
56
58
  },
57
59
  "devDependencies": {
58
60
  "@nuxt/devtools": "^3.2.3",
59
61
  "@nuxt/module-builder": "^1.0.2",
60
62
  "@nuxt/schema": "4.4.2",
61
- "@nuxt/test-utils": "^4.0.0",
62
- "@types/node": "^25.5.0",
63
+ "@nuxt/test-utils": "^4.0.2",
64
+ "@types/node": "^25.6.0",
63
65
  "nuxt": "^4.4.2",
64
- "vitest": "^4.1.0",
65
- "vue-tsc": "^3.2.5"
66
+ "vitest": "^4.1.4",
67
+ "vue-tsc": "^3.2.6"
66
68
  },
67
69
  "peerDependencies": {
68
70
  "nuxt": ">=4.0.0"
@@ -0,0 +1,45 @@
1
+ import { defineGraphqlServerOptions } from 'nuxt-graphql-middleware/server-options'
2
+ import { getHeader, getCookie } from 'h3'
3
+ import { useRuntimeConfig } from '#imports'
4
+
5
+ /**
6
+ * WPNuxt default server options for nuxt-graphql-middleware.
7
+ *
8
+ * This enables:
9
+ * - Cookie forwarding for WordPress preview mode
10
+ * - Authorization header forwarding for authenticated requests
11
+ * - Auth token from cookie for @wpnuxt/auth
12
+ * - Consistent error logging
13
+ *
14
+ * Users can customize by creating their own server/graphqlMiddleware.serverOptions.ts
15
+ */
16
+ export default defineGraphqlServerOptions({
17
+ async serverFetchOptions(event, _operation, _operationName, _context) {
18
+ // Get auth token from Authorization header or from cookie
19
+ let authorization = getHeader(event, 'authorization') || ''
20
+
21
+ // If no Authorization header, check for auth token in cookie (@wpnuxt/auth)
22
+ if (!authorization) {
23
+ const config = (useRuntimeConfig().public as Record<string, unknown>).wpNuxtAuth as { cookieName?: string } | undefined
24
+ const cookieName = config?.cookieName || 'wpnuxt-auth-token'
25
+ const authToken = getCookie(event, cookieName)
26
+ if (authToken) {
27
+ authorization = `Bearer ${authToken}`
28
+ }
29
+ }
30
+
31
+ return {
32
+ headers: {
33
+ // Forward WordPress auth cookies for previews
34
+ Cookie: getHeader(event, 'cookie') || '',
35
+ // Forward authorization header or token from cookie
36
+ Authorization: authorization
37
+ }
38
+ }
39
+ },
40
+
41
+ async onServerError(event, error, _operation, operationName) {
42
+ const url = event.node.req.url || 'unknown'
43
+ console.error(`[WPNuxt] GraphQL error in ${operationName} (${url}):`, error.message)
44
+ }
45
+ })
@@ -1,12 +0,0 @@
1
- import { defineGraphqlClientOptions } from "@wpnuxt/core/client-options";
2
- import { useRoute } from "#imports";
3
- export default defineGraphqlClientOptions({
4
- buildClientContext() {
5
- const route = useRoute();
6
- return {
7
- // Context values must be strings - use 'true'/'false' instead of boolean
8
- preview: route.query.preview === "true" ? "true" : void 0,
9
- previewToken: route.query.token
10
- };
11
- }
12
- });
@@ -1,28 +0,0 @@
1
- import { defineGraphqlServerOptions } from "@wpnuxt/core/server-options";
2
- import { getHeader, getCookie } from "h3";
3
- import { useRuntimeConfig } from "#imports";
4
- export default defineGraphqlServerOptions({
5
- async serverFetchOptions(event, _operation, _operationName, _context) {
6
- let authorization = getHeader(event, "authorization") || "";
7
- if (!authorization) {
8
- const config = useRuntimeConfig().public.wpNuxtAuth;
9
- const cookieName = config?.cookieName || "wpnuxt-auth-token";
10
- const authToken = getCookie(event, cookieName);
11
- if (authToken) {
12
- authorization = `Bearer ${authToken}`;
13
- }
14
- }
15
- return {
16
- headers: {
17
- // Forward WordPress auth cookies for previews
18
- Cookie: getHeader(event, "cookie") || "",
19
- // Forward authorization header or token from cookie
20
- Authorization: authorization
21
- }
22
- };
23
- },
24
- async onServerError(event, error, _operation, operationName) {
25
- const url = event.node.req.url || "unknown";
26
- console.error(`[WPNuxt] GraphQL error in ${operationName} (${url}):`, error.message);
27
- }
28
- });