@lewebsimple/nuxt-graphql 0.7.0 → 0.7.1

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
@@ -188,7 +188,6 @@ That's it! You can now use Nuxt GraphQL in your Nuxt app ✨
188
188
  Fragments are fully supported and are the recommended way to share selection sets across operations.
189
189
 
190
190
  - Fragment names must be unique across all `.gql` files (duplicates throw during generation).
191
- - Fragment types are re-exported from `#graphql/types`.
192
191
  - Fragments are not executable by themselves and are not part of the registry.
193
192
 
194
193
  Example with a fragment:
@@ -209,12 +208,14 @@ query SwapiFilms {
209
208
  }
210
209
  ```
211
210
 
212
- From TypeScript, you can also use fragment types explicitly when needed:
211
+ From TypeScript, you can also use fragment types explicitly when needed (see below):
213
212
 
214
213
  ```ts
215
- import type { TheFilmFragment } from "#graphql/types";
214
+ import type { TheFilmFragment, SwapiFilmsVariables } from "#graphql/types";
216
215
  ```
217
216
 
217
+ ⚠️ These types are inferred from the Zod schemas and cannot be used as top-level in component props, i.e. `defineProps<TheFilmFragment>()` breaks but `defineProps<{ film: TheFilmFragment }>()` works just fine.
218
+
218
219
  ### Use the auto-imported composables
219
220
 
220
221
  The auto-imported composables allow executing queries, mutations, and subscriptions based on their registry name with full type-safety (variables and return value).
@@ -249,6 +250,14 @@ export default defineEventHandler(async (event) => {
249
250
 
250
251
  Server helpers return a `ExecuteGraphQLResult` in the same format as some composables, i.e. `{ data: TResult, error: null } | { data: null, error: NormalizedError }`
251
252
 
253
+ ### Type-safety
254
+
255
+ All enum, fragment and operation variables & result types are re-exported from `#graphql/types` for your convenience:
256
+
257
+ ```ts
258
+ import type { TheFilmFragment } from "#graphql/types";
259
+ ```
260
+
252
261
  ### Query caching (client-side only)
253
262
 
254
263
  `useAsyncGraphQLQuery` can cache query results based on the global cache configuration and per-query overrides.
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-graphql",
3
3
  "configKey": "graphql",
4
- "version": "0.7.0",
4
+ "version": "0.7.1",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "unknown"
package/dist/module.mjs CHANGED
@@ -15,7 +15,7 @@ import zodPreset from '@lewebsimple/graphql-codegen-zod';
15
15
  import { createRequire } from 'node:module';
16
16
  import { resolveCacheConfig } from '../dist/runtime/app/lib/cache-config.js';
17
17
 
18
- const version = "0.7.0";
18
+ const version = "0.7.1";
19
19
 
20
20
  const buildCache = /* @__PURE__ */ new Map();
21
21
  function getCachedLoader(baseKey, loader) {
@@ -291,7 +291,7 @@ async function resolveSchemaDefs(schemaDefs, nuxt) {
291
291
  })
292
292
  );
293
293
  }
294
- function getRemoteSchemaServerTemplate({
294
+ function getRemoteSchemaTemplate({
295
295
  endpoint,
296
296
  headers,
297
297
  hooks,
@@ -318,8 +318,9 @@ export const schema = {
318
318
  };
319
319
  `.trim();
320
320
  }
321
- function getSchemaServerTemplate({ localPaths, remotePaths }) {
321
+ function getSchemaTemplate({ localPaths, remotePaths }) {
322
322
  const imports = [
323
+ `import { extendSchemaWithZodDirectives } from "@lewebsimple/graphql-codegen-zod/extend-schema";`,
323
324
  ...localPaths.map(
324
325
  (schemaPath, index) => `import { schema as localSchema${index} } from ${JSON.stringify(schemaPath)};`
325
326
  ),
@@ -341,13 +342,19 @@ function getSchemaServerTemplate({ localPaths, remotePaths }) {
341
342
  if (schemaRefs.length === 0) {
342
343
  imports.unshift(`import { buildSchema } from "graphql";`);
343
344
  schemaRef = `buildSchema("type Query { _empty: String }")`;
344
- } else if (schemaRefs.length === 1) {
345
+ } else if (remoteSchemaRefs.length === 0) {
345
346
  schemaRef = schemaRefs[0];
346
347
  } else {
347
348
  imports.unshift(`import { stitchSchemas } from "@graphql-tools/stitch";`);
348
349
  schemaRef = `stitchSchemas({ subschemas: [${schemaRefs.join(", ")}] })`;
349
350
  }
350
- return [...imports, "", `export const schema = ${schemaRef};`].join("\n");
351
+ return [
352
+ ...imports,
353
+ "",
354
+ `export const schema = extendSchemaWithZodDirectives(`,
355
+ ` ${schemaRef},`,
356
+ `);`
357
+ ].join("\n");
351
358
  }
352
359
  async function loadLocalSchema(path, nuxt) {
353
360
  const { createJiti } = await import('jiti');
@@ -458,7 +465,7 @@ const module$1 = defineNuxtModule({
458
465
  await addCompiledTemplate(
459
466
  {
460
467
  filename: `graphql/schemas/remote-${index}`,
461
- getContents: async () => getRemoteSchemaServerTemplate({
468
+ getContents: async () => getRemoteSchemaTemplate({
462
469
  ...schemaDef,
463
470
  sdl: getSchemaSDL(await schemaLoader())
464
471
  })
@@ -473,7 +480,7 @@ const module$1 = defineNuxtModule({
473
480
  const { dst: schemaDst } = await addCompiledTemplate(
474
481
  {
475
482
  filename: "graphql/schema",
476
- getContents: () => getSchemaServerTemplate(schemaInput)
483
+ getContents: () => getSchemaTemplate(schemaInput)
477
484
  },
478
485
  nuxt
479
486
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lewebsimple/nuxt-graphql",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "description": "Opinionated Nuxt module for using GraphQL",
5
5
  "license": "AGPL-3.0-only",
6
6
  "repository": "lewebsimple/nuxt-graphql",
@@ -34,13 +34,12 @@
34
34
  "@graphql-tools/graphql-file-loader": "^8.1.12",
35
35
  "@graphql-tools/load": "^8.1.8",
36
36
  "@graphql-tools/schema": "^10.0.31",
37
- "@graphql-tools/stitch": "^10.1.15",
37
+ "@graphql-tools/stitch": "^10.1.16",
38
38
  "@graphql-typed-document-node/core": "^3.2.0",
39
- "@lewebsimple/graphql-codegen-zod": "^0.1.6",
39
+ "@lewebsimple/graphql-codegen-zod": "^0.2.0",
40
40
  "@nuxt/kit": "^4.4.2",
41
41
  "defu": "^6.1.4",
42
42
  "es-toolkit": "^1.45.1",
43
- "graphql": "^16.13.1",
44
43
  "graphql-sse": "^2.6.0",
45
44
  "graphql-yoga": "^5.18.1",
46
45
  "jiti": "^2.6.1",
@@ -50,22 +49,24 @@
50
49
  },
51
50
  "devDependencies": {
52
51
  "@graphql-codegen/plugin-helpers": "^6.2.0",
53
- "@nuxt/devtools": "^3.2.3",
52
+ "@nuxt/devtools": "^3.2.4",
54
53
  "@nuxt/module-builder": "^1.0.2",
55
54
  "@nuxt/schema": "^4.4.2",
56
55
  "@nuxt/test-utils": "^4.0.0",
57
56
  "@types/node": "latest",
58
57
  "@types/picomatch": "^4.0.2",
59
58
  "changelogen": "^0.6.2",
59
+ "graphql": "^16.13.1",
60
60
  "nuxt": "^4.4.2",
61
61
  "oxfmt": "^0.41.0",
62
62
  "oxlint": "^1.56.0",
63
63
  "typescript": "~5.9.3",
64
64
  "vitest": "^4.1.0",
65
- "vue-tsc": "^3.2.5",
65
+ "vue-tsc": "^3.2.6",
66
66
  "zod": "^4.3.6"
67
67
  },
68
68
  "peerDependencies": {
69
+ "graphql": "^16",
69
70
  "zod": "^4"
70
71
  },
71
72
  "scripts": {