@lewebsimple/nuxt-graphql 0.7.0 → 0.7.2
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 +12 -3
- package/dist/module.json +1 -1
- package/dist/module.mjs +16 -7
- package/package.json +7 -6
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
package/dist/module.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { mkdir, writeFile } from 'node:fs/promises';
|
|
2
2
|
import { relative, resolve, parse, dirname } from 'node:path';
|
|
3
3
|
import { stitchSchemas } from '@graphql-tools/stitch';
|
|
4
|
+
import { extendSchemaWithZodDirectives } from '@lewebsimple/graphql-codegen-zod/extend-schema';
|
|
4
5
|
import { createResolver, addTemplate, addTypeTemplate, defineNuxtModule, useLogger, addServerImports, updateTemplates, addServerHandler, addPlugin, addImportsDir, addServerImportsDir } from '@nuxt/kit';
|
|
5
6
|
import { defu } from 'defu';
|
|
6
7
|
import { parse as parse$1, printSchema, lexicographicSortSchema, getIntrospectionQuery, buildClientSchema, GraphQLSchema, buildSchema } from 'graphql';
|
|
@@ -15,7 +16,7 @@ import zodPreset from '@lewebsimple/graphql-codegen-zod';
|
|
|
15
16
|
import { createRequire } from 'node:module';
|
|
16
17
|
import { resolveCacheConfig } from '../dist/runtime/app/lib/cache-config.js';
|
|
17
18
|
|
|
18
|
-
const version = "0.7.
|
|
19
|
+
const version = "0.7.2";
|
|
19
20
|
|
|
20
21
|
const buildCache = /* @__PURE__ */ new Map();
|
|
21
22
|
function getCachedLoader(baseKey, loader) {
|
|
@@ -291,7 +292,7 @@ async function resolveSchemaDefs(schemaDefs, nuxt) {
|
|
|
291
292
|
})
|
|
292
293
|
);
|
|
293
294
|
}
|
|
294
|
-
function
|
|
295
|
+
function getRemoteSchemaTemplate({
|
|
295
296
|
endpoint,
|
|
296
297
|
headers,
|
|
297
298
|
hooks,
|
|
@@ -318,8 +319,9 @@ export const schema = {
|
|
|
318
319
|
};
|
|
319
320
|
`.trim();
|
|
320
321
|
}
|
|
321
|
-
function
|
|
322
|
+
function getSchemaTemplate({ localPaths, remotePaths }) {
|
|
322
323
|
const imports = [
|
|
324
|
+
`import { extendSchemaWithZodDirectives } from "@lewebsimple/graphql-codegen-zod/extend-schema";`,
|
|
323
325
|
...localPaths.map(
|
|
324
326
|
(schemaPath, index) => `import { schema as localSchema${index} } from ${JSON.stringify(schemaPath)};`
|
|
325
327
|
),
|
|
@@ -341,13 +343,19 @@ function getSchemaServerTemplate({ localPaths, remotePaths }) {
|
|
|
341
343
|
if (schemaRefs.length === 0) {
|
|
342
344
|
imports.unshift(`import { buildSchema } from "graphql";`);
|
|
343
345
|
schemaRef = `buildSchema("type Query { _empty: String }")`;
|
|
344
|
-
} else if (
|
|
346
|
+
} else if (remoteSchemaRefs.length === 0) {
|
|
345
347
|
schemaRef = schemaRefs[0];
|
|
346
348
|
} else {
|
|
347
349
|
imports.unshift(`import { stitchSchemas } from "@graphql-tools/stitch";`);
|
|
348
350
|
schemaRef = `stitchSchemas({ subschemas: [${schemaRefs.join(", ")}] })`;
|
|
349
351
|
}
|
|
350
|
-
return [
|
|
352
|
+
return [
|
|
353
|
+
...imports,
|
|
354
|
+
"",
|
|
355
|
+
`export const schema = extendSchemaWithZodDirectives(`,
|
|
356
|
+
` ${schemaRef},`,
|
|
357
|
+
`);`
|
|
358
|
+
].join("\n");
|
|
351
359
|
}
|
|
352
360
|
async function loadLocalSchema(path, nuxt) {
|
|
353
361
|
const { createJiti } = await import('jiti');
|
|
@@ -458,7 +466,7 @@ const module$1 = defineNuxtModule({
|
|
|
458
466
|
await addCompiledTemplate(
|
|
459
467
|
{
|
|
460
468
|
filename: `graphql/schemas/remote-${index}`,
|
|
461
|
-
getContents: async () =>
|
|
469
|
+
getContents: async () => getRemoteSchemaTemplate({
|
|
462
470
|
...schemaDef,
|
|
463
471
|
sdl: getSchemaSDL(await schemaLoader())
|
|
464
472
|
})
|
|
@@ -473,7 +481,7 @@ const module$1 = defineNuxtModule({
|
|
|
473
481
|
const { dst: schemaDst } = await addCompiledTemplate(
|
|
474
482
|
{
|
|
475
483
|
filename: "graphql/schema",
|
|
476
|
-
getContents: () =>
|
|
484
|
+
getContents: () => getSchemaTemplate(schemaInput)
|
|
477
485
|
},
|
|
478
486
|
nuxt
|
|
479
487
|
);
|
|
@@ -494,6 +502,7 @@ const module$1 = defineNuxtModule({
|
|
|
494
502
|
throw new Error("Failed to load GraphQL schema");
|
|
495
503
|
}
|
|
496
504
|
}
|
|
505
|
+
schema = extendSchemaWithZodDirectives(schema);
|
|
497
506
|
if (nuxt.options.dev) {
|
|
498
507
|
const sdl = getSchemaSDL(schema);
|
|
499
508
|
await writeFile(sdlPath, sdl);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lewebsimple/nuxt-graphql",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2",
|
|
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.
|
|
37
|
+
"@graphql-tools/stitch": "^10.1.16",
|
|
38
38
|
"@graphql-typed-document-node/core": "^3.2.0",
|
|
39
|
-
"@lewebsimple/graphql-codegen-zod": "^0.
|
|
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.
|
|
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.
|
|
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": {
|