nitro-graphql 2.0.0-beta.42 → 2.0.0-beta.43

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.
@@ -1,4 +1,4 @@
1
- import { writeFile } from "../utils/file-io.mjs";
1
+ import { writeFileIfChanged } from "../utils/file-io.mjs";
2
2
  import { resolve } from "pathe";
3
3
  import { printSchemaWithDirectives } from "@graphql-tools/utils";
4
4
  import { GraphQLFileLoader } from "@graphql-tools/graphql-file-loader";
@@ -116,7 +116,7 @@ async function downloadAndSaveSchema(service, buildDir) {
116
116
  ...Object.keys(headers).length > 0 && { headers }
117
117
  });
118
118
  else schema = loadSchemaSync(schemas, { loaders: [new GraphQLFileLoader()] });
119
- writeFile(schemaFilePath, printSchemaWithDirectives(schema));
119
+ writeFileIfChanged(schemaFilePath, printSchemaWithDirectives(schema));
120
120
  }
121
121
  return schemaFilePath;
122
122
  } catch {
@@ -207,7 +207,7 @@ async function generateDirectiveSchemas(nitro, directives) {
207
207
  const schemaContent = allParsedDirectives.map((d) => generateDirectiveSchema(d)).join("\n\n");
208
208
  const directivesPath = path.join(nitro.graphql.buildDir, "_directives.graphql");
209
209
  fs.mkdirSync(path.dirname(directivesPath), { recursive: true });
210
- fs.writeFileSync(directivesPath, schemaContent, "utf-8");
210
+ if ((fs.existsSync(directivesPath) ? fs.readFileSync(directivesPath, "utf-8") : null) !== schemaContent) fs.writeFileSync(directivesPath, schemaContent, "utf-8");
211
211
  return directivesPath;
212
212
  }
213
213
 
@@ -1,6 +1,6 @@
1
- import * as nitro_deps_h31 from "nitro/deps/h3";
1
+ import * as nitro_deps_h30 from "nitro/deps/h3";
2
2
 
3
3
  //#region src/nitro/routes/apollo-server.d.ts
4
- declare const _default: nitro_deps_h31.EventHandlerWithFetch<nitro_deps_h31.EventHandlerRequest, Promise<any>>;
4
+ declare const _default: nitro_deps_h30.EventHandlerWithFetch<nitro_deps_h30.EventHandlerRequest, Promise<any>>;
5
5
  //#endregion
6
6
  export { _default as default };
@@ -1,4 +1,4 @@
1
- import * as nitro_deps_h30 from "nitro/deps/h3";
1
+ import * as nitro_deps_h31 from "nitro/deps/h3";
2
2
 
3
3
  //#region src/nitro/routes/debug.d.ts
4
4
 
@@ -10,7 +10,7 @@ import * as nitro_deps_h30 from "nitro/deps/h3";
10
10
  * - /_nitro/graphql/debug - HTML dashboard
11
11
  * - /_nitro/graphql/debug?format=json - JSON API
12
12
  */
13
- declare const _default: nitro_deps_h30.EventHandlerWithFetch<nitro_deps_h30.EventHandlerRequest, Promise<string | {
13
+ declare const _default: nitro_deps_h31.EventHandlerWithFetch<nitro_deps_h31.EventHandlerRequest, Promise<string | {
14
14
  timestamp: string;
15
15
  environment: {
16
16
  dev: any;
@@ -1,6 +1,6 @@
1
- import * as nitro_deps_h33 from "nitro/deps/h3";
1
+ import * as nitro_deps_h35 from "nitro/deps/h3";
2
2
 
3
3
  //#region src/nitro/routes/graphql-yoga.d.ts
4
- declare const _default: nitro_deps_h33.EventHandlerWithFetch<nitro_deps_h33.EventHandlerRequest, Promise<Response>>;
4
+ declare const _default: nitro_deps_h35.EventHandlerWithFetch<nitro_deps_h35.EventHandlerRequest, Promise<Response>>;
5
5
  //#endregion
6
6
  export { _default as default };
@@ -1,7 +1,7 @@
1
- import * as nitro_deps_h35 from "nitro/deps/h3";
1
+ import * as nitro_deps_h33 from "nitro/deps/h3";
2
2
 
3
3
  //#region src/nitro/routes/health.d.ts
4
- declare const _default: nitro_deps_h35.EventHandlerWithFetch<nitro_deps_h35.EventHandlerRequest, Promise<{
4
+ declare const _default: nitro_deps_h33.EventHandlerWithFetch<nitro_deps_h33.EventHandlerRequest, Promise<{
5
5
  status: string;
6
6
  message: string;
7
7
  timestamp: string;
@@ -8,6 +8,7 @@ import consola from "consola";
8
8
  import { join, resolve } from "pathe";
9
9
  import { existsSync, readFileSync, writeFileSync } from "node:fs";
10
10
  import { watch } from "chokidar";
11
+ import { debounce } from "perfect-debounce";
11
12
 
12
13
  //#region src/nitro/setup/file-watcher.ts
13
14
  const logger = consola.withTag(LOG_TAG);
@@ -33,12 +34,15 @@ function setupFileWatcher(nitro, watchDirs) {
33
34
  ignoreInitial: DEFAULT_WATCHER_IGNORE_INITIAL,
34
35
  ignored: nitro.options.ignore
35
36
  });
36
- watcher.on("all", async (_, path) => {
37
- if (path.includes("/sdk.ts") || path.includes("/sdk.js") || path.endsWith("/config.ts")) return;
38
- const isGraphQLFile = GRAPHQL_EXTENSIONS.some((ext) => path.endsWith(ext));
39
- const isResolverFile = RESOLVER_EXTENSIONS.some((ext) => path.endsWith(ext));
40
- const isDirectiveFile = DIRECTIVE_EXTENSIONS.some((ext) => path.endsWith(ext));
41
- if (isGraphQLFile || isResolverFile || isDirectiveFile) if (path.includes(nitro.graphql.serverDir) || path.includes(DIR_SERVER_GRAPHQL) || path.includes(DIR_SERVER_GRAPHQL_WIN) || isResolverFile || isDirectiveFile) {
37
+ const pending = {
38
+ server: false,
39
+ client: false,
40
+ graphql: false
41
+ };
42
+ async function processChanges() {
43
+ const changes = { ...pending };
44
+ pending.server = pending.client = pending.graphql = false;
45
+ if (changes.server) {
42
46
  const directivesResult = await NitroAdapter.scanDirectives(nitro);
43
47
  nitro.scanDirectives = directivesResult.items;
44
48
  if (!nitro.scanSchemas) nitro.scanSchemas = [];
@@ -51,12 +55,25 @@ function setupFileWatcher(nitro, watchDirs) {
51
55
  logger.success("Types regenerated");
52
56
  await generateServerTypes(nitro, { silent: true });
53
57
  await generateClientTypes(nitro, { silent: true });
54
- if (isGraphQLFile) triggerRolldownRebuild(nitro);
58
+ if (changes.graphql) triggerRolldownRebuild(nitro);
55
59
  await nitro.hooks.callHook("dev:reload");
56
- } else {
60
+ } else if (changes.client) {
57
61
  logger.success("Types regenerated");
58
62
  await generateClientTypes(nitro, { silent: true });
59
63
  }
64
+ }
65
+ const debouncedProcess = debounce(processChanges, 150);
66
+ watcher.on("all", (_, path) => {
67
+ if (path.includes("/sdk.ts") || path.includes("/sdk.js") || path.endsWith("/config.ts")) return;
68
+ const isGraphQL = GRAPHQL_EXTENSIONS.some((ext) => path.endsWith(ext));
69
+ const isResolver = RESOLVER_EXTENSIONS.some((ext) => path.endsWith(ext));
70
+ const isDirective = DIRECTIVE_EXTENSIONS.some((ext) => path.endsWith(ext));
71
+ if (!isGraphQL && !isResolver && !isDirective) return;
72
+ if (path.includes(nitro.graphql.serverDir) || path.includes(DIR_SERVER_GRAPHQL) || path.includes(DIR_SERVER_GRAPHQL_WIN) || isResolver || isDirective) {
73
+ pending.server = true;
74
+ if (isGraphQL) pending.graphql = true;
75
+ } else pending.client = true;
76
+ debouncedProcess();
60
77
  });
61
78
  return watcher;
62
79
  }
@@ -158,9 +158,14 @@ async function scanGraphQLFiles(nitro, serverEnabled) {
158
158
  */
159
159
  function setupDevHooks(nitro) {
160
160
  let hasShownInitialLogs = false;
161
+ let lastDevStart = 0;
162
+ const DEBOUNCE_MS = 500;
161
163
  nitro.hooks.hook("dev:start", async () => {
164
+ const now = Date.now();
165
+ if (now - lastDevStart < DEBOUNCE_MS) return;
166
+ lastDevStart = now;
162
167
  await scanAllGraphQLFiles(nitro);
163
- await resolveExtendConfig(nitro);
168
+ await resolveExtendConfig(nitro, { silent: true });
164
169
  if (nitro.options.dev && !hasShownInitialLogs) {
165
170
  hasShownInitialLogs = true;
166
171
  logResolverDiagnostics(nitro);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nitro-graphql",
3
3
  "type": "module",
4
- "version": "2.0.0-beta.42",
4
+ "version": "2.0.0-beta.43",
5
5
  "description": "GraphQL integration for Nitro",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -117,6 +117,7 @@
117
117
  "ohash": "^2.0.11",
118
118
  "oxc-parser": "^0.106.0",
119
119
  "pathe": "^2.0.3",
120
+ "perfect-debounce": "^2.0.0",
120
121
  "tinyglobby": "^0.2.15"
121
122
  },
122
123
  "devDependencies": {