@lewebsimple/nuxt-graphql 0.7.3 → 0.7.5

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.3",
4
+ "version": "0.7.5",
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.3";
19
+ const version = "0.7.5";
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) {
@@ -325,7 +349,6 @@ export const schema = {
325
349
  }
326
350
  function getSchemaTemplate({ localPaths, remotePaths }) {
327
351
  const imports = [
328
- `import { extendSchemaWithZodDirectives } from "@lewebsimple/graphql-codegen-zod/extend-schema";`,
329
352
  ...localPaths.map(
330
353
  (schemaPath, index) => `import { schema as localSchema${index} } from ${JSON.stringify(schemaPath)};`
331
354
  ),
@@ -356,9 +379,7 @@ function getSchemaTemplate({ localPaths, remotePaths }) {
356
379
  return [
357
380
  ...imports,
358
381
  "",
359
- `export const schema = extendSchemaWithZodDirectives(`,
360
- ` ${schemaRef},`,
361
- `);`
382
+ `export const schema = ${schemaRef};`
362
383
  ].join("\n");
363
384
  }
364
385
  async function loadLocalSchema(path, nuxt) {
@@ -538,14 +559,14 @@ const module$1 = defineNuxtModule({
538
559
  if (nuxt.options.dev) {
539
560
  const schemaWatchPaths = schemaDefs.filter((schemaDef) => schemaDef.type === "local").map((schemaDef) => schemaDef.path);
540
561
  const isDocument = picomatch(documentGlobs);
541
- nuxt.hook("builder:watch", async (_event, path) => {
562
+ nuxt.hook("builder:watch", async (event, path) => {
542
563
  if (schemaWatchPaths.some((schemaPath) => path.includes(schemaPath))) {
543
564
  logger.info(`Local schema change detected: ${path}`);
544
565
  clearBuildCache(["graphql:schema", "graphql:registry"]);
545
566
  await syncRegistryTemplates();
546
567
  await updateTemplates({ filter: (template) => template.filename.startsWith("graphql/") });
547
568
  }
548
- if (isDocument(path)) {
569
+ if (isDocument(path) && await isGraphQLDocumentChange(path, event)) {
549
570
  logger.info(`Document change detected: ${path}`);
550
571
  clearBuildCache(["graphql:documents", "graphql:registry"]);
551
572
  await syncRegistryTemplates();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lewebsimple/nuxt-graphql",
3
- "version": "0.7.3",
3
+ "version": "0.7.5",
4
4
  "description": "Opinionated Nuxt module for using GraphQL",
5
5
  "license": "AGPL-3.0-only",
6
6
  "repository": "lewebsimple/nuxt-graphql",
@@ -36,7 +36,7 @@
36
36
  "@graphql-tools/schema": "^10.0.31",
37
37
  "@graphql-tools/stitch": "^10.1.16",
38
38
  "@graphql-typed-document-node/core": "^3.2.0",
39
- "@lewebsimple/graphql-codegen-zod": "^0.2.0",
39
+ "@lewebsimple/graphql-codegen-zod": "^0.2.1",
40
40
  "@nuxt/kit": "^4.4.2",
41
41
  "defu": "^6.1.4",
42
42
  "es-toolkit": "^1.45.1",