nitro-graphql 2.0.0-beta.7 → 2.0.0-beta.70
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 +31 -1196
- package/dist/cli/adapter.d.mts +13 -0
- package/dist/cli/adapter.mjs +69 -0
- package/dist/cli/commands/build.d.mts +21 -0
- package/dist/cli/commands/build.mjs +52 -0
- package/dist/cli/commands/dev.d.mts +40 -0
- package/dist/cli/commands/dev.mjs +76 -0
- package/dist/cli/commands/generate.d.mts +25 -0
- package/dist/cli/commands/generate.mjs +198 -0
- package/dist/cli/commands/index.d.mts +5 -0
- package/dist/cli/commands/index.mjs +6 -0
- package/dist/cli/commands/init.d.mts +45 -0
- package/dist/cli/commands/init.mjs +195 -0
- package/dist/cli/commands/validate.d.mts +9 -0
- package/dist/cli/commands/validate.mjs +67 -0
- package/dist/cli/completions.d.mts +6 -0
- package/dist/cli/completions.mjs +34 -0
- package/dist/cli/config.d.mts +18 -0
- package/dist/cli/config.mjs +20 -0
- package/dist/cli/index.d.mts +26 -0
- package/dist/cli/index.mjs +317 -0
- package/dist/cli/server/debug-handler.d.mts +9 -0
- package/dist/cli/server/debug-handler.mjs +71 -0
- package/dist/cli/server/dev-server.d.mts +29 -0
- package/dist/cli/server/dev-server.mjs +64 -0
- package/dist/cli/server/graphql-handler.d.mts +21 -0
- package/dist/cli/server/graphql-handler.mjs +45 -0
- package/dist/cli/server/health-handler.d.mts +12 -0
- package/dist/cli/server/health-handler.mjs +30 -0
- package/dist/cli/server/loader.d.mts +33 -0
- package/dist/cli/server/loader.mjs +146 -0
- package/dist/cli/server/sandbox-handler.d.mts +12 -0
- package/dist/cli/server/sandbox-handler.mjs +19 -0
- package/dist/cli/server/watcher.d.mts +20 -0
- package/dist/cli/server/watcher.mjs +66 -0
- package/dist/cli/server/ws-handler.d.mts +28 -0
- package/dist/cli/server/ws-handler.mjs +50 -0
- package/dist/config.d.mts +2 -0
- package/dist/config.mjs +3 -0
- package/dist/core/codegen/client.d.mts +42 -0
- package/dist/core/codegen/client.mjs +553 -0
- package/dist/core/codegen/document-loader.d.mts +9 -0
- package/dist/core/codegen/document-loader.mjs +18 -0
- package/dist/core/codegen/index.d.mts +8 -0
- package/dist/core/codegen/index.mjs +9 -0
- package/dist/core/codegen/plugin.d.mts +19 -0
- package/dist/core/codegen/plugin.mjs +30 -0
- package/dist/core/codegen/runtime.d.mts +19 -0
- package/dist/core/codegen/runtime.mjs +60 -0
- package/dist/core/codegen/schema-loader.d.mts +27 -0
- package/dist/core/codegen/schema-loader.mjs +128 -0
- package/dist/core/codegen/server.d.mts +27 -0
- package/dist/core/codegen/server.mjs +144 -0
- package/dist/core/codegen/validation.d.mts +17 -0
- package/dist/core/codegen/validation.mjs +35 -0
- package/dist/core/config.d.mts +45 -0
- package/dist/core/config.mjs +78 -0
- package/dist/core/constants.d.mts +188 -0
- package/dist/core/constants.mjs +210 -0
- package/dist/core/debug/index.d.mts +2 -0
- package/dist/core/debug/index.mjs +3 -0
- package/dist/core/debug/template.d.mts +52 -0
- package/dist/core/debug/template.mjs +383 -0
- package/dist/core/extend/index.d.mts +2 -0
- package/dist/core/extend/index.mjs +3 -0
- package/dist/core/extend/loader.d.mts +40 -0
- package/dist/core/extend/loader.mjs +198 -0
- package/dist/core/index.d.mts +37 -0
- package/dist/core/index.mjs +29 -0
- package/dist/core/manifest.d.mts +56 -0
- package/dist/core/manifest.mjs +102 -0
- package/dist/core/pubsub/index.d.mts +109 -0
- package/dist/core/pubsub/index.mjs +148 -0
- package/dist/core/scanning/ast-scanner.d.mts +27 -0
- package/dist/core/scanning/ast-scanner.mjs +116 -0
- package/dist/core/scanning/common.d.mts +25 -0
- package/dist/core/scanning/common.mjs +59 -0
- package/dist/core/scanning/directives.d.mts +13 -0
- package/dist/core/scanning/directives.mjs +29 -0
- package/dist/core/scanning/documents.d.mts +20 -0
- package/dist/core/scanning/documents.mjs +37 -0
- package/dist/core/scanning/index.d.mts +7 -0
- package/dist/core/scanning/index.mjs +8 -0
- package/dist/core/scanning/resolvers.d.mts +14 -0
- package/dist/core/scanning/resolvers.mjs +59 -0
- package/dist/core/scanning/schemas.d.mts +13 -0
- package/dist/core/scanning/schemas.mjs +52 -0
- package/dist/core/schema/builder.d.mts +59 -0
- package/dist/core/schema/builder.mjs +78 -0
- package/dist/core/schema/federation.d.mts +33 -0
- package/dist/core/schema/federation.mjs +40 -0
- package/dist/core/schema/index.d.mts +3 -0
- package/dist/core/schema/index.mjs +4 -0
- package/dist/core/server/index.d.mts +4 -0
- package/dist/core/server/index.mjs +4 -0
- package/dist/core/server/sandbox.d.mts +18 -0
- package/dist/core/server/sandbox.mjs +39 -0
- package/dist/core/server/types.d.mts +54 -0
- package/dist/core/server/yoga.d.mts +42 -0
- package/dist/core/server/yoga.mjs +89 -0
- package/dist/core/types/adapter.d.mts +57 -0
- package/dist/core/types/codegen.d.mts +136 -0
- package/dist/core/types/codegen.mjs +1 -0
- package/dist/core/types/config.d.mts +188 -0
- package/dist/core/types/config.mjs +1 -0
- package/dist/{utils/define.d.ts → core/types/define.d.mts} +2 -30
- package/dist/core/types/define.mjs +1 -0
- package/dist/core/types/index.d.mts +5 -0
- package/dist/core/types/index.mjs +1 -0
- package/dist/core/types/scanning.d.mts +64 -0
- package/dist/core/types/scanning.mjs +1 -0
- package/dist/{utils/directive-parser.d.ts → core/utils/directive-parser.d.mts} +18 -4
- package/dist/{utils/directive-parser.js → core/utils/directive-parser.mjs} +28 -34
- package/dist/core/utils/errors.d.mts +77 -0
- package/dist/core/utils/errors.mjs +93 -0
- package/dist/core/utils/file-io.d.mts +24 -0
- package/dist/core/utils/file-io.mjs +47 -0
- package/dist/core/utils/imports.d.mts +15 -0
- package/dist/core/utils/imports.mjs +25 -0
- package/dist/core/utils/index.d.mts +7 -0
- package/dist/core/utils/index.mjs +8 -0
- package/dist/core/utils/logger.d.mts +18 -0
- package/dist/core/utils/logger.mjs +38 -0
- package/dist/core/utils/ofetch-templates.d.mts +30 -0
- package/dist/core/utils/ofetch-templates.mjs +135 -0
- package/dist/core/utils/runtime.d.mts +74 -0
- package/dist/core/utils/runtime.mjs +111 -0
- package/dist/core/utils/subscribe-templates.d.mts +8 -0
- package/dist/core/utils/subscribe-templates.mjs +59 -0
- package/dist/core/validation/external-services.d.mts +11 -0
- package/dist/core/validation/external-services.mjs +33 -0
- package/dist/core/validation/index.d.mts +2 -0
- package/dist/core/validation/index.mjs +3 -0
- package/dist/core/watcher/index.d.mts +107 -0
- package/dist/core/watcher/index.mjs +141 -0
- package/dist/define.d.mts +294 -0
- package/dist/define.mjs +325 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.mjs +6 -0
- package/dist/nitro/adapter.d.mts +29 -0
- package/dist/nitro/adapter.mjs +93 -0
- package/dist/{utils/apollo.d.ts → nitro/apollo.d.mts} +3 -3
- package/dist/nitro/apollo.mjs +59 -0
- package/dist/nitro/codegen.d.mts +18 -0
- package/dist/nitro/codegen.mjs +173 -0
- package/dist/nitro/config.d.mts +50 -0
- package/dist/nitro/config.mjs +57 -0
- package/dist/nitro/index.d.mts +45 -0
- package/dist/nitro/index.mjs +65 -0
- package/dist/{utils/path-resolver.d.ts → nitro/paths.d.mts} +8 -25
- package/dist/{utils/path-resolver.js → nitro/paths.mjs} +14 -49
- package/dist/nitro/rollup.d.mts +6 -0
- package/dist/nitro/rollup.mjs +53 -0
- package/dist/nitro/routes/apollo-sandbox-script.d.mts +6 -0
- package/dist/nitro/routes/apollo-sandbox-script.mjs +14 -0
- package/dist/nitro/routes/apollo-server-ws.d.mts +15 -0
- package/dist/nitro/routes/apollo-server-ws.mjs +53 -0
- package/dist/nitro/routes/apollo-server.d.mts +6 -0
- package/dist/nitro/routes/apollo-server.mjs +71 -0
- package/dist/{routes/debug.d.ts → nitro/routes/debug.d.mts} +12 -19
- package/dist/nitro/routes/debug.mjs +102 -0
- package/dist/nitro/routes/graphql-yoga-ws.d.mts +12 -0
- package/dist/nitro/routes/graphql-yoga-ws.mjs +53 -0
- package/dist/nitro/routes/graphql-yoga.d.mts +12 -0
- package/dist/nitro/routes/graphql-yoga.mjs +41 -0
- package/dist/nitro/routes/health.d.mts +10 -0
- package/dist/{routes/health.js → nitro/routes/health.mjs} +4 -3
- package/dist/nitro/setup/extend-loader.d.mts +16 -0
- package/dist/nitro/setup/extend-loader.mjs +82 -0
- package/dist/nitro/setup/file-watcher.d.mts +18 -0
- package/dist/nitro/setup/file-watcher.mjs +63 -0
- package/dist/nitro/setup/logging.d.mts +16 -0
- package/dist/nitro/setup/logging.mjs +66 -0
- package/dist/nitro/setup/rollup-integration.d.mts +24 -0
- package/dist/nitro/setup/rollup-integration.mjs +63 -0
- package/dist/nitro/setup/routes.d.mts +13 -0
- package/dist/nitro/setup/routes.mjs +71 -0
- package/dist/nitro/setup/scanner.d.mts +59 -0
- package/dist/nitro/setup/scanner.mjs +120 -0
- package/dist/nitro/setup/ts-config.d.mts +10 -0
- package/dist/nitro/setup/ts-config.mjs +69 -0
- package/dist/nitro/setup.d.mts +11 -0
- package/dist/nitro/setup.mjs +191 -0
- package/dist/nitro/types.d.mts +549 -0
- package/dist/nitro/types.mjs +1 -0
- package/dist/nitro/virtual/generators.d.mts +38 -0
- package/dist/nitro/virtual/generators.mjs +192 -0
- package/dist/nitro/virtual/stubs.d.mts +21 -0
- package/dist/nitro/virtual/stubs.mjs +32 -0
- package/dist/{ecosystem/nuxt.d.ts → nuxt.d.mts} +1 -1
- package/dist/nuxt.mjs +112 -0
- package/dist/{graphql/server.d.ts → stubs/index.d.mts} +5 -1
- package/dist/stubs/index.mjs +1 -0
- package/dist/subscribe/index.d.mts +78 -0
- package/dist/subscribe/index.mjs +206 -0
- package/native/index.d.ts +20 -0
- package/native/index.js +585 -0
- package/package.json +201 -111
- package/dist/ecosystem/nuxt.js +0 -67
- package/dist/graphql/index.d.ts +0 -5
- package/dist/index.d.ts +0 -8
- package/dist/index.js +0 -318
- package/dist/rollup.js +0 -277
- package/dist/routes/apollo-server.d.ts +0 -6
- package/dist/routes/apollo-server.js +0 -89
- package/dist/routes/debug.js +0 -449
- package/dist/routes/graphql-yoga.d.ts +0 -6
- package/dist/routes/graphql-yoga.js +0 -91
- package/dist/routes/health.d.ts +0 -10
- package/dist/types/index.d.ts +0 -246
- package/dist/types/standard-schema.d.ts +0 -59
- package/dist/utils/apollo.js +0 -61
- package/dist/utils/client-codegen.d.ts +0 -38
- package/dist/utils/client-codegen.js +0 -290
- package/dist/utils/define.js +0 -57
- package/dist/utils/file-generator.d.ts +0 -37
- package/dist/utils/file-generator.js +0 -72
- package/dist/utils/index.d.ts +0 -39
- package/dist/utils/index.js +0 -278
- package/dist/utils/server-codegen.d.ts +0 -7
- package/dist/utils/server-codegen.js +0 -136
- package/dist/utils/type-generation.d.ts +0 -7
- package/dist/utils/type-generation.js +0 -360
- package/dist/virtual/debug-info.d.ts +0 -9
- package/dist/virtual/debug-info.js +0 -26
- package/dist/virtual/graphql-config.d.ts +0 -9
- package/dist/virtual/graphql-config.js +0 -10
- package/dist/virtual/module-config.d.ts +0 -9
- package/dist/virtual/module-config.js +0 -10
- package/dist/virtual/server-directives.d.ts +0 -11
- package/dist/virtual/server-directives.js +0 -10
- package/dist/virtual/server-resolvers.d.ts +0 -11
- package/dist/virtual/server-resolvers.js +0 -10
- package/dist/virtual/server-schemas.d.ts +0 -11
- package/dist/virtual/server-schemas.js +0 -10
- package/dist/vite.d.ts +0 -25
- package/dist/vite.js +0 -40
- /package/dist/{graphql/index.js → core/server/types.mjs} +0 -0
- /package/dist/{graphql/server.js → core/types/adapter.mjs} +0 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { basename, dirname, join, resolve } from "pathe";
|
|
2
|
+
import { existsSync, mkdirSync, promises, readFileSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { pathToFileURL as pathToFileURL$1 } from "node:url";
|
|
4
|
+
|
|
5
|
+
//#region src/core/utils/runtime.ts
|
|
6
|
+
/**
|
|
7
|
+
* Cross-runtime compatibility layer
|
|
8
|
+
*
|
|
9
|
+
* Provides runtime-agnostic file system and process utilities
|
|
10
|
+
* that work across Node.js, Bun, and Deno.
|
|
11
|
+
*/
|
|
12
|
+
const _globalThis = globalThis;
|
|
13
|
+
/**
|
|
14
|
+
* Read file contents asynchronously
|
|
15
|
+
*/
|
|
16
|
+
async function readFile(path) {
|
|
17
|
+
return promises.readFile(path, "utf-8");
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Read file contents synchronously
|
|
21
|
+
*/
|
|
22
|
+
function readFileSync_(path) {
|
|
23
|
+
return readFileSync(path, "utf-8");
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Write file contents asynchronously
|
|
27
|
+
*/
|
|
28
|
+
async function writeFile(path, content) {
|
|
29
|
+
await promises.writeFile(path, content, "utf-8");
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Write file contents synchronously
|
|
33
|
+
*/
|
|
34
|
+
function writeFileSync_(path, content) {
|
|
35
|
+
writeFileSync(path, content, "utf-8");
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Check if file/directory exists asynchronously
|
|
39
|
+
*/
|
|
40
|
+
async function exists(path) {
|
|
41
|
+
try {
|
|
42
|
+
await promises.access(path);
|
|
43
|
+
return true;
|
|
44
|
+
} catch {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Check if file/directory exists synchronously
|
|
50
|
+
*/
|
|
51
|
+
function existsSync_(path) {
|
|
52
|
+
return existsSync(path);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Create directory recursively asynchronously
|
|
56
|
+
*/
|
|
57
|
+
async function mkdir(path) {
|
|
58
|
+
await promises.mkdir(path, { recursive: true });
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Create directory recursively synchronously
|
|
62
|
+
*/
|
|
63
|
+
function mkdirSync_(path) {
|
|
64
|
+
mkdirSync(path, { recursive: true });
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Get current working directory
|
|
68
|
+
* Works across Node.js, Bun, and Deno
|
|
69
|
+
*/
|
|
70
|
+
function getCwd() {
|
|
71
|
+
if (_globalThis.Deno) return _globalThis.Deno.cwd();
|
|
72
|
+
return process.cwd();
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Exit process with code
|
|
76
|
+
* Works across Node.js, Bun, and Deno
|
|
77
|
+
*/
|
|
78
|
+
function exit(code) {
|
|
79
|
+
if (_globalThis.Deno) _globalThis.Deno.exit(code);
|
|
80
|
+
process.exit(code);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Convert file path to file URL
|
|
84
|
+
* Works across Node.js, Bun, and Deno
|
|
85
|
+
*/
|
|
86
|
+
function pathToFileURL(path) {
|
|
87
|
+
return pathToFileURL$1(path);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Register signal handler (SIGINT, SIGTERM, etc.)
|
|
91
|
+
* Works across Node.js, Bun, and Deno
|
|
92
|
+
*/
|
|
93
|
+
function onSignal(signal, handler) {
|
|
94
|
+
if (_globalThis.Deno) _globalThis.Deno.addSignalListener(signal, handler);
|
|
95
|
+
else process.on(signal, handler);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Read directory contents
|
|
99
|
+
*/
|
|
100
|
+
async function readdir(path) {
|
|
101
|
+
return promises.readdir(path);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Get file/directory stats
|
|
105
|
+
*/
|
|
106
|
+
async function stat(path) {
|
|
107
|
+
return promises.stat(path);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
//#endregion
|
|
111
|
+
export { basename, dirname, exists, existsSync_, exit, getCwd, join, mkdir, mkdirSync_, onSignal, pathToFileURL, readFile, readFileSync_, readdir, resolve, stat, writeFile, writeFileSync_ };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
//#region src/core/utils/subscribe-templates.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Template for GraphQL subscription client config
|
|
4
|
+
* Small config file that users can customize (like ofetch.ts pattern)
|
|
5
|
+
*/
|
|
6
|
+
declare const subscribeClientTemplate = "// This file is auto-generated once by nitro-graphql for quick start\n// You can modify this file to customize the subscription client\n// The implementation comes from nitro-graphql/subscribe - you'll get updates automatically!\n//\n// Usage Examples:\n// ---------------\n// Basic subscription:\n// subscriptionClient.subscribe(query, variables, onData, onError)\n//\n// Multiplexed subscriptions (shared connection):\n// const session = subscriptionClient.createSession()\n// session.subscribe(query1, vars1, onData1)\n// session.subscribe(query2, vars2, onData2)\n//\n// With authentication:\n// Edit connectionParams below to add auth headers\n\nimport type {\n ConnectionState,\n SubscriptionClient,\n SubscriptionClientConfig,\n SubscriptionHandle,\n SubscriptionSession,\n} from 'nitro-graphql/subscribe'\nimport { createSubscriptionClient } from 'nitro-graphql/subscribe'\n\n// Re-export types for convenience\nexport type { ConnectionState, SubscriptionClient, SubscriptionHandle, SubscriptionSession }\n\n// Configure the subscription client\n// Customize these settings according to your needs\nconst config: SubscriptionClientConfig = {\n // WebSocket endpoint (default: '/api/graphql/ws')\n wsEndpoint: '/api/graphql/ws',\n\n // Connection timeout in ms (default: 10000)\n connectionTimeoutMs: 10000,\n\n // Max reconnection attempts (default: 5)\n maxRetries: 5,\n\n // Authentication params sent with connection_init\n // Can be a function for dynamic values (e.g., JWT tokens)\n // connectionParams: () => ({\n // authorization: `Bearer ${getToken()}`,\n // }),\n}\n\n// Export configured client instance\nexport const subscriptionClient = createSubscriptionClient(config)\n";
|
|
7
|
+
//#endregion
|
|
8
|
+
export { subscribeClientTemplate };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
//#region src/core/utils/subscribe-templates.ts
|
|
2
|
+
/**
|
|
3
|
+
* Template for GraphQL subscription client config
|
|
4
|
+
* Small config file that users can customize (like ofetch.ts pattern)
|
|
5
|
+
*/
|
|
6
|
+
const subscribeClientTemplate = `// This file is auto-generated once by nitro-graphql for quick start
|
|
7
|
+
// You can modify this file to customize the subscription client
|
|
8
|
+
// The implementation comes from nitro-graphql/subscribe - you'll get updates automatically!
|
|
9
|
+
//
|
|
10
|
+
// Usage Examples:
|
|
11
|
+
// ---------------
|
|
12
|
+
// Basic subscription:
|
|
13
|
+
// subscriptionClient.subscribe(query, variables, onData, onError)
|
|
14
|
+
//
|
|
15
|
+
// Multiplexed subscriptions (shared connection):
|
|
16
|
+
// const session = subscriptionClient.createSession()
|
|
17
|
+
// session.subscribe(query1, vars1, onData1)
|
|
18
|
+
// session.subscribe(query2, vars2, onData2)
|
|
19
|
+
//
|
|
20
|
+
// With authentication:
|
|
21
|
+
// Edit connectionParams below to add auth headers
|
|
22
|
+
|
|
23
|
+
import type {
|
|
24
|
+
ConnectionState,
|
|
25
|
+
SubscriptionClient,
|
|
26
|
+
SubscriptionClientConfig,
|
|
27
|
+
SubscriptionHandle,
|
|
28
|
+
SubscriptionSession,
|
|
29
|
+
} from 'nitro-graphql/subscribe'
|
|
30
|
+
import { createSubscriptionClient } from 'nitro-graphql/subscribe'
|
|
31
|
+
|
|
32
|
+
// Re-export types for convenience
|
|
33
|
+
export type { ConnectionState, SubscriptionClient, SubscriptionHandle, SubscriptionSession }
|
|
34
|
+
|
|
35
|
+
// Configure the subscription client
|
|
36
|
+
// Customize these settings according to your needs
|
|
37
|
+
const config: SubscriptionClientConfig = {
|
|
38
|
+
// WebSocket endpoint (default: '/api/graphql/ws')
|
|
39
|
+
wsEndpoint: '/api/graphql/ws',
|
|
40
|
+
|
|
41
|
+
// Connection timeout in ms (default: 10000)
|
|
42
|
+
connectionTimeoutMs: 10000,
|
|
43
|
+
|
|
44
|
+
// Max reconnection attempts (default: 5)
|
|
45
|
+
maxRetries: 5,
|
|
46
|
+
|
|
47
|
+
// Authentication params sent with connection_init
|
|
48
|
+
// Can be a function for dynamic values (e.g., JWT tokens)
|
|
49
|
+
// connectionParams: () => ({
|
|
50
|
+
// authorization: \`Bearer \${getToken()}\`,
|
|
51
|
+
// }),
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Export configured client instance
|
|
55
|
+
export const subscriptionClient = createSubscriptionClient(config)
|
|
56
|
+
`;
|
|
57
|
+
|
|
58
|
+
//#endregion
|
|
59
|
+
export { subscribeClientTemplate };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/core/validation/external-services.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* External services validation utilities
|
|
4
|
+
* Framework-agnostic validation helpers
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Validate external GraphQL service configuration
|
|
8
|
+
*/
|
|
9
|
+
declare function validateExternalServices(services: unknown[]): string[];
|
|
10
|
+
//#endregion
|
|
11
|
+
export { validateExternalServices };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
//#region src/core/validation/external-services.ts
|
|
2
|
+
/**
|
|
3
|
+
* External services validation utilities
|
|
4
|
+
* Framework-agnostic validation helpers
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Validate external GraphQL service configuration
|
|
8
|
+
*/
|
|
9
|
+
function validateExternalServices(services) {
|
|
10
|
+
const errors = [];
|
|
11
|
+
const serviceNames = /* @__PURE__ */ new Set();
|
|
12
|
+
for (const [index, service] of services.entries()) {
|
|
13
|
+
const prefix = `externalServices[${index}]`;
|
|
14
|
+
if (!service || typeof service !== "object") {
|
|
15
|
+
errors.push(`${prefix} must be an object`);
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
if (!("name" in service) || typeof service.name !== "string") errors.push(`${prefix}.name is required and must be a string`);
|
|
19
|
+
else if (serviceNames.has(service.name)) errors.push(`${prefix}.name "${service.name}" must be unique`);
|
|
20
|
+
else serviceNames.add(service.name);
|
|
21
|
+
if (!("endpoint" in service) || typeof service.endpoint !== "string") errors.push(`${prefix}.endpoint is required and must be a string`);
|
|
22
|
+
else try {
|
|
23
|
+
new URL(service.endpoint);
|
|
24
|
+
} catch {
|
|
25
|
+
errors.push(`${prefix}.endpoint "${service.endpoint}" must be a valid URL`);
|
|
26
|
+
}
|
|
27
|
+
if ("name" in service && typeof service.name === "string" && !/^[a-z]\w*$/i.test(service.name)) errors.push(`${prefix}.name "${service.name}" must be a valid identifier (letters, numbers, underscore, starting with letter)`);
|
|
28
|
+
}
|
|
29
|
+
return errors;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
export { validateExternalServices };
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { FSWatcher } from "chokidar";
|
|
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 };
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { DIRECTIVE_EXTENSIONS, GRAPHQL_EXTENSIONS, RESOLVER_EXTENSIONS } from "../constants.mjs";
|
|
2
|
+
import { watch } from "chokidar";
|
|
3
|
+
import { debounce } from "perfect-debounce";
|
|
4
|
+
|
|
5
|
+
//#region src/core/watcher/index.ts
|
|
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(/\\/g, "/");
|
|
30
|
+
const normalizedServerDir = serverDir.replace(/\\/g, "/");
|
|
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
|
+
|
|
140
|
+
//#endregion
|
|
141
|
+
export { classifyChange, closeWatcher, createCoreWatcher, createIgnoredFunction, getFileType, isWatchableFile, shouldSkipPath };
|