nitro-graphql 2.0.0-beta.72 → 2.0.0-beta.73
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 +1 -1
- package/dist/cli/adapter.d.mts +0 -3
- package/dist/cli/adapter.mjs +6 -29
- package/dist/cli/commands/generate.mjs +2 -2
- package/dist/cli/config.d.mts +4 -5
- package/dist/cli/config.mjs +3 -1
- package/dist/cli/index.d.mts +3 -6
- package/dist/cli/index.mjs +1 -1
- package/dist/cli/server/graphql-handler.mjs +2 -1
- package/dist/cli/server/watcher.mjs +1 -1
- package/dist/core/codegen/client.d.mts +4 -27
- package/dist/core/codegen/client.mjs +26 -445
- package/dist/core/codegen/file-header.d.mts +7 -0
- package/dist/core/codegen/file-header.mjs +12 -0
- package/dist/core/codegen/index.d.mts +7 -5
- package/dist/core/codegen/index.mjs +7 -5
- package/dist/core/codegen/{runtime.d.mts → runtime-generator.d.mts} +1 -1
- package/dist/core/codegen/{runtime.mjs → runtime-generator.mjs} +1 -1
- package/dist/core/codegen/schema-loader.d.mts +2 -7
- package/dist/core/codegen/schema-loader.mjs +65 -70
- package/dist/core/codegen/server-type-helpers.d.mts +14 -0
- package/dist/core/codegen/server-type-helpers.mjs +76 -0
- package/dist/core/codegen/server.d.mts +1 -15
- package/dist/core/codegen/server.mjs +15 -105
- package/dist/core/codegen/subscription-extractor.d.mts +20 -0
- package/dist/core/codegen/subscription-extractor.mjs +30 -0
- package/dist/core/codegen/vue-subscription-builder.d.mts +10 -0
- package/dist/core/codegen/vue-subscription-builder.mjs +351 -0
- package/dist/core/constants.d.mts +5 -53
- package/dist/core/constants.mjs +13 -54
- package/dist/core/create-config.d.mts +31 -0
- package/dist/core/create-config.mjs +42 -0
- package/dist/core/debug/index.d.mts +2 -2
- package/dist/core/debug/index.mjs +2 -2
- package/dist/core/debug/template.d.mts +1 -5
- package/dist/core/debug/template.mjs +1 -1
- package/dist/core/extend/loader.d.mts +0 -1
- package/dist/core/extend/loader.mjs +59 -89
- package/dist/core/index.d.mts +22 -17
- package/dist/core/index.mjs +19 -15
- package/dist/core/manifest.mjs +3 -1
- package/dist/core/pubsub/index.d.mts +2 -109
- package/dist/core/pubsub/index.mjs +1 -145
- package/dist/core/pubsub/memory-pubsub.d.mts +109 -0
- package/dist/core/pubsub/memory-pubsub.mjs +146 -0
- package/dist/core/scanning/ast-scanner.mjs +4 -2
- package/dist/core/scanning/directives.mjs +2 -3
- package/dist/core/scanning/documents.d.mts +4 -3
- package/dist/core/scanning/documents.mjs +1 -1
- package/dist/core/scanning/{common.d.mts → file-scanner.d.mts} +1 -1
- package/dist/core/scanning/{common.mjs → file-scanner.mjs} +2 -10
- package/dist/core/scanning/index.d.mts +3 -3
- package/dist/core/scanning/index.mjs +3 -3
- package/dist/core/scanning/resolvers.mjs +8 -9
- package/dist/core/scanning/schemas.d.mts +1 -5
- package/dist/core/scanning/schemas.mjs +2 -24
- package/dist/core/schema/builder.d.mts +4 -2
- package/dist/core/schema/builder.mjs +4 -2
- package/dist/core/schema/index.d.mts +2 -2
- package/dist/core/schema/index.mjs +2 -2
- package/dist/core/server/apollo.d.mts +20 -0
- package/dist/core/server/apollo.mjs +54 -0
- package/dist/core/server/index.d.mts +4 -2
- package/dist/core/server/index.mjs +3 -2
- package/dist/core/server/types.d.mts +7 -14
- package/dist/core/server/types.mjs +15 -1
- package/dist/core/server/yoga.d.mts +1 -7
- package/dist/core/server/yoga.mjs +4 -13
- package/dist/core/types/adapter.d.mts +4 -39
- package/dist/core/types/codegen.d.mts +22 -45
- package/dist/core/types/config.d.mts +33 -121
- package/dist/core/types/define.d.mts +8 -5
- package/dist/core/types/index.d.mts +5 -4
- package/dist/core/types/scanning.d.mts +4 -1
- package/dist/core/types/standard-schema.d.mts +64 -0
- package/dist/core/utils/directive-parser.d.mts +8 -63
- package/dist/core/utils/directive-parser.mjs +114 -166
- package/dist/core/utils/file-io.d.mts +1 -5
- package/dist/core/utils/file-io.mjs +1 -11
- package/dist/core/utils/index.d.mts +5 -4
- package/dist/core/utils/index.mjs +6 -5
- package/dist/core/utils/logger.d.mts +1 -10
- package/dist/core/utils/logger.mjs +1 -19
- package/dist/core/utils/ofetch-templates.mjs +3 -4
- package/dist/core/utils/runtime.d.mts +1 -30
- package/dist/core/utils/runtime.mjs +2 -44
- package/dist/core/utils/string.d.mts +10 -0
- package/dist/core/utils/string.mjs +12 -0
- package/dist/core/watcher/create-watcher.d.mts +103 -0
- package/dist/core/watcher/create-watcher.mjs +143 -0
- package/dist/core/watcher/index.d.mts +2 -107
- package/dist/core/watcher/index.mjs +1 -139
- package/dist/define.d.mts +4 -2
- package/dist/define.mjs +7 -6
- package/dist/index.d.mts +4 -3
- package/dist/index.mjs +1 -1
- package/dist/nitro/adapter.d.mts +6 -10
- package/dist/nitro/adapter.mjs +12 -42
- package/dist/nitro/codegen/client-types.d.mts +12 -0
- package/dist/nitro/codegen/client-types.mjs +73 -0
- package/dist/nitro/codegen/external-types.d.mts +8 -0
- package/dist/nitro/codegen/external-types.mjs +47 -0
- package/dist/nitro/codegen/index.d.mts +4 -0
- package/dist/nitro/codegen/index.mjs +4 -0
- package/dist/nitro/codegen/server-types.d.mts +12 -0
- package/dist/nitro/codegen/server-types.mjs +81 -0
- package/dist/nitro/defaults.d.mts +28 -0
- package/dist/nitro/defaults.mjs +34 -0
- package/dist/nitro/index.d.mts +11 -3
- package/dist/nitro/index.mjs +1 -1
- package/dist/nitro/paths.d.mts +3 -2
- package/dist/nitro/paths.mjs +13 -9
- package/dist/nitro/rollup.mjs +4 -3
- package/dist/nitro/routes/_ws-handler.d.mts +6 -0
- package/dist/nitro/routes/_ws-handler.mjs +49 -0
- package/dist/nitro/routes/apollo-server-ws.d.mts +1 -1
- package/dist/nitro/routes/apollo-server-ws.mjs +9 -44
- package/dist/nitro/routes/apollo-server.d.mts +1 -1
- package/dist/nitro/routes/apollo-server.mjs +16 -55
- package/dist/nitro/routes/debug.d.mts +1 -1
- package/dist/nitro/routes/debug.mjs +1 -0
- package/dist/nitro/routes/graphql-yoga-ws.d.mts +1 -1
- package/dist/nitro/routes/graphql-yoga-ws.mjs +6 -44
- package/dist/nitro/routes/graphql-yoga.mjs +7 -5
- package/dist/nitro/routes/health.mjs +22 -24
- package/dist/nitro/setup/extend-loader.d.mts +6 -5
- package/dist/nitro/setup/extend-loader.mjs +30 -58
- package/dist/nitro/setup/file-watcher.mjs +6 -4
- package/dist/nitro/setup/logging.d.mts +1 -8
- package/dist/nitro/setup/logging.mjs +7 -22
- package/dist/nitro/setup/rollup-integration.mjs +32 -1
- package/dist/nitro/setup/scanner.d.mts +8 -43
- package/dist/nitro/setup/scanner.mjs +56 -58
- package/dist/nitro/setup/security.d.mts +10 -0
- package/dist/nitro/setup/security.mjs +17 -0
- package/dist/nitro/setup/type-generation.d.mts +13 -0
- package/dist/nitro/setup/type-generation.mjs +16 -0
- package/dist/nitro/setup.d.mts +4 -3
- package/dist/nitro/setup.mjs +87 -74
- package/dist/nitro/state.d.mts +32 -0
- package/dist/nitro/state.mjs +58 -0
- package/dist/nitro/types/augmentation.d.mts +59 -0
- package/dist/nitro/types/augmentation.mjs +1 -0
- package/dist/nitro/types/config.d.mts +327 -0
- package/dist/nitro/types/config.mjs +1 -0
- package/dist/nitro/types/define.d.mts +13 -0
- package/dist/nitro/types/define.mjs +1 -0
- package/dist/nitro/types/index.d.mts +10 -0
- package/dist/nitro/types/index.mjs +1 -0
- package/dist/nitro/virtual/debug-info.d.mts +9 -0
- package/dist/nitro/virtual/debug-info.mjs +35 -0
- package/dist/nitro/virtual/graphql-config.d.mts +9 -0
- package/dist/nitro/virtual/graphql-config.mjs +33 -0
- package/dist/nitro/virtual/index.d.mts +25 -0
- package/dist/nitro/virtual/index.mjs +45 -0
- package/dist/nitro/virtual/module-config.d.mts +9 -0
- package/dist/nitro/virtual/module-config.mjs +10 -0
- package/dist/nitro/virtual/pubsub.d.mts +9 -0
- package/dist/nitro/virtual/pubsub.mjs +17 -0
- package/dist/nitro/virtual/server-directives.d.mts +9 -0
- package/dist/nitro/virtual/server-directives.mjs +12 -0
- package/dist/nitro/virtual/server-resolvers.d.mts +9 -0
- package/dist/nitro/virtual/server-resolvers.mjs +17 -0
- package/dist/nitro/virtual/server-schemas.d.mts +9 -0
- package/dist/nitro/virtual/server-schemas.mjs +31 -0
- package/dist/nitro/virtual/stubs.d.mts +42 -10
- package/dist/nitro/virtual/stubs.mjs +0 -5
- package/dist/nitro/virtual/utils.d.mts +15 -0
- package/dist/nitro/virtual/utils.mjs +26 -0
- package/dist/nitro/virtual/validation-schemas.d.mts +9 -0
- package/dist/nitro/virtual/validation-schemas.mjs +33 -0
- package/native/index.js +52 -52
- package/package.json +15 -15
- package/dist/cli/commands/index.d.mts +0 -5
- package/dist/cli/commands/index.mjs +0 -5
- package/dist/core/codegen/plugin.d.mts +0 -19
- package/dist/core/codegen/plugin.mjs +0 -29
- package/dist/core/config.d.mts +0 -45
- package/dist/core/config.mjs +0 -76
- package/dist/nitro/codegen.d.mts +0 -18
- package/dist/nitro/codegen.mjs +0 -171
- package/dist/nitro/config.d.mts +0 -50
- package/dist/nitro/config.mjs +0 -55
- package/dist/nitro/types.d.mts +0 -549
- package/dist/nitro/virtual/generators.d.mts +0 -38
- package/dist/nitro/virtual/generators.mjs +0 -190
- /package/dist/{nitro/types.mjs → core/types/standard-schema.mjs} +0 -0
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { existsSync, mkdirSync, promises, readFileSync, writeFileSync } from "node:fs";
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
2
|
import { pathToFileURL as pathToFileURL$1 } from "node:url";
|
|
4
3
|
//#region src/core/utils/runtime.ts
|
|
5
4
|
/**
|
|
@@ -10,53 +9,24 @@ import { pathToFileURL as pathToFileURL$1 } from "node:url";
|
|
|
10
9
|
*/
|
|
11
10
|
const _globalThis = globalThis;
|
|
12
11
|
/**
|
|
13
|
-
* Read file contents asynchronously
|
|
14
|
-
*/
|
|
15
|
-
async function readFile(path) {
|
|
16
|
-
return promises.readFile(path, "utf-8");
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
12
|
* Read file contents synchronously
|
|
20
13
|
*/
|
|
21
14
|
function readFileSync_(path) {
|
|
22
15
|
return readFileSync(path, "utf-8");
|
|
23
16
|
}
|
|
24
17
|
/**
|
|
25
|
-
* Write file contents asynchronously
|
|
26
|
-
*/
|
|
27
|
-
async function writeFile(path, content) {
|
|
28
|
-
await promises.writeFile(path, content, "utf-8");
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
18
|
* Write file contents synchronously
|
|
32
19
|
*/
|
|
33
20
|
function writeFileSync_(path, content) {
|
|
34
21
|
writeFileSync(path, content, "utf-8");
|
|
35
22
|
}
|
|
36
23
|
/**
|
|
37
|
-
* Check if file/directory exists asynchronously
|
|
38
|
-
*/
|
|
39
|
-
async function exists(path) {
|
|
40
|
-
try {
|
|
41
|
-
await promises.access(path);
|
|
42
|
-
return true;
|
|
43
|
-
} catch {
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
24
|
* Check if file/directory exists synchronously
|
|
49
25
|
*/
|
|
50
26
|
function existsSync_(path) {
|
|
51
27
|
return existsSync(path);
|
|
52
28
|
}
|
|
53
29
|
/**
|
|
54
|
-
* Create directory recursively asynchronously
|
|
55
|
-
*/
|
|
56
|
-
async function mkdir(path) {
|
|
57
|
-
await promises.mkdir(path, { recursive: true });
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
30
|
* Create directory recursively synchronously
|
|
61
31
|
*/
|
|
62
32
|
function mkdirSync_(path) {
|
|
@@ -93,17 +63,5 @@ function onSignal(signal, handler) {
|
|
|
93
63
|
if (_globalThis.Deno) _globalThis.Deno.addSignalListener(signal, handler);
|
|
94
64
|
else process.on(signal, handler);
|
|
95
65
|
}
|
|
96
|
-
/**
|
|
97
|
-
* Read directory contents
|
|
98
|
-
*/
|
|
99
|
-
async function readdir(path) {
|
|
100
|
-
return promises.readdir(path);
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Get file/directory stats
|
|
104
|
-
*/
|
|
105
|
-
async function stat(path) {
|
|
106
|
-
return promises.stat(path);
|
|
107
|
-
}
|
|
108
66
|
//#endregion
|
|
109
|
-
export {
|
|
67
|
+
export { existsSync_, exit, getCwd, mkdirSync_, onSignal, pathToFileURL, readFileSync_, writeFileSync_ };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/core/utils/string.ts
|
|
2
|
+
/**
|
|
3
|
+
* Shared string utilities
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Capitalize the first character of a string (PascalCase first letter)
|
|
7
|
+
*/
|
|
8
|
+
function capitalize(str) {
|
|
9
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { capitalize };
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { FSWatcher } from "chokidar";
|
|
2
|
+
|
|
3
|
+
//#region src/core/watcher/create-watcher.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Configuration for core watcher
|
|
6
|
+
*/
|
|
7
|
+
interface CoreWatcherConfig {
|
|
8
|
+
/** Directories to watch */
|
|
9
|
+
watchDirs: string[];
|
|
10
|
+
/** Server directory path (to classify changes) */
|
|
11
|
+
serverDir: string;
|
|
12
|
+
/** Debounce delay in ms (default: 150) */
|
|
13
|
+
debounceMs?: number;
|
|
14
|
+
/** Persistent watcher (default: true) */
|
|
15
|
+
persistent?: boolean;
|
|
16
|
+
/** Ignore initial scan (default: true) */
|
|
17
|
+
ignoreInitial?: boolean;
|
|
18
|
+
/** Use polling mode (default: false, but auto-enabled in CI/test environments) */
|
|
19
|
+
usePolling?: boolean;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Callbacks for watcher events
|
|
23
|
+
*/
|
|
24
|
+
interface CoreWatcherCallbacks {
|
|
25
|
+
/** Called when server files change (schemas, resolvers, directives) */
|
|
26
|
+
onServerChange: () => Promise<void>;
|
|
27
|
+
/** Called when client files change (documents only) */
|
|
28
|
+
onClientChange: () => Promise<void>;
|
|
29
|
+
/** Called when watcher is ready */
|
|
30
|
+
onReady?: () => void;
|
|
31
|
+
/** Called on watcher error */
|
|
32
|
+
onError?: (error: unknown) => void;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* File type classification
|
|
36
|
+
*/
|
|
37
|
+
type FileType = 'graphql' | 'resolver' | 'directive' | null;
|
|
38
|
+
/**
|
|
39
|
+
* Change type classification
|
|
40
|
+
*/
|
|
41
|
+
type ChangeType = 'server' | 'client' | null;
|
|
42
|
+
/**
|
|
43
|
+
* Check if a file is a GraphQL-related file
|
|
44
|
+
*/
|
|
45
|
+
declare function getFileType(path: string): FileType;
|
|
46
|
+
/**
|
|
47
|
+
* Check if a file should be watched
|
|
48
|
+
*/
|
|
49
|
+
declare function isWatchableFile(path: string): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Classify a file change as server or client
|
|
52
|
+
*/
|
|
53
|
+
declare function classifyChange(path: string, serverDir: string): ChangeType;
|
|
54
|
+
declare function createIgnoredFunction(): (path: string) => boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Check if a path should be skipped (generated files)
|
|
57
|
+
*/
|
|
58
|
+
declare function shouldSkipPath(path: string): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Create a core file watcher
|
|
61
|
+
*
|
|
62
|
+
* This is the shared watcher used by both Nitro and CLI.
|
|
63
|
+
* Framework-specific actions are passed as callbacks.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* // In Nitro
|
|
68
|
+
* const watcher = createCoreWatcher(
|
|
69
|
+
* { watchDirs, serverDir: nitro.graphql.serverDir },
|
|
70
|
+
* {
|
|
71
|
+
* onServerChange: async () => {
|
|
72
|
+
* await performGraphQLScan(nitro, { silent: true, isRescan: true })
|
|
73
|
+
* await generateServerTypes(nitro, { silent: true })
|
|
74
|
+
* await nitro.hooks.callHook('dev:reload')
|
|
75
|
+
* },
|
|
76
|
+
* onClientChange: async () => {
|
|
77
|
+
* await generateClientTypes(nitro, { silent: true })
|
|
78
|
+
* },
|
|
79
|
+
* }
|
|
80
|
+
* )
|
|
81
|
+
*
|
|
82
|
+
* // In CLI
|
|
83
|
+
* const watcher = createCoreWatcher(
|
|
84
|
+
* { watchDirs, serverDir: ctx.config.serverDir },
|
|
85
|
+
* {
|
|
86
|
+
* onServerChange: async () => {
|
|
87
|
+
* await generateAll(ctx, { silent: true })
|
|
88
|
+
* await reloadHandler()
|
|
89
|
+
* },
|
|
90
|
+
* onClientChange: async () => {
|
|
91
|
+
* await generateClient(ctx, { silent: true })
|
|
92
|
+
* },
|
|
93
|
+
* }
|
|
94
|
+
* )
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
declare function createCoreWatcher(config: CoreWatcherConfig, callbacks: CoreWatcherCallbacks): FSWatcher;
|
|
98
|
+
/**
|
|
99
|
+
* Close a watcher safely
|
|
100
|
+
*/
|
|
101
|
+
declare function closeWatcher(watcher: FSWatcher): Promise<void>;
|
|
102
|
+
//#endregion
|
|
103
|
+
export { ChangeType, CoreWatcherCallbacks, CoreWatcherConfig, FileType, classifyChange, closeWatcher, createCoreWatcher, createIgnoredFunction, getFileType, isWatchableFile, shouldSkipPath };
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { DEFAULT_IGNORE_PATTERNS, DIRECTIVE_EXTENSIONS, GRAPHQL_EXTENSIONS, RESOLVER_EXTENSIONS } from "../constants.mjs";
|
|
2
|
+
import { watch } from "chokidar";
|
|
3
|
+
import { debounce } from "perfect-debounce";
|
|
4
|
+
//#region src/core/watcher/create-watcher.ts
|
|
5
|
+
const BACKSLASH_RE = /\\/g;
|
|
6
|
+
/**
|
|
7
|
+
* Check if a file is a GraphQL-related file
|
|
8
|
+
*/
|
|
9
|
+
function getFileType(path) {
|
|
10
|
+
if (GRAPHQL_EXTENSIONS.some((ext) => path.endsWith(ext))) return "graphql";
|
|
11
|
+
if (RESOLVER_EXTENSIONS.some((ext) => path.endsWith(ext))) return "resolver";
|
|
12
|
+
if (DIRECTIVE_EXTENSIONS.some((ext) => path.endsWith(ext))) return "directive";
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Check if a file should be watched
|
|
17
|
+
*/
|
|
18
|
+
function isWatchableFile(path) {
|
|
19
|
+
return getFileType(path) !== null;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Classify a file change as server or client
|
|
23
|
+
*/
|
|
24
|
+
function classifyChange(path, serverDir) {
|
|
25
|
+
const fileType = getFileType(path);
|
|
26
|
+
if (!fileType) return null;
|
|
27
|
+
if (fileType === "resolver" || fileType === "directive") return "server";
|
|
28
|
+
if (fileType === "graphql") {
|
|
29
|
+
const normalizedPath = path.replace(BACKSLASH_RE, "/");
|
|
30
|
+
const normalizedServerDir = serverDir.replace(BACKSLASH_RE, "/");
|
|
31
|
+
if (normalizedPath.includes(normalizedServerDir)) return "server";
|
|
32
|
+
if (normalizedPath.includes("/server/graphql/") || normalizedPath.includes("\\server\\graphql\\")) return "server";
|
|
33
|
+
return "client";
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Create the ignored function for chokidar
|
|
39
|
+
* Filters out non-GraphQL files and system directories
|
|
40
|
+
*/
|
|
41
|
+
const GLOB_STAR_RE = /\*\*/g;
|
|
42
|
+
const SINGLE_STAR_RE = /\*/g;
|
|
43
|
+
function createIgnoredFunction() {
|
|
44
|
+
const ignoredDirs = DEFAULT_IGNORE_PATTERNS.map((p) => p.replace(GLOB_STAR_RE, "").replace(SINGLE_STAR_RE, ""));
|
|
45
|
+
return (path) => {
|
|
46
|
+
if (ignoredDirs.some((dir) => path.includes(dir))) return true;
|
|
47
|
+
if (!(path.split("/").pop() || "").includes(".") || path.endsWith("/")) return false;
|
|
48
|
+
return !isWatchableFile(path);
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Check if a path should be skipped (generated files)
|
|
53
|
+
*/
|
|
54
|
+
function shouldSkipPath(path) {
|
|
55
|
+
return path.includes("/sdk.ts") || path.includes("/sdk.js") || path.endsWith("/config.ts");
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Create a core file watcher
|
|
59
|
+
*
|
|
60
|
+
* This is the shared watcher used by both Nitro and CLI.
|
|
61
|
+
* Framework-specific actions are passed as callbacks.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* // In Nitro
|
|
66
|
+
* const watcher = createCoreWatcher(
|
|
67
|
+
* { watchDirs, serverDir: nitro.graphql.serverDir },
|
|
68
|
+
* {
|
|
69
|
+
* onServerChange: async () => {
|
|
70
|
+
* await performGraphQLScan(nitro, { silent: true, isRescan: true })
|
|
71
|
+
* await generateServerTypes(nitro, { silent: true })
|
|
72
|
+
* await nitro.hooks.callHook('dev:reload')
|
|
73
|
+
* },
|
|
74
|
+
* onClientChange: async () => {
|
|
75
|
+
* await generateClientTypes(nitro, { silent: true })
|
|
76
|
+
* },
|
|
77
|
+
* }
|
|
78
|
+
* )
|
|
79
|
+
*
|
|
80
|
+
* // In CLI
|
|
81
|
+
* const watcher = createCoreWatcher(
|
|
82
|
+
* { watchDirs, serverDir: ctx.config.serverDir },
|
|
83
|
+
* {
|
|
84
|
+
* onServerChange: async () => {
|
|
85
|
+
* await generateAll(ctx, { silent: true })
|
|
86
|
+
* await reloadHandler()
|
|
87
|
+
* },
|
|
88
|
+
* onClientChange: async () => {
|
|
89
|
+
* await generateClient(ctx, { silent: true })
|
|
90
|
+
* },
|
|
91
|
+
* }
|
|
92
|
+
* )
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
function createCoreWatcher(config, callbacks) {
|
|
96
|
+
const { watchDirs, serverDir, debounceMs = 150, persistent = true, ignoreInitial = true, usePolling } = config;
|
|
97
|
+
const shouldUsePolling = usePolling ?? (process.env.CI === "true" || process.env.VITE_TEST === "true");
|
|
98
|
+
const watcher = watch(watchDirs, {
|
|
99
|
+
persistent,
|
|
100
|
+
ignoreInitial,
|
|
101
|
+
ignored: createIgnoredFunction(),
|
|
102
|
+
usePolling: shouldUsePolling,
|
|
103
|
+
interval: shouldUsePolling ? 100 : void 0,
|
|
104
|
+
awaitWriteFinish: shouldUsePolling ? {
|
|
105
|
+
stabilityThreshold: 100,
|
|
106
|
+
pollInterval: 50
|
|
107
|
+
} : false
|
|
108
|
+
});
|
|
109
|
+
const pending = {
|
|
110
|
+
server: false,
|
|
111
|
+
client: false
|
|
112
|
+
};
|
|
113
|
+
async function processChanges() {
|
|
114
|
+
const changes = { ...pending };
|
|
115
|
+
pending.server = pending.client = false;
|
|
116
|
+
try {
|
|
117
|
+
if (changes.server) await callbacks.onServerChange();
|
|
118
|
+
else if (changes.client) await callbacks.onClientChange();
|
|
119
|
+
} catch (error) {
|
|
120
|
+
callbacks.onError?.(error);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
const debouncedProcess = debounce(processChanges, debounceMs);
|
|
124
|
+
watcher.on("all", (_, path) => {
|
|
125
|
+
if (shouldSkipPath(path)) return;
|
|
126
|
+
const changeType = classifyChange(path, serverDir);
|
|
127
|
+
if (!changeType) return;
|
|
128
|
+
if (changeType === "server") pending.server = true;
|
|
129
|
+
else pending.client = true;
|
|
130
|
+
debouncedProcess();
|
|
131
|
+
});
|
|
132
|
+
if (callbacks.onReady) watcher.on("ready", callbacks.onReady);
|
|
133
|
+
if (callbacks.onError) watcher.on("error", callbacks.onError);
|
|
134
|
+
return watcher;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Close a watcher safely
|
|
138
|
+
*/
|
|
139
|
+
async function closeWatcher(watcher) {
|
|
140
|
+
await watcher.close();
|
|
141
|
+
}
|
|
142
|
+
//#endregion
|
|
143
|
+
export { classifyChange, closeWatcher, createCoreWatcher, createIgnoredFunction, getFileType, isWatchableFile, shouldSkipPath };
|
|
@@ -1,107 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
//#region src/core/watcher/index.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* Configuration for core watcher
|
|
6
|
-
*/
|
|
7
|
-
interface CoreWatcherConfig {
|
|
8
|
-
/** Directories to watch */
|
|
9
|
-
watchDirs: string[];
|
|
10
|
-
/** Server directory path (to classify changes) */
|
|
11
|
-
serverDir: string;
|
|
12
|
-
/** Debounce delay in ms (default: 150) */
|
|
13
|
-
debounceMs?: number;
|
|
14
|
-
/** Persistent watcher (default: true) */
|
|
15
|
-
persistent?: boolean;
|
|
16
|
-
/** Ignore initial scan (default: true) */
|
|
17
|
-
ignoreInitial?: boolean;
|
|
18
|
-
/** Use polling mode (default: false, but auto-enabled in CI/test environments) */
|
|
19
|
-
usePolling?: boolean;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Callbacks for watcher events
|
|
23
|
-
*/
|
|
24
|
-
interface CoreWatcherCallbacks {
|
|
25
|
-
/** Called when server files change (schemas, resolvers, directives) */
|
|
26
|
-
onServerChange: () => Promise<void>;
|
|
27
|
-
/** Called when client files change (documents only) */
|
|
28
|
-
onClientChange: () => Promise<void>;
|
|
29
|
-
/** Called when watcher is ready */
|
|
30
|
-
onReady?: () => void;
|
|
31
|
-
/** Called on watcher error */
|
|
32
|
-
onError?: (error: unknown) => void;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* File type classification
|
|
36
|
-
*/
|
|
37
|
-
type FileType = 'graphql' | 'resolver' | 'directive' | null;
|
|
38
|
-
/**
|
|
39
|
-
* Change type classification
|
|
40
|
-
*/
|
|
41
|
-
type ChangeType = 'server' | 'client' | null;
|
|
42
|
-
/**
|
|
43
|
-
* Check if a file is a GraphQL-related file
|
|
44
|
-
*/
|
|
45
|
-
declare function getFileType(path: string): FileType;
|
|
46
|
-
/**
|
|
47
|
-
* Check if a file should be watched
|
|
48
|
-
*/
|
|
49
|
-
declare function isWatchableFile(path: string): boolean;
|
|
50
|
-
/**
|
|
51
|
-
* Classify a file change as server or client
|
|
52
|
-
*/
|
|
53
|
-
declare function classifyChange(path: string, serverDir: string): ChangeType;
|
|
54
|
-
/**
|
|
55
|
-
* Create the ignored function for chokidar
|
|
56
|
-
* Filters out non-GraphQL files and system directories
|
|
57
|
-
*/
|
|
58
|
-
declare function createIgnoredFunction(): (path: string) => boolean;
|
|
59
|
-
/**
|
|
60
|
-
* Check if a path should be skipped (generated files)
|
|
61
|
-
*/
|
|
62
|
-
declare function shouldSkipPath(path: string): boolean;
|
|
63
|
-
/**
|
|
64
|
-
* Create a core file watcher
|
|
65
|
-
*
|
|
66
|
-
* This is the shared watcher used by both Nitro and CLI.
|
|
67
|
-
* Framework-specific actions are passed as callbacks.
|
|
68
|
-
*
|
|
69
|
-
* @example
|
|
70
|
-
* ```typescript
|
|
71
|
-
* // In Nitro
|
|
72
|
-
* const watcher = createCoreWatcher(
|
|
73
|
-
* { watchDirs, serverDir: nitro.graphql.serverDir },
|
|
74
|
-
* {
|
|
75
|
-
* onServerChange: async () => {
|
|
76
|
-
* await performGraphQLScan(nitro, { silent: true, isRescan: true })
|
|
77
|
-
* await generateServerTypes(nitro, { silent: true })
|
|
78
|
-
* await nitro.hooks.callHook('dev:reload')
|
|
79
|
-
* },
|
|
80
|
-
* onClientChange: async () => {
|
|
81
|
-
* await generateClientTypes(nitro, { silent: true })
|
|
82
|
-
* },
|
|
83
|
-
* }
|
|
84
|
-
* )
|
|
85
|
-
*
|
|
86
|
-
* // In CLI
|
|
87
|
-
* const watcher = createCoreWatcher(
|
|
88
|
-
* { watchDirs, serverDir: ctx.config.serverDir },
|
|
89
|
-
* {
|
|
90
|
-
* onServerChange: async () => {
|
|
91
|
-
* await generateAll(ctx, { silent: true })
|
|
92
|
-
* await reloadHandler()
|
|
93
|
-
* },
|
|
94
|
-
* onClientChange: async () => {
|
|
95
|
-
* await generateClient(ctx, { silent: true })
|
|
96
|
-
* },
|
|
97
|
-
* }
|
|
98
|
-
* )
|
|
99
|
-
* ```
|
|
100
|
-
*/
|
|
101
|
-
declare function createCoreWatcher(config: CoreWatcherConfig, callbacks: CoreWatcherCallbacks): FSWatcher;
|
|
102
|
-
/**
|
|
103
|
-
* Close a watcher safely
|
|
104
|
-
*/
|
|
105
|
-
declare function closeWatcher(watcher: FSWatcher): Promise<void>;
|
|
106
|
-
//#endregion
|
|
107
|
-
export { ChangeType, CoreWatcherCallbacks, CoreWatcherConfig, FileType, classifyChange, closeWatcher, createCoreWatcher, createIgnoredFunction, getFileType, isWatchableFile, shouldSkipPath };
|
|
1
|
+
import { ChangeType, CoreWatcherCallbacks, CoreWatcherConfig, FileType, classifyChange, closeWatcher, createCoreWatcher, createIgnoredFunction, getFileType, isWatchableFile, shouldSkipPath } from "./create-watcher.mjs";
|
|
2
|
+
export { type ChangeType, type CoreWatcherCallbacks, type CoreWatcherConfig, type FileType, classifyChange, closeWatcher, createCoreWatcher, createIgnoredFunction, getFileType, isWatchableFile, shouldSkipPath };
|
|
@@ -1,140 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { watch } from "chokidar";
|
|
3
|
-
import { debounce } from "perfect-debounce";
|
|
4
|
-
//#region src/core/watcher/index.ts
|
|
5
|
-
const BACKSLASH_RE = /\\/g;
|
|
6
|
-
/**
|
|
7
|
-
* Check if a file is a GraphQL-related file
|
|
8
|
-
*/
|
|
9
|
-
function getFileType(path) {
|
|
10
|
-
if (GRAPHQL_EXTENSIONS.some((ext) => path.endsWith(ext))) return "graphql";
|
|
11
|
-
if (RESOLVER_EXTENSIONS.some((ext) => path.endsWith(ext))) return "resolver";
|
|
12
|
-
if (DIRECTIVE_EXTENSIONS.some((ext) => path.endsWith(ext))) return "directive";
|
|
13
|
-
return null;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Check if a file should be watched
|
|
17
|
-
*/
|
|
18
|
-
function isWatchableFile(path) {
|
|
19
|
-
return getFileType(path) !== null;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Classify a file change as server or client
|
|
23
|
-
*/
|
|
24
|
-
function classifyChange(path, serverDir) {
|
|
25
|
-
const fileType = getFileType(path);
|
|
26
|
-
if (!fileType) return null;
|
|
27
|
-
if (fileType === "resolver" || fileType === "directive") return "server";
|
|
28
|
-
if (fileType === "graphql") {
|
|
29
|
-
const normalizedPath = path.replace(BACKSLASH_RE, "/");
|
|
30
|
-
const normalizedServerDir = serverDir.replace(BACKSLASH_RE, "/");
|
|
31
|
-
if (normalizedPath.includes(normalizedServerDir)) return "server";
|
|
32
|
-
if (normalizedPath.includes("/server/graphql/") || normalizedPath.includes("\\server\\graphql\\")) return "server";
|
|
33
|
-
return "client";
|
|
34
|
-
}
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Create the ignored function for chokidar
|
|
39
|
-
* Filters out non-GraphQL files and system directories
|
|
40
|
-
*/
|
|
41
|
-
function createIgnoredFunction() {
|
|
42
|
-
return (path) => {
|
|
43
|
-
if (path.includes("/node_modules/") || path.includes("/.git/") || path.includes("/.output/") || path.includes("/.nitro/") || path.includes("/.nuxt/") || path.includes("/.graphql/") || path.includes("/dist/")) return true;
|
|
44
|
-
if (!(path.split("/").pop() || "").includes(".") || path.endsWith("/")) return false;
|
|
45
|
-
return !isWatchableFile(path);
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Check if a path should be skipped (generated files)
|
|
50
|
-
*/
|
|
51
|
-
function shouldSkipPath(path) {
|
|
52
|
-
return path.includes("/sdk.ts") || path.includes("/sdk.js") || path.endsWith("/config.ts");
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Create a core file watcher
|
|
56
|
-
*
|
|
57
|
-
* This is the shared watcher used by both Nitro and CLI.
|
|
58
|
-
* Framework-specific actions are passed as callbacks.
|
|
59
|
-
*
|
|
60
|
-
* @example
|
|
61
|
-
* ```typescript
|
|
62
|
-
* // In Nitro
|
|
63
|
-
* const watcher = createCoreWatcher(
|
|
64
|
-
* { watchDirs, serverDir: nitro.graphql.serverDir },
|
|
65
|
-
* {
|
|
66
|
-
* onServerChange: async () => {
|
|
67
|
-
* await performGraphQLScan(nitro, { silent: true, isRescan: true })
|
|
68
|
-
* await generateServerTypes(nitro, { silent: true })
|
|
69
|
-
* await nitro.hooks.callHook('dev:reload')
|
|
70
|
-
* },
|
|
71
|
-
* onClientChange: async () => {
|
|
72
|
-
* await generateClientTypes(nitro, { silent: true })
|
|
73
|
-
* },
|
|
74
|
-
* }
|
|
75
|
-
* )
|
|
76
|
-
*
|
|
77
|
-
* // In CLI
|
|
78
|
-
* const watcher = createCoreWatcher(
|
|
79
|
-
* { watchDirs, serverDir: ctx.config.serverDir },
|
|
80
|
-
* {
|
|
81
|
-
* onServerChange: async () => {
|
|
82
|
-
* await generateAll(ctx, { silent: true })
|
|
83
|
-
* await reloadHandler()
|
|
84
|
-
* },
|
|
85
|
-
* onClientChange: async () => {
|
|
86
|
-
* await generateClient(ctx, { silent: true })
|
|
87
|
-
* },
|
|
88
|
-
* }
|
|
89
|
-
* )
|
|
90
|
-
* ```
|
|
91
|
-
*/
|
|
92
|
-
function createCoreWatcher(config, callbacks) {
|
|
93
|
-
const { watchDirs, serverDir, debounceMs = 150, persistent = true, ignoreInitial = true, usePolling } = config;
|
|
94
|
-
const shouldUsePolling = usePolling ?? (process.env.CI === "true" || process.env.VITE_TEST === "true");
|
|
95
|
-
const watcher = watch(watchDirs, {
|
|
96
|
-
persistent,
|
|
97
|
-
ignoreInitial,
|
|
98
|
-
ignored: createIgnoredFunction(),
|
|
99
|
-
usePolling: shouldUsePolling,
|
|
100
|
-
interval: shouldUsePolling ? 100 : void 0,
|
|
101
|
-
awaitWriteFinish: shouldUsePolling ? {
|
|
102
|
-
stabilityThreshold: 100,
|
|
103
|
-
pollInterval: 50
|
|
104
|
-
} : false
|
|
105
|
-
});
|
|
106
|
-
const pending = {
|
|
107
|
-
server: false,
|
|
108
|
-
client: false
|
|
109
|
-
};
|
|
110
|
-
async function processChanges() {
|
|
111
|
-
const changes = { ...pending };
|
|
112
|
-
pending.server = pending.client = false;
|
|
113
|
-
try {
|
|
114
|
-
if (changes.server) await callbacks.onServerChange();
|
|
115
|
-
else if (changes.client) await callbacks.onClientChange();
|
|
116
|
-
} catch (error) {
|
|
117
|
-
callbacks.onError?.(error);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
const debouncedProcess = debounce(processChanges, debounceMs);
|
|
121
|
-
watcher.on("all", (_, path) => {
|
|
122
|
-
if (shouldSkipPath(path)) return;
|
|
123
|
-
const changeType = classifyChange(path, serverDir);
|
|
124
|
-
if (!changeType) return;
|
|
125
|
-
if (changeType === "server") pending.server = true;
|
|
126
|
-
else pending.client = true;
|
|
127
|
-
debouncedProcess();
|
|
128
|
-
});
|
|
129
|
-
if (callbacks.onReady) watcher.on("ready", callbacks.onReady);
|
|
130
|
-
if (callbacks.onError) watcher.on("error", callbacks.onError);
|
|
131
|
-
return watcher;
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Close a watcher safely
|
|
135
|
-
*/
|
|
136
|
-
async function closeWatcher(watcher) {
|
|
137
|
-
await watcher.close();
|
|
138
|
-
}
|
|
139
|
-
//#endregion
|
|
1
|
+
import { classifyChange, closeWatcher, createCoreWatcher, createIgnoredFunction, getFileType, isWatchableFile, shouldSkipPath } from "./create-watcher.mjs";
|
|
140
2
|
export { classifyChange, closeWatcher, createCoreWatcher, createIgnoredFunction, getFileType, isWatchableFile, shouldSkipPath };
|
package/dist/define.d.mts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { DefineDirectiveConfig,
|
|
2
|
-
import {
|
|
1
|
+
import { DefineDirectiveConfig, DirectiveDefinition, Flatten } from "./core/types/define.mjs";
|
|
2
|
+
import { StandardSchemaV1 } from "./core/types/standard-schema.mjs";
|
|
3
|
+
import { DefineServerConfig } from "./nitro/types/define.mjs";
|
|
4
|
+
import { PubSubEngine, TypedPubSub, createPubSub, mapAsyncIterator, withFilter } from "./core/pubsub/memory-pubsub.mjs";
|
|
3
5
|
import { NPMConfig, Resolvers, ResolversTypes } from "#graphql/server";
|
|
4
6
|
|
|
5
7
|
//#region src/define.d.ts
|
package/dist/define.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createPubSub, mapAsyncIterator, withFilter } from "./core/pubsub/
|
|
1
|
+
import { createPubSub, mapAsyncIterator, withFilter } from "./core/pubsub/memory-pubsub.mjs";
|
|
2
2
|
//#region src/define.ts
|
|
3
3
|
/**
|
|
4
4
|
* Define schema extensions programmatically for GraphQL types.
|
|
@@ -308,16 +308,17 @@ function defineDirective(config) {
|
|
|
308
308
|
const argsString = args ? `(${args})` : "";
|
|
309
309
|
const locations = config.locations.join(" | ");
|
|
310
310
|
const schemaDefinition = `directive @${config.name}${argsString} on ${locations}`;
|
|
311
|
-
|
|
311
|
+
const result = {
|
|
312
|
+
...config,
|
|
313
|
+
locations: [...config.locations]
|
|
314
|
+
};
|
|
315
|
+
Object.defineProperty(result, "__schema", {
|
|
312
316
|
value: schemaDefinition,
|
|
313
317
|
enumerable: false,
|
|
314
318
|
configurable: false,
|
|
315
319
|
writable: false
|
|
316
320
|
});
|
|
317
|
-
return
|
|
318
|
-
...config,
|
|
319
|
-
locations: [...config.locations]
|
|
320
|
-
};
|
|
321
|
+
return result;
|
|
321
322
|
}
|
|
322
323
|
//#endregion
|
|
323
324
|
export { createPubSub, defineDirective, defineField, defineGraphQLConfig, defineMutation, defineQuery, defineResolver, defineSchema, defineSubscription, mapAsyncIterator, withFilter };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CoreSecurityConfig } from "./core/types/config.mjs";
|
|
2
|
+
import { ExternalGraphQLService, NitroGraphQLOptions } from "./nitro/types/config.mjs";
|
|
2
3
|
import { NitroAdapter } from "./nitro/adapter.mjs";
|
|
3
|
-
import { resolveSecurityConfig } from "./nitro/setup/
|
|
4
|
+
import { resolveSecurityConfig } from "./nitro/setup/security.mjs";
|
|
4
5
|
import { setupNitroGraphQL } from "./nitro/setup.mjs";
|
|
5
6
|
import graphqlModule from "./nitro/index.mjs";
|
|
6
|
-
export { type ExternalGraphQLService, NitroAdapter, type NitroGraphQLOptions, type SecurityConfig, graphqlModule as default, resolveSecurityConfig, setupNitroGraphQL };
|
|
7
|
+
export { type ExternalGraphQLService, NitroAdapter, type NitroGraphQLOptions, type CoreSecurityConfig as SecurityConfig, graphqlModule as default, resolveSecurityConfig, setupNitroGraphQL };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NitroAdapter } from "./nitro/adapter.mjs";
|
|
2
|
-
import { resolveSecurityConfig } from "./nitro/setup/
|
|
2
|
+
import { resolveSecurityConfig } from "./nitro/setup/security.mjs";
|
|
3
3
|
import { setupNitroGraphQL } from "./nitro/setup.mjs";
|
|
4
4
|
import graphqlModule from "./nitro/index.mjs";
|
|
5
5
|
export { NitroAdapter, graphqlModule as default, resolveSecurityConfig, setupNitroGraphQL };
|