@lewebsimple/nuxt-graphql 0.7.12 → 0.7.14
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 +1 -1
- package/dist/module.mjs +5 -5
- package/dist/runtime/app/composables/useGraphQLSubscription.client.js +2 -2
- package/dist/runtime/server/lib/remote-executor.js +2 -2
- package/dist/runtime/server/utils/execute-schema.js +2 -1
- package/dist/runtime/shared/utils/document.d.ts +18 -0
- package/dist/runtime/shared/utils/document.js +33 -0
- package/dist/runtime/shared/utils/execute.js +6 -2
- package/package.json +5 -5
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -16,7 +16,7 @@ import zodPreset from '@lewebsimple/graphql-codegen-zod';
|
|
|
16
16
|
import { createRequire } from 'node:module';
|
|
17
17
|
import { resolveCacheConfig } from '../dist/runtime/app/lib/cache-config.js';
|
|
18
18
|
|
|
19
|
-
const version = "0.7.
|
|
19
|
+
const version = "0.7.14";
|
|
20
20
|
|
|
21
21
|
const buildCache = /* @__PURE__ */ new Map();
|
|
22
22
|
function getCachedLoader(baseKey, loader) {
|
|
@@ -94,12 +94,12 @@ function getContextTemplate({ paths }) {
|
|
|
94
94
|
].join("\n");
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
const DOCUMENT_IGNORE_GLOBS = ["**/.nuxt/**", "**/.output/**", "**/dist/**", "**/node_modules/**"];
|
|
98
97
|
const DEFAULT_DOCUMENT_GLOBS = [
|
|
99
98
|
"app/**/*.{gql,ts,vue}",
|
|
100
99
|
"server/**/*.{gql,ts}",
|
|
101
100
|
"shared/**/*.{gql,ts}"
|
|
102
101
|
];
|
|
102
|
+
const DOCUMENT_IGNORE_GLOBS = ["**/.nuxt/**", "**/.output/**", "**/dist/**", "**/node_modules/**"];
|
|
103
103
|
const GRAPHQL_FILE_EXTENSIONS = /* @__PURE__ */ new Set([".gql", ".graphql"]);
|
|
104
104
|
const CODE_FILE_EXTENSIONS = /* @__PURE__ */ new Set([".ts", ".mts", ".cts", ".js", ".mjs", ".cjs", ".vue"]);
|
|
105
105
|
function getDocumentGlobs(globs) {
|
|
@@ -215,7 +215,7 @@ async function generateRegistryArtifacts({
|
|
|
215
215
|
},
|
|
216
216
|
pluginMap: {},
|
|
217
217
|
plugins: [],
|
|
218
|
-
presetConfig: {}
|
|
218
|
+
presetConfig: { documentsTypes: false }
|
|
219
219
|
});
|
|
220
220
|
if (!documents.length) {
|
|
221
221
|
return {
|
|
@@ -275,7 +275,7 @@ async function addRegistryArtifactTemplates(artifacts, nuxt) {
|
|
|
275
275
|
}
|
|
276
276
|
function getRegistryFallback() {
|
|
277
277
|
return `
|
|
278
|
-
import type {
|
|
278
|
+
import type { DocumentTypeDecoration } from "@graphql-typed-document-node/core";
|
|
279
279
|
import type * as z from "zod";
|
|
280
280
|
|
|
281
281
|
type EnumEntry = { schema: z.ZodEnum<Record<string, string>> };
|
|
@@ -284,7 +284,7 @@ type FragmentEntry = { schema: z.ZodObject<z.ZodRawShape> };
|
|
|
284
284
|
|
|
285
285
|
type OperationEntry = {
|
|
286
286
|
kind: "query" | "mutation" | "subscription";
|
|
287
|
-
document:
|
|
287
|
+
document: DocumentTypeDecoration<any, any>;
|
|
288
288
|
resultSchema: z.ZodObject<z.ZodRawShape>;
|
|
289
289
|
variablesSchema: z.ZodObject<z.ZodRawShape>;
|
|
290
290
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useNuxtApp } from "#app";
|
|
2
|
-
import { print } from "graphql";
|
|
3
2
|
import { onScopeDispose, shallowRef } from "vue";
|
|
3
|
+
import { printDocument } from "../../shared/utils/document.js";
|
|
4
4
|
import { normalizeError } from "../../shared/utils/error.js";
|
|
5
5
|
import {
|
|
6
6
|
getOperationDocument
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
export function useGraphQLSubscription(operationName, variables) {
|
|
9
9
|
const { $getGraphQLSSEClient } = useNuxtApp();
|
|
10
10
|
const document = getOperationDocument(operationName);
|
|
11
|
-
const query =
|
|
11
|
+
const query = printDocument(document);
|
|
12
12
|
const data = shallowRef(null);
|
|
13
13
|
const error = shallowRef(null);
|
|
14
14
|
let unsubscribe = null;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { printDocument } from "../../shared/utils/document.js";
|
|
2
2
|
export function getRemoteExecutor({
|
|
3
3
|
endpoint,
|
|
4
4
|
headers,
|
|
@@ -19,7 +19,7 @@ export function getRemoteExecutor({
|
|
|
19
19
|
...request.extensions?.headers
|
|
20
20
|
},
|
|
21
21
|
body: JSON.stringify({
|
|
22
|
-
query:
|
|
22
|
+
query: printDocument(request.document),
|
|
23
23
|
variables: request.variables,
|
|
24
24
|
operationName: request.operationName
|
|
25
25
|
})
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createContext } from "#graphql/context";
|
|
2
2
|
import { executor, getSchema } from "#graphql/schema";
|
|
3
3
|
import { execute } from "graphql";
|
|
4
|
+
import { parseDocument } from "../../shared/utils/document.js";
|
|
4
5
|
import { normalizeError } from "../../shared/utils/error.js";
|
|
5
6
|
import {
|
|
6
7
|
getOperationDocument,
|
|
@@ -19,7 +20,7 @@ export async function executeSchemaOperation(event, { operationName, variables }
|
|
|
19
20
|
context: contextValue
|
|
20
21
|
}) : await execute({
|
|
21
22
|
schema: getSchema(),
|
|
22
|
-
document,
|
|
23
|
+
document: parseDocument(document),
|
|
23
24
|
variableValues,
|
|
24
25
|
operationName,
|
|
25
26
|
contextValue
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type DocumentNode } from "graphql";
|
|
2
|
+
/**
|
|
3
|
+
* Serialize a GraphQL document to a query string.
|
|
4
|
+
*
|
|
5
|
+
* Accepts both string-form documents (emitted by codegen string mode as
|
|
6
|
+
* `TypedDocumentString`, which extends `String`) and AST `DocumentNode`s.
|
|
7
|
+
*/
|
|
8
|
+
export declare function printDocument(document: unknown): string;
|
|
9
|
+
/**
|
|
10
|
+
* Parse a document into a `DocumentNode` AST, caching by reference.
|
|
11
|
+
*
|
|
12
|
+
* The string-mode codegen emits each operation as a `TypedDocumentString`
|
|
13
|
+
* instance whose identity is stable across calls, so a `WeakMap` keyed on the
|
|
14
|
+
* instance avoids re-parsing on every request. Raw string sources fall back to
|
|
15
|
+
* a `Map` keyed on the SDL text, deduplicating equal queries while keeping the
|
|
16
|
+
* cache bounded by the number of distinct operations.
|
|
17
|
+
*/
|
|
18
|
+
export declare function parseDocument(document: unknown): DocumentNode;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { parse, print } from "graphql";
|
|
2
|
+
export function printDocument(document) {
|
|
3
|
+
if (typeof document === "string" || document instanceof String) {
|
|
4
|
+
return String(document);
|
|
5
|
+
}
|
|
6
|
+
return print(document);
|
|
7
|
+
}
|
|
8
|
+
const astCache = /* @__PURE__ */ new WeakMap();
|
|
9
|
+
const astStringCache = /* @__PURE__ */ new Map();
|
|
10
|
+
export function parseDocument(document) {
|
|
11
|
+
if (typeof document === "string") {
|
|
12
|
+
let ast = astStringCache.get(document);
|
|
13
|
+
if (!ast) {
|
|
14
|
+
ast = parse(document);
|
|
15
|
+
astStringCache.set(document, ast);
|
|
16
|
+
}
|
|
17
|
+
return ast;
|
|
18
|
+
}
|
|
19
|
+
if (document instanceof String || typeof document === "object" && document !== null) {
|
|
20
|
+
const obj = document;
|
|
21
|
+
const cached = astCache.get(obj);
|
|
22
|
+
if (cached) {
|
|
23
|
+
return cached;
|
|
24
|
+
}
|
|
25
|
+
if (document instanceof String) {
|
|
26
|
+
const ast = parse(String(document));
|
|
27
|
+
astCache.set(obj, ast);
|
|
28
|
+
return ast;
|
|
29
|
+
}
|
|
30
|
+
return document;
|
|
31
|
+
}
|
|
32
|
+
throw new TypeError("Cannot parse document: unsupported type");
|
|
33
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { print } from "graphql";
|
|
2
1
|
import { mergeHeaders } from "../lib/headers.js";
|
|
2
|
+
import { printDocument } from "./document.js";
|
|
3
3
|
import { normalizeError } from "./error.js";
|
|
4
4
|
import {
|
|
5
5
|
getOperationDocument,
|
|
@@ -13,7 +13,11 @@ export async function executeHttpOperation({ operationName, variables }, { endpo
|
|
|
13
13
|
const result = await $fetch(endpoint, {
|
|
14
14
|
method: "POST",
|
|
15
15
|
headers: mergeHeaders({ "content-type": "application/json" }, headers),
|
|
16
|
-
body: JSON.stringify({
|
|
16
|
+
body: JSON.stringify({
|
|
17
|
+
query: printDocument(document),
|
|
18
|
+
variables: parsedVariables,
|
|
19
|
+
operationName
|
|
20
|
+
})
|
|
17
21
|
});
|
|
18
22
|
if (result.errors) {
|
|
19
23
|
return { data: null, error: normalizeError(result.errors) };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lewebsimple/nuxt-graphql",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.14",
|
|
4
4
|
"description": "Opinionated Nuxt module for using GraphQL",
|
|
5
5
|
"license": "AGPL-3.0-only",
|
|
6
6
|
"repository": "lewebsimple/nuxt-graphql",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"@graphql-typed-document-node/core": "^3.2.0",
|
|
39
39
|
"@nuxt/kit": "^4.4.6",
|
|
40
40
|
"defu": "^6.1.7",
|
|
41
|
-
"es-toolkit": "^1.
|
|
41
|
+
"es-toolkit": "^1.47.0",
|
|
42
42
|
"graphql-sse": "^2.6.0",
|
|
43
43
|
"graphql-yoga": "^5.21.0",
|
|
44
44
|
"jiti": "^2.7.0",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@graphql-codegen/plugin-helpers": "^7.0.1",
|
|
51
|
-
"@lewebsimple/graphql-codegen-zod": "^0.
|
|
51
|
+
"@lewebsimple/graphql-codegen-zod": "^0.3.0",
|
|
52
52
|
"@nuxt/devtools": "^3.2.4",
|
|
53
53
|
"@nuxt/module-builder": "^1.0.2",
|
|
54
54
|
"@nuxt/schema": "^4.4.6",
|
|
@@ -62,11 +62,11 @@
|
|
|
62
62
|
"oxlint": "^1.66.0",
|
|
63
63
|
"typescript": "^6.0.3",
|
|
64
64
|
"vitest": "^4.1.7",
|
|
65
|
-
"vue-tsc": "^3.3.
|
|
65
|
+
"vue-tsc": "^3.3.2",
|
|
66
66
|
"zod": "^4.4.3"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
-
"@lewebsimple/graphql-codegen-zod": "^0.
|
|
69
|
+
"@lewebsimple/graphql-codegen-zod": "^0.3",
|
|
70
70
|
"graphql": "^16",
|
|
71
71
|
"zod": "^4"
|
|
72
72
|
},
|