@wpnuxt/core 1.0.0-edge.14 → 1.0.0-edge.16

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.d.mts CHANGED
@@ -68,6 +68,7 @@ type WPNuxtQuery = {
68
68
  nodes?: string[]
69
69
  fragments: string[]
70
70
  params: Record<string, string>
71
+ operation: OperationTypeNode
71
72
  }
72
73
 
73
74
  declare const _default: _nuxt_schema.NuxtModule<WPNuxtConfig, WPNuxtConfig, false>;
package/dist/module.d.ts CHANGED
@@ -68,6 +68,7 @@ type WPNuxtQuery = {
68
68
  nodes?: string[]
69
69
  fragments: string[]
70
70
  params: Record<string, string>
71
+ operation: OperationTypeNode
71
72
  }
72
73
 
73
74
  declare const _default: _nuxt_schema.NuxtModule<WPNuxtConfig, WPNuxtConfig, false>;
package/dist/module.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wpnuxt/core",
3
- "version": "1.0.0-edge.14",
3
+ "version": "1.0.0-edge.16",
4
4
  "configKey": "wpNuxt",
5
5
  "nuxt": ">=3.1.0",
6
6
  "builder": {
package/dist/module.mjs CHANGED
@@ -7,7 +7,7 @@ import { upperFirst } from 'scule';
7
7
  import { parse } from 'graphql';
8
8
 
9
9
  const name = "@wpnuxt/core";
10
- const version = "1.0.0-edge.14";
10
+ const version = "1.0.0-edge.16";
11
11
 
12
12
  const loggerRef = ref();
13
13
  const initLogger = (logLevel) => {
@@ -49,7 +49,8 @@ const _parseDoc = async (doc) => {
49
49
  name: operationDefinition.name.value.trim(),
50
50
  nodes: [],
51
51
  fragments: [],
52
- params: {}
52
+ params: {},
53
+ operation: operationDefinition.operation
53
54
  };
54
55
  processSelections(operationDefinition.selectionSet.selections, 0, query);
55
56
  return query;
@@ -81,7 +82,7 @@ async function prepareContext(ctx) {
81
82
  const fnExp = (q, typed = false) => {
82
83
  const functionName = fnName(q.name);
83
84
  if (!typed) {
84
- return `export const ${functionName} = (params) => useWPContent('${q.name}', [${q.nodes?.map((n) => `'${n}'`).join(",")}], false, params)`;
85
+ return `export const ${functionName} = (params) => useWPContent('${q.operation}', '${q.name}', [${q.nodes?.map((n) => `'${n}'`).join(",")}], false, params)`;
85
86
  }
86
87
  const fragmentSuffix = q.fragments?.length && q.nodes?.includes("nodes") ? "[]" : "";
87
88
  const fragments = q.fragments?.length ? q.fragments.map((f) => `${f}Fragment${fragmentSuffix}`).join(" | ") : "any";
@@ -1,4 +1,5 @@
1
1
  <script setup lang="ts">
2
+ import { OperationTypeNode } from 'graphql'
2
3
  import { useWPUri } from '../composables/useWPUri'
3
4
  import { useWPContent } from '../composables'
4
5
  import WPNuxtLogo from './WPNuxtLogo.vue'
@@ -27,7 +28,7 @@ if (uri.startsWith('/')) {
27
28
  if (uri.endsWith('/')) {
28
29
  uri = uri.substring(0, uri.length - 1)
29
30
  }
30
- const { data: post } = await useWPContent('NodeByUri', ['nodeByUri'], false, { uri: uri })
31
+ const { data: post } = await useWPContent(OperationTypeNode.QUERY, 'NodeByUri', ['nodeByUri'], false, { uri: uri })
31
32
 
32
33
  if (import.meta.client) {
33
34
  document.body.style.marginBottom = '40px'
@@ -1,3 +1,4 @@
1
+ import { OperationTypeNode } from "graphql";
1
2
  import { useWPContent } from "./useWPContent.js";
2
3
  const _usePrevNextPost = async (currentPostSlug) => {
3
4
  const allPosts = await getAllPosts();
@@ -11,7 +12,7 @@ const _usePrevNextPost = async (currentPostSlug) => {
11
12
  };
12
13
  };
13
14
  const getAllPosts = async () => {
14
- const { data: allPosts } = await useWPContent("Posts", ["posts", "nodes"], false);
15
+ const { data: allPosts } = await useWPContent(OperationTypeNode.QUERY, "Posts", ["posts", "nodes"], false);
15
16
  if (allPosts) {
16
17
  return {
17
18
  slugs: allPosts?.map((post) => {
@@ -1,5 +1,6 @@
1
1
  import type { FetchError } from 'ofetch';
2
- export declare const useWPContent: <T>(queryName: string, nodes: string[], fixImagePaths: boolean, params?: T) => Promise<{
2
+ import type { OperationTypeNode } from 'graphql';
3
+ export declare const useWPContent: <T>(operation: OperationTypeNode, queryName: string, nodes: string[], fixImagePaths: boolean, params?: T) => Promise<{
3
4
  data: unknown;
4
5
  error: import("vue").Ref<FetchError<any> | null>;
5
6
  }>;
@@ -1,14 +1,15 @@
1
1
  import { getRelativeImagePath } from "../util/images.js";
2
- const _useWPContent = async (queryName, nodes, fixImagePaths, params) => {
2
+ const _useWPContent = async (operation, queryName, nodes, fixImagePaths, params) => {
3
3
  const { data, error } = await $fetch("/api/wpContent", {
4
4
  method: "POST",
5
5
  body: {
6
+ operation,
6
7
  queryName,
7
8
  params
8
9
  }
9
10
  });
10
11
  return {
11
- data: transformData(data, nodes, fixImagePaths),
12
+ data: error ? void 0 : transformData(data, nodes, fixImagePaths),
12
13
  error
13
14
  };
14
15
  };
@@ -7,15 +7,17 @@ export default defineCachedEventHandler(async (event) => {
7
7
  "The request must contain a queryName"
8
8
  );
9
9
  }
10
- return $fetch("/api/graphql_middleware/query/" + body.queryName, {
11
- params: buildRequestParams(body.params),
10
+ return $fetch("/api/graphql_middleware/" + (body.operation || "query") + "/" + body.queryName, {
11
+ method: body.operation === "mutation" ? "POST" : "GET",
12
+ params: body.operation === "query" ? buildRequestParams(body.params) : void 0,
13
+ body: body.operation === "mutation" ? body.params : void 0,
12
14
  headers: {
13
15
  Authorization: `Bearer ${event.context.accessToken}`
14
16
  }
15
17
  }).then((v) => {
16
18
  return {
17
19
  data: v.data,
18
- errors: v.errors || []
20
+ error: v.errors || void 0
19
21
  };
20
22
  });
21
23
  }, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wpnuxt/core",
3
- "version": "1.0.0-edge.14",
3
+ "version": "1.0.0-edge.16",
4
4
  "description": "WPNuxt",
5
5
  "repository": {
6
6
  "type": "git",