@lewebsimple/nuxt-graphql 0.5.9 → 0.5.11

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
@@ -163,9 +163,8 @@ Write operations in `.gql` files; operation names become registry keys like `use
163
163
 
164
164
  By default, the module scans `**/*.gql` and generates:
165
165
 
166
- - Typed documents and types in virtual modules under the `#graphql/operations` alias (internal)
166
+ - Typed documents and operations / fragments types in virtual modules under the `#graphql/operations` alias (internal)
167
167
  - Operation registry in virtual modules under the `#graphql/registry` alias (internal)
168
- - Fragment types in virtual modules under the `#graphql/fragments` alias
169
168
 
170
169
  Example document files:
171
170
 
@@ -198,7 +197,7 @@ That's it! You can now use Nuxt GraphQL in your Nuxt app ✨
198
197
  Fragments are fully supported and are the recommended way to share selection sets across operations.
199
198
 
200
199
  - Fragment names must be unique across all `.gql` files (duplicates throw during generation).
201
- - Fragment types are re-exported from `#graphql/fragments`.
200
+ - Fragment types are re-exported from `#graphql/operations`.
202
201
  - Fragments are not executable by themselves and are not part of the registry.
203
202
 
204
203
  Example with a fragment:
@@ -222,7 +221,7 @@ query SwapiFilms {
222
221
  From TypeScript, you can also use fragment types explicitly when needed:
223
222
 
224
223
  ```ts
225
- import type { TheFilmFragment } from "#graphql/fragments";
224
+ import type { TheFilmFragment } from "#graphql/operations";
226
225
  ```
227
226
 
228
227
 
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-graphql",
3
3
  "configKey": "graphql",
4
- "version": "0.5.9",
4
+ "version": "0.5.11",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -97,7 +97,7 @@ async function renderOperationsTemplate({ schema, documents }) {
97
97
  const module = docs.map(({ name, object }) => `export const ${name} = ${object};`).join("\n");
98
98
  const types = `${content.replace(/export const \w+ = [\s\S]*?;\n?/g, "")}
99
99
  declare module "#graphql/operations" {
100
- ${docs.map(({ name, type }) => `export type ${name} = ${type};`).join("\n ")}
100
+ ${docs.map(({ name, type }) => `export const ${name}: ${type};`).join("\n ")}
101
101
  }`.trim();
102
102
  return { module, types };
103
103
  }
@@ -305,7 +305,6 @@ export {};
305
305
  function renderSharedTypesTemplate() {
306
306
  return `
307
307
  import type { DocumentNode } from "graphql";
308
- import type { CacheConfig } from "nuxt-graphql/runtime/shared/lib/cache-config";
309
308
 
310
309
  declare global {
311
310
  type GraphQLCacheConfig = {
@@ -326,7 +325,6 @@ declare module "nuxt/schema" {
326
325
  }
327
326
 
328
327
  export { };
329
-
330
328
  `.trim();
331
329
  }
332
330
 
@@ -360,7 +358,7 @@ const module$1 = defineNuxtModule({
360
358
  return relativePath;
361
359
  }
362
360
  nuxt.options.alias ||= {};
363
- nuxt.options.alias["#graphql"] ||= resolveBuild("graphql");
361
+ nuxt.options.alias["#graphql"] = resolveBuild("graphql");
364
362
  const buildCache = /* @__PURE__ */ new Map();
365
363
  function cachedLoader(baseKey, loader) {
366
364
  return async (...args) => {
@@ -405,10 +403,12 @@ const module$1 = defineNuxtModule({
405
403
  const schema = stitchSchemas({
406
404
  subschemas: await Promise.all(Object.values(schemaCachedLoaders).map((loader) => loader()))
407
405
  });
408
- const sdl = await printSchemaSDL(schema);
409
- mkdirSync(dirname(sdlPath), { recursive: true });
410
- writeFileSync(sdlPath, sdl, { encoding: "utf-8" });
411
- logger.info(`GraphQL SDL saved to: ${cyan}${getRelativePath(sdlPath)}${reset}`);
406
+ if (nuxt.options.dev) {
407
+ const sdl = await printSchemaSDL(schema);
408
+ mkdirSync(dirname(sdlPath), { recursive: true });
409
+ writeFileSync(sdlPath, sdl, { encoding: "utf-8" });
410
+ logger.info(`GraphQL SDL saved to: ${cyan}${getRelativePath(sdlPath)}${reset}`);
411
+ }
412
412
  return schema;
413
413
  });
414
414
  addTemplate({ filename: "graphql/schema.mjs", getContents: () => renderSchemaTemplate({ schemaNames: Object.keys(options.yoga?.schemas || {}) }), write: true });
@@ -424,7 +424,9 @@ const module$1 = defineNuxtModule({
424
424
  "!**/dist/**",
425
425
  "!**/node_modules/**"
426
426
  ], { loaders: [new GraphQLFileLoader()] });
427
- } catch {
427
+ } catch (error) {
428
+ const message = error instanceof Error ? error.message : String(error);
429
+ logger.warn(`Failed to load documents: ${message}`);
428
430
  return [];
429
431
  }
430
432
  });
@@ -470,8 +472,11 @@ const module$1 = defineNuxtModule({
470
472
  nuxt.hook("builder:watch", async (_event, changedPath) => {
471
473
  if (changedPath.endsWith(".gql")) {
472
474
  logger.info(`Documents change detected: ${cyan}${getRelativePath(changedPath)}${reset}`);
473
- buildCache.delete("documents");
474
- buildCache.delete("operations");
475
+ for (const key of buildCache.keys()) {
476
+ if (key.startsWith("documents:") || key.startsWith("operations:") || key.startsWith("registry:")) {
477
+ buildCache.delete(key);
478
+ }
479
+ }
475
480
  }
476
481
  });
477
482
  }
@@ -10,8 +10,7 @@ type UseAsyncGraphQLQueryOptions<TName extends QueryName> = ExecuteGraphQLHTTPOp
10
10
  * Async GraphQL query composable with caching support.
11
11
  *
12
12
  * @param operationName Operation name from the registry.
13
- * @param variables Operation variables (ref or getter).
14
- * @param options HTTP and cache options.
13
+ * @param args Operation variables (if any) and optional HTTP headers.
15
14
  * @returns Nuxt AsyncData wrapper for the query result.
16
15
  */
17
16
  export declare function useAsyncGraphQLQuery<TName extends QueryName>(operationName: TName, ...args: IsEmptyObject<VariablesOf<TName>> extends true ? [variables?: MaybeRefOrGetter<VariablesOf<TName>>, options?: UseAsyncGraphQLQueryOptions<TName>] : [variables: MaybeRefOrGetter<VariablesOf<TName>>, options?: UseAsyncGraphQLQueryOptions<TName>]): ReturnType<typeof useAsyncData<ResultOf<TName>>>;
@@ -6,6 +6,7 @@ import type { IsEmptyObject } from "../../shared/lib/utils.js";
6
6
  * Execute a GraphQL query over HTTP with in-flight deduplication.
7
7
  *
8
8
  * @param operationName Operation name from the registry.
9
+ * @param args Operation variables (if any) and optional HTTP headers.
9
10
  * @returns SafeResult containing data or a normalized error.
10
11
  */
11
12
  export declare function useGraphQLQuery<TName extends QueryName>(operationName: TName, ...args: IsEmptyObject<VariablesOf<TName>> extends true ? [variables?: VariablesOf<TName>, options?: ExecuteGraphQLHTTPOptions] : [variables: VariablesOf<TName>, options?: ExecuteGraphQLHTTPOptions]): Promise<SafeResult<ResultOf<TName>>>;
@@ -12,7 +12,7 @@ type UseGraphQLSubscriptionReturn<TName extends SubscriptionName> = {
12
12
  * GraphQL subscription composable (client-side only).
13
13
  *
14
14
  * @param operationName Subscription operation name.
15
- * @param variables Subscription variables.
15
+ * @param args Operation variables (if any).
16
16
  * @returns Object with reactive data, error, and start/stop helpers.
17
17
  */
18
18
  export declare function useGraphQLSubscription<TName extends SubscriptionName>(operationName: TName, ...args: IsEmptyObject<VariablesOf<TName>> extends true ? [variables?: VariablesOf<TName>] : [variables: VariablesOf<TName>]): UseGraphQLSubscriptionReturn<TName>;
@@ -11,7 +11,7 @@ import type { IsEmptyObject } from "../../shared/lib/utils.js";
11
11
  *
12
12
  * @param event H3 event used to create context.
13
13
  * @param operationName Operation name from the registry.
14
- * @param variables Operation variables.
14
+ * @param args Operation variables (if any).
15
15
  * @returns SafeResult containing data or a normalized error.
16
16
  */
17
17
  export declare function useServerGraphQLMutation<TName extends MutationName>(event: H3Event, operationName: TName, ...args: IsEmptyObject<VariablesOf<TName>> extends true ? [variables?: VariablesOf<TName>] : [variables: VariablesOf<TName>]): Promise<SafeResult<ResultOf<TName>>>;
@@ -1,8 +1,8 @@
1
1
  import { executeGraphQLSchema } from "../lib/execute-schema.js";
2
2
  import { normalizeError } from "../../shared/lib/error.js";
3
3
  export async function useServerGraphQLMutation(event, operationName, ...args) {
4
+ const [variables] = args;
4
5
  try {
5
- const [variables] = args;
6
6
  const data = await executeGraphQLSchema(event, operationName, variables);
7
7
  return { data, error: null };
8
8
  } catch (err) {
@@ -11,7 +11,7 @@ import type { IsEmptyObject } from "../../shared/lib/utils.js";
11
11
  *
12
12
  * @param event H3 event used to create context.
13
13
  * @param operationName Operation name from the registry.
14
- * @param variables Operation variables.
14
+ * @param args Operation variables (if any).
15
15
  * @returns SafeResult containing data or a normalized error.
16
16
  */
17
17
  export declare function useServerGraphQLQuery<TName extends QueryName>(event: H3Event, operationName: TName, ...args: IsEmptyObject<VariablesOf<TName>> extends true ? [variables?: VariablesOf<TName>] : [variables: VariablesOf<TName>]): Promise<SafeResult<ResultOf<TName>>>;
@@ -3,11 +3,7 @@ import { normalizeError } from "../../shared/lib/error.js";
3
3
  export async function useServerGraphQLQuery(event, operationName, ...args) {
4
4
  const [variables] = args;
5
5
  try {
6
- const data = await executeGraphQLSchema(
7
- event,
8
- operationName,
9
- variables
10
- );
6
+ const data = await executeGraphQLSchema(event, operationName, variables);
11
7
  return { data, error: null };
12
8
  } catch (err) {
13
9
  return {
@@ -1 +1 @@
1
- export type IsEmptyObject<T> = T extends Record<string, never> ? true : keyof T extends never ? true : false;
1
+ export type IsEmptyObject<T> = [T] extends [never] ? true : T extends object ? keyof T extends never ? true : false : false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lewebsimple/nuxt-graphql",
3
- "version": "0.5.9",
3
+ "version": "0.5.11",
4
4
  "description": "Opinionated Nuxt module for using GraphQL",
5
5
  "repository": "lewebsimple/nuxt-graphql",
6
6
  "license": "AGPL-3.0-only",