@lewebsimple/nuxt-graphql 0.7.2 → 0.7.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-graphql",
3
3
  "configKey": "graphql",
4
- "version": "0.7.2",
4
+ "version": "0.7.4",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "unknown"
package/dist/module.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { mkdir, writeFile } from 'node:fs/promises';
2
- import { relative, resolve, parse, dirname } from 'node:path';
2
+ import { relative, resolve, parse, extname, dirname } from 'node:path';
3
3
  import { stitchSchemas } from '@graphql-tools/stitch';
4
4
  import { extendSchemaWithZodDirectives } from '@lewebsimple/graphql-codegen-zod/extend-schema';
5
5
  import { createResolver, addTemplate, addTypeTemplate, defineNuxtModule, useLogger, addServerImports, updateTemplates, addServerHandler, addPlugin, addImportsDir, addServerImportsDir } from '@nuxt/kit';
@@ -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.2";
19
+ const version = "0.7.4";
20
20
 
21
21
  const buildCache = /* @__PURE__ */ new Map();
22
22
  function getCachedLoader(baseKey, loader) {
@@ -94,6 +94,9 @@ function getContextTemplate({ paths }) {
94
94
  ].join("\n");
95
95
  }
96
96
 
97
+ const DOCUMENT_IGNORE_GLOBS = ["**/.nuxt/**", "**/.output/**", "**/dist/**", "**/node_modules/**"];
98
+ const GRAPHQL_FILE_EXTENSIONS = /* @__PURE__ */ new Set([".gql", ".graphql"]);
99
+ const CODE_FILE_EXTENSIONS = /* @__PURE__ */ new Set([".ts", ".mts", ".cts", ".js", ".mjs", ".cjs", ".vue"]);
97
100
  async function resolveDocumentGlobs(globs, nuxt) {
98
101
  const { resolvePath } = createResolver(nuxt.options.rootDir);
99
102
  return Promise.all(
@@ -107,7 +110,8 @@ async function loadDocuments(globs) {
107
110
  try {
108
111
  const docs = await loadDocuments$1(globs, {
109
112
  loaders: [new GraphQLFileLoader(), new CodeFileLoader()],
110
- ignore: ["**/.nuxt/**", "**/.output/**", "**/dist/**", "**/node_modules/**"]
113
+ ignore: DOCUMENT_IGNORE_GLOBS,
114
+ noRequire: true
111
115
  });
112
116
  const seen = /* @__PURE__ */ new Set();
113
117
  return docs.filter((doc) => {
@@ -123,6 +127,26 @@ async function loadDocuments(globs) {
123
127
  throw error;
124
128
  }
125
129
  }
130
+ async function isGraphQLDocumentChange(path, event) {
131
+ const extension = extname(path).toLowerCase();
132
+ if (GRAPHQL_FILE_EXTENSIONS.has(extension)) {
133
+ return true;
134
+ }
135
+ if (!CODE_FILE_EXTENSIONS.has(extension)) {
136
+ return false;
137
+ }
138
+ if (event === "unlink" || event === "unlinkDir") {
139
+ return true;
140
+ }
141
+ try {
142
+ const docs = await new CodeFileLoader().load(path, {
143
+ noRequire: true
144
+ });
145
+ return docs.some((doc) => Boolean(doc.document));
146
+ } catch {
147
+ return true;
148
+ }
149
+ }
126
150
 
127
151
  const require$1 = createRequire(import.meta.url);
128
152
  function compileTsModule(ts) {
@@ -176,7 +200,11 @@ async function generateRegistryArtifacts({
176
200
  baseOutputDir: "registry.ts",
177
201
  schema: parse$1(printSchema(schema)),
178
202
  documents,
179
- config: {},
203
+ config: {
204
+ scalars: {
205
+ ZodValue: "unknown"
206
+ }
207
+ },
180
208
  pluginMap: {},
181
209
  plugins: [],
182
210
  presetConfig: {}
@@ -321,7 +349,6 @@ export const schema = {
321
349
  }
322
350
  function getSchemaTemplate({ localPaths, remotePaths }) {
323
351
  const imports = [
324
- `import { extendSchemaWithZodDirectives } from "@lewebsimple/graphql-codegen-zod/extend-schema";`,
325
352
  ...localPaths.map(
326
353
  (schemaPath, index) => `import { schema as localSchema${index} } from ${JSON.stringify(schemaPath)};`
327
354
  ),
@@ -352,9 +379,7 @@ function getSchemaTemplate({ localPaths, remotePaths }) {
352
379
  return [
353
380
  ...imports,
354
381
  "",
355
- `export const schema = extendSchemaWithZodDirectives(`,
356
- ` ${schemaRef},`,
357
- `);`
382
+ `export const schema = ${schemaRef};`
358
383
  ].join("\n");
359
384
  }
360
385
  async function loadLocalSchema(path, nuxt) {
@@ -534,14 +559,14 @@ const module$1 = defineNuxtModule({
534
559
  if (nuxt.options.dev) {
535
560
  const schemaWatchPaths = schemaDefs.filter((schemaDef) => schemaDef.type === "local").map((schemaDef) => schemaDef.path);
536
561
  const isDocument = picomatch(documentGlobs);
537
- nuxt.hook("builder:watch", async (_event, path) => {
562
+ nuxt.hook("builder:watch", async (event, path) => {
538
563
  if (schemaWatchPaths.some((schemaPath) => path.includes(schemaPath))) {
539
564
  logger.info(`Local schema change detected: ${path}`);
540
565
  clearBuildCache(["graphql:schema", "graphql:registry"]);
541
566
  await syncRegistryTemplates();
542
567
  await updateTemplates({ filter: (template) => template.filename.startsWith("graphql/") });
543
568
  }
544
- if (isDocument(path)) {
569
+ if (isDocument(path) && await isGraphQLDocumentChange(path, event)) {
545
570
  logger.info(`Document change detected: ${path}`);
546
571
  clearBuildCache(["graphql:documents", "graphql:registry"]);
547
572
  await syncRegistryTemplates();
@@ -553,7 +578,16 @@ const module$1 = defineNuxtModule({
553
578
  const configPath = resolveRoot(options.saveConfig || "graphql.config.json");
554
579
  const config = {
555
580
  schema: toRelativePath(rootDir, sdlPath),
556
- documents: documentGlobs.map((glob) => toRelativePath(rootDir, glob))
581
+ documents: documentGlobs.map((glob) => toRelativePath(rootDir, glob)),
582
+ extensions: {
583
+ codegen: {
584
+ config: {
585
+ scalars: {
586
+ ZodValue: "unknown"
587
+ }
588
+ }
589
+ }
590
+ }
557
591
  };
558
592
  await writeFile(configPath, JSON.stringify(config, null, 2));
559
593
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lewebsimple/nuxt-graphql",
3
- "version": "0.7.2",
3
+ "version": "0.7.4",
4
4
  "description": "Opinionated Nuxt module for using GraphQL",
5
5
  "license": "AGPL-3.0-only",
6
6
  "repository": "lewebsimple/nuxt-graphql",