@lewebsimple/nuxt-graphql 0.3.4 → 0.4.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/README.md
CHANGED
|
@@ -14,7 +14,7 @@ Opinionated Nuxt module that wires a typed GraphQL server + client into your app
|
|
|
14
14
|
|
|
15
15
|
- 🧘 **GraphQL Yoga** server at `/api/graphql` (**GraphiQL** in dev) + **SSE subscriptions**
|
|
16
16
|
- 🪡 **Stitched schema** from local and/or remote schemas (remote introspection at build time)
|
|
17
|
-
- 🪄 Code generation from `.gql` documents → **typed documents nodes**
|
|
17
|
+
- 🪄 Code generation from `.gql` documents → **typed documents nodes**
|
|
18
18
|
- 🧠 **Type-safe GraphQL helpers** for **queries, mutations, and subscriptions**, driven by **operation names** and shared across **client + server routes**
|
|
19
19
|
- 🧊 **SSR-friendly** by default: request header/cookie forwarding + no-HTTP server execution helpers
|
|
20
20
|
- 🚀 **Query caching** for `useGraphQLQuery` (cache policies + optional persistence in localStorage)
|
|
@@ -164,7 +164,6 @@ By default, the module scans `**/*.gql` and generates:
|
|
|
164
164
|
|
|
165
165
|
- Typed documents in `#graphql/typed-documents`
|
|
166
166
|
- Operation registry by name in `#graphql/registry` (used internally)
|
|
167
|
-
- Zod schemas in `#graphql/zod`
|
|
168
167
|
- A `graphql.config.json` at the project root (editor tooling)
|
|
169
168
|
|
|
170
169
|
Example document files (filenaming convention can vary):
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -66,7 +66,7 @@ function toRelativePath(from, to) {
|
|
|
66
66
|
return relativePath;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
async function runGraphQLCodegen({ schema, documents, typedDocumentsPath
|
|
69
|
+
async function runGraphQLCodegen({ schema, documents, typedDocumentsPath }) {
|
|
70
70
|
const config = {
|
|
71
71
|
schema,
|
|
72
72
|
documents,
|
|
@@ -85,15 +85,6 @@ async function runGraphQLCodegen({ schema, documents, typedDocumentsPath, zodPat
|
|
|
85
85
|
strictScalars: true,
|
|
86
86
|
useTypeImports: true
|
|
87
87
|
}
|
|
88
|
-
},
|
|
89
|
-
// Zod schemas
|
|
90
|
-
[zodPath]: {
|
|
91
|
-
plugins: ["typescript-validation-schema"],
|
|
92
|
-
config: {
|
|
93
|
-
schema: "zodv4",
|
|
94
|
-
importFrom: "#graphql/operations",
|
|
95
|
-
useTypeImports: true
|
|
96
|
-
}
|
|
97
88
|
}
|
|
98
89
|
},
|
|
99
90
|
ignoreNoDocuments: true,
|
|
@@ -386,11 +377,9 @@ const module$1 = defineNuxtModule({
|
|
|
386
377
|
}
|
|
387
378
|
const typedDocumentsPath = join(buildDir, "graphql/typed-documents.ts");
|
|
388
379
|
nuxt.options.alias["#graphql/typed-documents"] = typedDocumentsPath;
|
|
389
|
-
const zodPath = join(buildDir, "graphql/zod.ts");
|
|
390
|
-
nuxt.options.alias["#graphql/zod"] = zodPath;
|
|
391
380
|
async function generateGraphQLCodegen() {
|
|
392
381
|
try {
|
|
393
|
-
const files = await runGraphQLCodegen({ schema: sdlPath, documents, typedDocumentsPath
|
|
382
|
+
const files = await runGraphQLCodegen({ schema: sdlPath, documents, typedDocumentsPath });
|
|
394
383
|
for (const file of files) {
|
|
395
384
|
logger.info(`GraphQL Codegen generated: ${cyan}${toRelativePath(rootDir, file)}${reset}`);
|
|
396
385
|
}
|
|
@@ -441,7 +430,6 @@ const module$1 = defineNuxtModule({
|
|
|
441
430
|
await generateGraphQLArtifacts();
|
|
442
431
|
references.push({ path: registryPath });
|
|
443
432
|
references.push({ path: typedDocumentsPath });
|
|
444
|
-
references.push({ path: zodPath });
|
|
445
433
|
});
|
|
446
434
|
if (nuxt.options.dev) {
|
|
447
435
|
nuxt.hook("builder:watch", async (_event, path) => {
|
|
@@ -4,6 +4,6 @@ import { type QueryName, type QueryResult, type QueryVariables } from "#graphql/
|
|
|
4
4
|
import { type CacheConfig } from "../lib/cache-config.js";
|
|
5
5
|
export interface UseGraphQLQueryOptions<T> extends AsyncDataOptions<T> {
|
|
6
6
|
headers?: HeadersInit;
|
|
7
|
-
cache?: CacheConfig
|
|
7
|
+
cache?: Partial<CacheConfig>;
|
|
8
8
|
}
|
|
9
9
|
export declare function useGraphQLQuery<N extends QueryName>(operationName: N, ...args: IsEmptyObject<QueryVariables<N>> extends true ? [variables?: MaybeRefOrGetter<QueryVariables<N>>, options?: UseGraphQLQueryOptions<QueryResult<N>>] : [variables: MaybeRefOrGetter<QueryVariables<N>>, options?: UseGraphQLQueryOptions<QueryResult<N>>]): ReturnType<typeof useAsyncData<QueryResult<N>>>;
|
|
@@ -3,7 +3,9 @@ import { normalizeGraphQLError } from "../../shared/lib/graphql-error.js";
|
|
|
3
3
|
export function createRemoteExecutor(options) {
|
|
4
4
|
const { url, remoteName, headers = {}, middleware } = options;
|
|
5
5
|
const { onRequest, onResponse, onError } = middleware ?? {};
|
|
6
|
+
let executionDepth = 0;
|
|
6
7
|
return async ({ document, variables, context, operationName }) => {
|
|
8
|
+
executionDepth++;
|
|
7
9
|
const parsedDocument = typeof document === "string" ? parse(document) : document;
|
|
8
10
|
const op = getOperationAST(parsedDocument, operationName);
|
|
9
11
|
const resolvedOperationName = op?.name?.value ?? operationName ?? "anonymous";
|
|
@@ -15,7 +17,7 @@ export function createRemoteExecutor(options) {
|
|
|
15
17
|
headers: requestHeaders,
|
|
16
18
|
body: JSON.stringify({ query, variables, operationName: resolvedOperationName })
|
|
17
19
|
};
|
|
18
|
-
if (onRequest) {
|
|
20
|
+
if (onRequest && executionDepth === 1) {
|
|
19
21
|
await onRequest({
|
|
20
22
|
remoteName,
|
|
21
23
|
operationName: resolvedOperationName,
|
|
@@ -33,7 +35,7 @@ export function createRemoteExecutor(options) {
|
|
|
33
35
|
}
|
|
34
36
|
throw statusError;
|
|
35
37
|
}
|
|
36
|
-
if (onResponse) {
|
|
38
|
+
if (onResponse && executionDepth === 1) {
|
|
37
39
|
await onResponse({ remoteName, operationName: resolvedOperationName, context: graphQLContext, response: safeResponse });
|
|
38
40
|
}
|
|
39
41
|
try {
|
|
@@ -59,6 +61,8 @@ export function createRemoteExecutor(options) {
|
|
|
59
61
|
await onError({ remoteName, operationName: resolvedOperationName, context: graphQLContext, error: normalized });
|
|
60
62
|
}
|
|
61
63
|
throw normalized;
|
|
64
|
+
} finally {
|
|
65
|
+
executionDepth--;
|
|
62
66
|
}
|
|
63
67
|
};
|
|
64
68
|
}
|