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.
Files changed (239) hide show
  1. package/README.md +31 -1196
  2. package/dist/cli/adapter.d.mts +13 -0
  3. package/dist/cli/adapter.mjs +69 -0
  4. package/dist/cli/commands/build.d.mts +21 -0
  5. package/dist/cli/commands/build.mjs +52 -0
  6. package/dist/cli/commands/dev.d.mts +40 -0
  7. package/dist/cli/commands/dev.mjs +76 -0
  8. package/dist/cli/commands/generate.d.mts +25 -0
  9. package/dist/cli/commands/generate.mjs +198 -0
  10. package/dist/cli/commands/index.d.mts +5 -0
  11. package/dist/cli/commands/index.mjs +6 -0
  12. package/dist/cli/commands/init.d.mts +45 -0
  13. package/dist/cli/commands/init.mjs +195 -0
  14. package/dist/cli/commands/validate.d.mts +9 -0
  15. package/dist/cli/commands/validate.mjs +67 -0
  16. package/dist/cli/completions.d.mts +6 -0
  17. package/dist/cli/completions.mjs +34 -0
  18. package/dist/cli/config.d.mts +18 -0
  19. package/dist/cli/config.mjs +20 -0
  20. package/dist/cli/index.d.mts +26 -0
  21. package/dist/cli/index.mjs +317 -0
  22. package/dist/cli/server/debug-handler.d.mts +9 -0
  23. package/dist/cli/server/debug-handler.mjs +71 -0
  24. package/dist/cli/server/dev-server.d.mts +29 -0
  25. package/dist/cli/server/dev-server.mjs +64 -0
  26. package/dist/cli/server/graphql-handler.d.mts +21 -0
  27. package/dist/cli/server/graphql-handler.mjs +45 -0
  28. package/dist/cli/server/health-handler.d.mts +12 -0
  29. package/dist/cli/server/health-handler.mjs +30 -0
  30. package/dist/cli/server/loader.d.mts +33 -0
  31. package/dist/cli/server/loader.mjs +146 -0
  32. package/dist/cli/server/sandbox-handler.d.mts +12 -0
  33. package/dist/cli/server/sandbox-handler.mjs +19 -0
  34. package/dist/cli/server/watcher.d.mts +20 -0
  35. package/dist/cli/server/watcher.mjs +66 -0
  36. package/dist/cli/server/ws-handler.d.mts +28 -0
  37. package/dist/cli/server/ws-handler.mjs +50 -0
  38. package/dist/config.d.mts +2 -0
  39. package/dist/config.mjs +3 -0
  40. package/dist/core/codegen/client.d.mts +42 -0
  41. package/dist/core/codegen/client.mjs +553 -0
  42. package/dist/core/codegen/document-loader.d.mts +9 -0
  43. package/dist/core/codegen/document-loader.mjs +18 -0
  44. package/dist/core/codegen/index.d.mts +8 -0
  45. package/dist/core/codegen/index.mjs +9 -0
  46. package/dist/core/codegen/plugin.d.mts +19 -0
  47. package/dist/core/codegen/plugin.mjs +30 -0
  48. package/dist/core/codegen/runtime.d.mts +19 -0
  49. package/dist/core/codegen/runtime.mjs +60 -0
  50. package/dist/core/codegen/schema-loader.d.mts +27 -0
  51. package/dist/core/codegen/schema-loader.mjs +128 -0
  52. package/dist/core/codegen/server.d.mts +27 -0
  53. package/dist/core/codegen/server.mjs +144 -0
  54. package/dist/core/codegen/validation.d.mts +17 -0
  55. package/dist/core/codegen/validation.mjs +35 -0
  56. package/dist/core/config.d.mts +45 -0
  57. package/dist/core/config.mjs +78 -0
  58. package/dist/core/constants.d.mts +188 -0
  59. package/dist/core/constants.mjs +210 -0
  60. package/dist/core/debug/index.d.mts +2 -0
  61. package/dist/core/debug/index.mjs +3 -0
  62. package/dist/core/debug/template.d.mts +52 -0
  63. package/dist/core/debug/template.mjs +383 -0
  64. package/dist/core/extend/index.d.mts +2 -0
  65. package/dist/core/extend/index.mjs +3 -0
  66. package/dist/core/extend/loader.d.mts +40 -0
  67. package/dist/core/extend/loader.mjs +198 -0
  68. package/dist/core/index.d.mts +37 -0
  69. package/dist/core/index.mjs +29 -0
  70. package/dist/core/manifest.d.mts +56 -0
  71. package/dist/core/manifest.mjs +102 -0
  72. package/dist/core/pubsub/index.d.mts +109 -0
  73. package/dist/core/pubsub/index.mjs +148 -0
  74. package/dist/core/scanning/ast-scanner.d.mts +27 -0
  75. package/dist/core/scanning/ast-scanner.mjs +116 -0
  76. package/dist/core/scanning/common.d.mts +25 -0
  77. package/dist/core/scanning/common.mjs +59 -0
  78. package/dist/core/scanning/directives.d.mts +13 -0
  79. package/dist/core/scanning/directives.mjs +29 -0
  80. package/dist/core/scanning/documents.d.mts +20 -0
  81. package/dist/core/scanning/documents.mjs +37 -0
  82. package/dist/core/scanning/index.d.mts +7 -0
  83. package/dist/core/scanning/index.mjs +8 -0
  84. package/dist/core/scanning/resolvers.d.mts +14 -0
  85. package/dist/core/scanning/resolvers.mjs +59 -0
  86. package/dist/core/scanning/schemas.d.mts +13 -0
  87. package/dist/core/scanning/schemas.mjs +52 -0
  88. package/dist/core/schema/builder.d.mts +59 -0
  89. package/dist/core/schema/builder.mjs +78 -0
  90. package/dist/core/schema/federation.d.mts +33 -0
  91. package/dist/core/schema/federation.mjs +40 -0
  92. package/dist/core/schema/index.d.mts +3 -0
  93. package/dist/core/schema/index.mjs +4 -0
  94. package/dist/core/server/index.d.mts +4 -0
  95. package/dist/core/server/index.mjs +4 -0
  96. package/dist/core/server/sandbox.d.mts +18 -0
  97. package/dist/core/server/sandbox.mjs +39 -0
  98. package/dist/core/server/types.d.mts +54 -0
  99. package/dist/core/server/yoga.d.mts +42 -0
  100. package/dist/core/server/yoga.mjs +89 -0
  101. package/dist/core/types/adapter.d.mts +57 -0
  102. package/dist/core/types/codegen.d.mts +136 -0
  103. package/dist/core/types/codegen.mjs +1 -0
  104. package/dist/core/types/config.d.mts +188 -0
  105. package/dist/core/types/config.mjs +1 -0
  106. package/dist/{utils/define.d.ts → core/types/define.d.mts} +2 -30
  107. package/dist/core/types/define.mjs +1 -0
  108. package/dist/core/types/index.d.mts +5 -0
  109. package/dist/core/types/index.mjs +1 -0
  110. package/dist/core/types/scanning.d.mts +64 -0
  111. package/dist/core/types/scanning.mjs +1 -0
  112. package/dist/{utils/directive-parser.d.ts → core/utils/directive-parser.d.mts} +18 -4
  113. package/dist/{utils/directive-parser.js → core/utils/directive-parser.mjs} +28 -34
  114. package/dist/core/utils/errors.d.mts +77 -0
  115. package/dist/core/utils/errors.mjs +93 -0
  116. package/dist/core/utils/file-io.d.mts +24 -0
  117. package/dist/core/utils/file-io.mjs +47 -0
  118. package/dist/core/utils/imports.d.mts +15 -0
  119. package/dist/core/utils/imports.mjs +25 -0
  120. package/dist/core/utils/index.d.mts +7 -0
  121. package/dist/core/utils/index.mjs +8 -0
  122. package/dist/core/utils/logger.d.mts +18 -0
  123. package/dist/core/utils/logger.mjs +38 -0
  124. package/dist/core/utils/ofetch-templates.d.mts +30 -0
  125. package/dist/core/utils/ofetch-templates.mjs +135 -0
  126. package/dist/core/utils/runtime.d.mts +74 -0
  127. package/dist/core/utils/runtime.mjs +111 -0
  128. package/dist/core/utils/subscribe-templates.d.mts +8 -0
  129. package/dist/core/utils/subscribe-templates.mjs +59 -0
  130. package/dist/core/validation/external-services.d.mts +11 -0
  131. package/dist/core/validation/external-services.mjs +33 -0
  132. package/dist/core/validation/index.d.mts +2 -0
  133. package/dist/core/validation/index.mjs +3 -0
  134. package/dist/core/watcher/index.d.mts +107 -0
  135. package/dist/core/watcher/index.mjs +141 -0
  136. package/dist/define.d.mts +294 -0
  137. package/dist/define.mjs +325 -0
  138. package/dist/index.d.mts +6 -0
  139. package/dist/index.mjs +6 -0
  140. package/dist/nitro/adapter.d.mts +29 -0
  141. package/dist/nitro/adapter.mjs +93 -0
  142. package/dist/{utils/apollo.d.ts → nitro/apollo.d.mts} +3 -3
  143. package/dist/nitro/apollo.mjs +59 -0
  144. package/dist/nitro/codegen.d.mts +18 -0
  145. package/dist/nitro/codegen.mjs +173 -0
  146. package/dist/nitro/config.d.mts +50 -0
  147. package/dist/nitro/config.mjs +57 -0
  148. package/dist/nitro/index.d.mts +45 -0
  149. package/dist/nitro/index.mjs +65 -0
  150. package/dist/{utils/path-resolver.d.ts → nitro/paths.d.mts} +8 -25
  151. package/dist/{utils/path-resolver.js → nitro/paths.mjs} +14 -49
  152. package/dist/nitro/rollup.d.mts +6 -0
  153. package/dist/nitro/rollup.mjs +53 -0
  154. package/dist/nitro/routes/apollo-sandbox-script.d.mts +6 -0
  155. package/dist/nitro/routes/apollo-sandbox-script.mjs +14 -0
  156. package/dist/nitro/routes/apollo-server-ws.d.mts +15 -0
  157. package/dist/nitro/routes/apollo-server-ws.mjs +53 -0
  158. package/dist/nitro/routes/apollo-server.d.mts +6 -0
  159. package/dist/nitro/routes/apollo-server.mjs +71 -0
  160. package/dist/{routes/debug.d.ts → nitro/routes/debug.d.mts} +12 -19
  161. package/dist/nitro/routes/debug.mjs +102 -0
  162. package/dist/nitro/routes/graphql-yoga-ws.d.mts +12 -0
  163. package/dist/nitro/routes/graphql-yoga-ws.mjs +53 -0
  164. package/dist/nitro/routes/graphql-yoga.d.mts +12 -0
  165. package/dist/nitro/routes/graphql-yoga.mjs +41 -0
  166. package/dist/nitro/routes/health.d.mts +10 -0
  167. package/dist/{routes/health.js → nitro/routes/health.mjs} +4 -3
  168. package/dist/nitro/setup/extend-loader.d.mts +16 -0
  169. package/dist/nitro/setup/extend-loader.mjs +82 -0
  170. package/dist/nitro/setup/file-watcher.d.mts +18 -0
  171. package/dist/nitro/setup/file-watcher.mjs +63 -0
  172. package/dist/nitro/setup/logging.d.mts +16 -0
  173. package/dist/nitro/setup/logging.mjs +66 -0
  174. package/dist/nitro/setup/rollup-integration.d.mts +24 -0
  175. package/dist/nitro/setup/rollup-integration.mjs +63 -0
  176. package/dist/nitro/setup/routes.d.mts +13 -0
  177. package/dist/nitro/setup/routes.mjs +71 -0
  178. package/dist/nitro/setup/scanner.d.mts +59 -0
  179. package/dist/nitro/setup/scanner.mjs +120 -0
  180. package/dist/nitro/setup/ts-config.d.mts +10 -0
  181. package/dist/nitro/setup/ts-config.mjs +69 -0
  182. package/dist/nitro/setup.d.mts +11 -0
  183. package/dist/nitro/setup.mjs +191 -0
  184. package/dist/nitro/types.d.mts +549 -0
  185. package/dist/nitro/types.mjs +1 -0
  186. package/dist/nitro/virtual/generators.d.mts +38 -0
  187. package/dist/nitro/virtual/generators.mjs +192 -0
  188. package/dist/nitro/virtual/stubs.d.mts +21 -0
  189. package/dist/nitro/virtual/stubs.mjs +32 -0
  190. package/dist/{ecosystem/nuxt.d.ts → nuxt.d.mts} +1 -1
  191. package/dist/nuxt.mjs +112 -0
  192. package/dist/{graphql/server.d.ts → stubs/index.d.mts} +5 -1
  193. package/dist/stubs/index.mjs +1 -0
  194. package/dist/subscribe/index.d.mts +78 -0
  195. package/dist/subscribe/index.mjs +206 -0
  196. package/native/index.d.ts +20 -0
  197. package/native/index.js +585 -0
  198. package/package.json +201 -111
  199. package/dist/ecosystem/nuxt.js +0 -67
  200. package/dist/graphql/index.d.ts +0 -5
  201. package/dist/index.d.ts +0 -8
  202. package/dist/index.js +0 -318
  203. package/dist/rollup.js +0 -277
  204. package/dist/routes/apollo-server.d.ts +0 -6
  205. package/dist/routes/apollo-server.js +0 -89
  206. package/dist/routes/debug.js +0 -449
  207. package/dist/routes/graphql-yoga.d.ts +0 -6
  208. package/dist/routes/graphql-yoga.js +0 -91
  209. package/dist/routes/health.d.ts +0 -10
  210. package/dist/types/index.d.ts +0 -246
  211. package/dist/types/standard-schema.d.ts +0 -59
  212. package/dist/utils/apollo.js +0 -61
  213. package/dist/utils/client-codegen.d.ts +0 -38
  214. package/dist/utils/client-codegen.js +0 -290
  215. package/dist/utils/define.js +0 -57
  216. package/dist/utils/file-generator.d.ts +0 -37
  217. package/dist/utils/file-generator.js +0 -72
  218. package/dist/utils/index.d.ts +0 -39
  219. package/dist/utils/index.js +0 -278
  220. package/dist/utils/server-codegen.d.ts +0 -7
  221. package/dist/utils/server-codegen.js +0 -136
  222. package/dist/utils/type-generation.d.ts +0 -7
  223. package/dist/utils/type-generation.js +0 -360
  224. package/dist/virtual/debug-info.d.ts +0 -9
  225. package/dist/virtual/debug-info.js +0 -26
  226. package/dist/virtual/graphql-config.d.ts +0 -9
  227. package/dist/virtual/graphql-config.js +0 -10
  228. package/dist/virtual/module-config.d.ts +0 -9
  229. package/dist/virtual/module-config.js +0 -10
  230. package/dist/virtual/server-directives.d.ts +0 -11
  231. package/dist/virtual/server-directives.js +0 -10
  232. package/dist/virtual/server-resolvers.d.ts +0 -11
  233. package/dist/virtual/server-resolvers.js +0 -10
  234. package/dist/virtual/server-schemas.d.ts +0 -11
  235. package/dist/virtual/server-schemas.js +0 -10
  236. package/dist/vite.d.ts +0 -25
  237. package/dist/vite.js +0 -40
  238. /package/dist/{graphql/index.js → core/server/types.mjs} +0 -0
  239. /package/dist/{graphql/server.js → core/types/adapter.mjs} +0 -0
@@ -0,0 +1,13 @@
1
+ import { FrameworkAdapter } from "../core/types/adapter.mjs";
2
+ import { CLIContext } from "./index.mjs";
3
+
4
+ //#region src/cli/adapter.d.ts
5
+ /**
6
+ * CLI Framework Adapter
7
+ *
8
+ * Enables the CLI to use the same core functions as the Nitro module.
9
+ * The adapter converts CLIContext to the types expected by core functions.
10
+ */
11
+ declare const CLIAdapter: FrameworkAdapter<CLIContext>;
12
+ //#endregion
13
+ export { CLIAdapter };
@@ -0,0 +1,69 @@
1
+ import { LOG_TAG } from "../core/constants.mjs";
2
+ import { createCoreConfig, createCoreContext, createScanContext } from "../core/config.mjs";
3
+ import consola from "consola";
4
+
5
+ //#region src/cli/adapter.ts
6
+ /**
7
+ * Create a CoreLogger from consola for CLI usage
8
+ */
9
+ function createCLILogger() {
10
+ const logger = consola.withTag(LOG_TAG);
11
+ return {
12
+ info: (...args) => logger.info(...args),
13
+ warn: (...args) => logger.warn(...args),
14
+ error: (...args) => logger.error(...args),
15
+ debug: (...args) => logger.debug(...args),
16
+ success: (...args) => logger.success(...args)
17
+ };
18
+ }
19
+ /**
20
+ * CLI Framework Adapter
21
+ *
22
+ * Enables the CLI to use the same core functions as the Nitro module.
23
+ * The adapter converts CLIContext to the types expected by core functions.
24
+ */
25
+ const CLIAdapter = {
26
+ name: "cli",
27
+ createCoreConfig: (ctx) => {
28
+ return createCoreConfig({
29
+ rootDir: ctx.config.rootDir,
30
+ buildDir: ctx.config.buildDir,
31
+ serverDir: ctx.config.serverDir,
32
+ clientDir: ctx.config.clientDir,
33
+ isNuxt: false,
34
+ isDev: true,
35
+ graphqlOptions: {
36
+ framework: ctx.config.framework,
37
+ endpoint: ctx.config.endpoint?.graphql,
38
+ security: ctx.config.security,
39
+ federation: ctx.config.federation,
40
+ externalServices: ctx.config.externalServices?.map((s) => ({
41
+ name: s.name,
42
+ endpoint: s.endpoint,
43
+ schema: (Array.isArray(s.schema) ? s.schema[0] : s.schema) || s.endpoint,
44
+ headers: s.headers,
45
+ documents: s.documents,
46
+ paths: s.paths ? {
47
+ sdk: typeof s.paths.sdk === "string" ? s.paths.sdk : void 0,
48
+ types: typeof s.paths.types === "string" ? s.paths.types : void 0
49
+ } : void 0
50
+ })),
51
+ codegen: ctx.config.codegen
52
+ },
53
+ logger: createCLILogger(),
54
+ ignorePatterns: ctx.config.ignore || []
55
+ });
56
+ },
57
+ createCoreContext: (ctx) => {
58
+ return createCoreContext(CLIAdapter.createCoreConfig(ctx));
59
+ },
60
+ createScanContext: (ctx) => {
61
+ return createScanContext(CLIAdapter.createCoreConfig(ctx));
62
+ },
63
+ getLogger: () => {
64
+ return createCLILogger();
65
+ }
66
+ };
67
+
68
+ //#endregion
69
+ export { CLIAdapter };
@@ -0,0 +1,21 @@
1
+ import * as citty0 from "citty";
2
+
3
+ //#region src/cli/commands/build.d.ts
4
+ /**
5
+ * CLI Build Command
6
+ *
7
+ * Builds GraphQL types and validates schemas for production.
8
+ */
9
+ declare const buildCommand: citty0.CommandDef<{
10
+ readonly cwd: {
11
+ readonly type: "string";
12
+ readonly description: "Working directory";
13
+ };
14
+ readonly skipValidation: {
15
+ readonly type: "boolean";
16
+ readonly description: "Skip schema validation";
17
+ readonly default: false;
18
+ };
19
+ }>;
20
+ //#endregion
21
+ export { buildCommand };
@@ -0,0 +1,52 @@
1
+ import { createCLIContext } from "../index.mjs";
2
+ import { generateAll } from "./generate.mjs";
3
+ import { validate } from "./validate.mjs";
4
+ import consola from "consola";
5
+ import { defineCommand } from "citty";
6
+
7
+ //#region src/cli/commands/build.ts
8
+ /**
9
+ * CLI Build Command
10
+ *
11
+ * Builds GraphQL types and validates schemas for production.
12
+ */
13
+ const logger = consola.withTag("nitro-graphql");
14
+ const buildCommand = defineCommand({
15
+ meta: {
16
+ name: "build",
17
+ description: "Build GraphQL types for production"
18
+ },
19
+ args: {
20
+ cwd: {
21
+ type: "string",
22
+ description: "Working directory"
23
+ },
24
+ skipValidation: {
25
+ type: "boolean",
26
+ description: "Skip schema validation",
27
+ default: false
28
+ }
29
+ },
30
+ async run({ args }) {
31
+ const ctx = await createCLIContext({ cwd: args.cwd });
32
+ logger.info("Building GraphQL for production...");
33
+ if (!args.skipValidation) {
34
+ logger.info("Validating schemas...");
35
+ if (!await validate(ctx)) {
36
+ logger.error("Schema validation failed!");
37
+ process.exit(1);
38
+ }
39
+ logger.success("Schema validation passed");
40
+ }
41
+ logger.info("Generating types...");
42
+ await generateAll(ctx, {
43
+ silent: false,
44
+ runtime: true
45
+ });
46
+ logger.success("Build complete!");
47
+ logger.info(`Output: ${ctx.config.buildDir}`);
48
+ }
49
+ });
50
+
51
+ //#endregion
52
+ export { buildCommand };
@@ -0,0 +1,40 @@
1
+ import * as citty0 from "citty";
2
+
3
+ //#region src/cli/commands/dev.d.ts
4
+ /**
5
+ * Dev Command
6
+ *
7
+ * Starts the GraphQL development server with hot reload.
8
+ * Runtime-agnostic: works on Node.js, Bun, and Deno.
9
+ */
10
+ declare const devCommand: citty0.CommandDef<{
11
+ readonly cwd: {
12
+ readonly type: "string";
13
+ readonly description: "Working directory";
14
+ };
15
+ readonly port: {
16
+ readonly type: "string";
17
+ readonly alias: "p";
18
+ readonly default: "4000";
19
+ readonly description: "Server port";
20
+ };
21
+ readonly host: {
22
+ readonly type: "string";
23
+ readonly alias: "H";
24
+ readonly default: "localhost";
25
+ readonly description: "Server host";
26
+ };
27
+ readonly open: {
28
+ readonly type: "boolean";
29
+ readonly alias: "o";
30
+ readonly description: "Open browser";
31
+ };
32
+ readonly watch: {
33
+ readonly type: "boolean";
34
+ readonly alias: "w";
35
+ readonly default: true;
36
+ readonly description: "Enable file watching for hot reload";
37
+ };
38
+ }>;
39
+ //#endregion
40
+ export { devCommand };
@@ -0,0 +1,76 @@
1
+ import { exit, onSignal } from "../../core/utils/runtime.mjs";
2
+ import { createCLIContext } from "../index.mjs";
3
+ import { startDevServer } from "../server/dev-server.mjs";
4
+ import { createDevWatcher } from "../server/watcher.mjs";
5
+ import consola from "consola";
6
+ import { defineCommand } from "citty";
7
+
8
+ //#region src/cli/commands/dev.ts
9
+ /**
10
+ * Dev Command
11
+ *
12
+ * Starts the GraphQL development server with hot reload.
13
+ * Runtime-agnostic: works on Node.js, Bun, and Deno.
14
+ */
15
+ const logger = consola.withTag("nitro-graphql");
16
+ const devCommand = defineCommand({
17
+ meta: {
18
+ name: "dev",
19
+ description: "Start GraphQL development server"
20
+ },
21
+ args: {
22
+ cwd: {
23
+ type: "string",
24
+ description: "Working directory"
25
+ },
26
+ port: {
27
+ type: "string",
28
+ alias: "p",
29
+ default: "4000",
30
+ description: "Server port"
31
+ },
32
+ host: {
33
+ type: "string",
34
+ alias: "H",
35
+ default: "localhost",
36
+ description: "Server host"
37
+ },
38
+ open: {
39
+ type: "boolean",
40
+ alias: "o",
41
+ description: "Open browser"
42
+ },
43
+ watch: {
44
+ type: "boolean",
45
+ alias: "w",
46
+ default: true,
47
+ description: "Enable file watching for hot reload"
48
+ }
49
+ },
50
+ async run({ args }) {
51
+ const ctx = await createCLIContext({ cwd: args.cwd });
52
+ const serverInstance = await startDevServer(ctx, {
53
+ port: Number.parseInt(args.port),
54
+ hostname: args.host,
55
+ open: args.open
56
+ });
57
+ let watcher = null;
58
+ if (args.watch) {
59
+ watcher = createDevWatcher(ctx, async () => {
60
+ await serverInstance.reload();
61
+ });
62
+ logger.info("File watching enabled - changes will trigger hot reload");
63
+ }
64
+ const shutdown = async () => {
65
+ logger.info("Shutting down...");
66
+ if (watcher) await watcher.close();
67
+ await serverInstance.close();
68
+ exit(0);
69
+ };
70
+ onSignal("SIGINT", shutdown);
71
+ onSignal("SIGTERM", shutdown);
72
+ }
73
+ });
74
+
75
+ //#endregion
76
+ export { devCommand };
@@ -0,0 +1,25 @@
1
+ import { CLIContext } from "../index.mjs";
2
+
3
+ //#region src/cli/commands/generate.d.ts
4
+ /**
5
+ * Generate all types (server + client + optional runtime)
6
+ */
7
+ declare function generateAll(ctx: CLIContext, options?: {
8
+ silent?: boolean;
9
+ watch?: boolean;
10
+ runtime?: boolean;
11
+ }): Promise<void>;
12
+ /**
13
+ * Generate server types
14
+ */
15
+ declare function generateServer(ctx: CLIContext, options?: {
16
+ silent?: boolean;
17
+ }): Promise<void>;
18
+ /**
19
+ * Generate client types
20
+ */
21
+ declare function generateClient(ctx: CLIContext, options?: {
22
+ silent?: boolean;
23
+ }): Promise<void>;
24
+ //#endregion
25
+ export { generateAll, generateClient, generateServer };
@@ -0,0 +1,198 @@
1
+ import { LOG_TAG } from "../../core/constants.mjs";
2
+ import { loadGraphQLDocuments } from "../../core/codegen/document-loader.mjs";
3
+ import { generateClientTypesCore } from "../../core/codegen/client.mjs";
4
+ import { generateResolverModule, generateRuntimeIndex, generateSchemaModule } from "../../core/codegen/runtime.mjs";
5
+ import { generateServerTypesCore } from "../../core/codegen/server.mjs";
6
+ import { scanDocumentsCore } from "../../core/scanning/documents.mjs";
7
+ import { scanResolversCore } from "../../core/scanning/resolvers.mjs";
8
+ import { scanSchemasCore } from "../../core/scanning/schemas.mjs";
9
+ import { buildGraphQLSchema } from "../../core/schema/builder.mjs";
10
+ import { existsSync_, mkdirSync_, onSignal, readFileSync_, writeFileSync_ } from "../../core/utils/runtime.mjs";
11
+ import consola from "consola";
12
+ import { dirname, join, relative, resolve as resolve$1 } from "pathe";
13
+
14
+ //#region src/cli/commands/generate.ts
15
+ const logger = consola.withTag(LOG_TAG);
16
+ /**
17
+ * Create ScanContext from CLI context
18
+ */
19
+ function createScanContext(ctx) {
20
+ return {
21
+ rootDir: ctx.config.rootDir,
22
+ serverDir: ctx.config.serverDir,
23
+ clientDir: ctx.config.clientDir,
24
+ ignorePatterns: ctx.config.ignore,
25
+ isDev: false,
26
+ logger: {
27
+ info: (msg, ...args) => logger.info(msg, ...args),
28
+ warn: (msg, ...args) => logger.warn(msg, ...args),
29
+ error: (msg, ...args) => logger.error(msg, ...args),
30
+ success: (msg, ...args) => logger.success(msg, ...args),
31
+ debug: (msg, ...args) => logger.debug(msg, ...args)
32
+ }
33
+ };
34
+ }
35
+ /**
36
+ * Generate all types (server + client + optional runtime)
37
+ */
38
+ async function generateAll(ctx, options = {}) {
39
+ await generateServer(ctx, options);
40
+ await generateClient(ctx, options);
41
+ if (options.runtime) await generateRuntimeFiles(ctx, options);
42
+ if (options.watch) await watchAndRegenerate(ctx, options);
43
+ }
44
+ /**
45
+ * Generate server types
46
+ */
47
+ async function generateServer(ctx, options = {}) {
48
+ const schemaResult = await scanSchemasCore(createScanContext(ctx));
49
+ if (schemaResult.errors.length > 0) for (const error of schemaResult.errors) logger.error(error);
50
+ if (schemaResult.items.length === 0) {
51
+ if (!options.silent) logger.info("No GraphQL schemas found in server directory");
52
+ return;
53
+ }
54
+ const schema = await buildGraphQLSchema(schemaResult.items);
55
+ if (!schema) {
56
+ logger.error("Failed to build GraphQL schema");
57
+ return;
58
+ }
59
+ const result = await generateServerTypesCore({
60
+ framework: ctx.config.framework,
61
+ schema,
62
+ config: ctx.config.codegen?.server,
63
+ federationEnabled: ctx.config.federation?.enabled
64
+ });
65
+ const schemaPath = join(ctx.config.buildDir, "schema.graphql");
66
+ mkdirSync_(dirname(schemaPath));
67
+ writeFileSync_(schemaPath, result.schemaString);
68
+ const typesConfig = ctx.config.types;
69
+ let typesPath;
70
+ if (typesConfig && typeof typesConfig === "object" && typeof typesConfig.server === "string") typesPath = resolve$1(ctx.config.rootDir, typesConfig.server);
71
+ else typesPath = join(ctx.config.typesDir, "nitro-graphql-server.d.ts");
72
+ mkdirSync_(dirname(typesPath));
73
+ writeFileSync_(typesPath, result.types);
74
+ if (!options.silent) logger.success(`Generated server types: ${relative(ctx.config.rootDir, typesPath)}`);
75
+ }
76
+ /**
77
+ * Generate client types
78
+ */
79
+ async function generateClient(ctx, options = {}) {
80
+ const scanCtx = createScanContext(ctx);
81
+ const schemaPath = join(ctx.config.buildDir, "schema.graphql");
82
+ if (!existsSync_(schemaPath)) {
83
+ if (!options.silent) logger.info("Server schema not found. Generate server types first.");
84
+ return;
85
+ }
86
+ const docsResult = await scanDocumentsCore(scanCtx, { externalServices: ctx.config.externalServices });
87
+ if (docsResult.errors.length > 0) for (const error of docsResult.errors) logger.error(error);
88
+ if (docsResult.items.length === 0) {
89
+ if (!options.silent) logger.info("No GraphQL documents found in client directory");
90
+ return;
91
+ }
92
+ const documents = await loadGraphQLDocuments(docsResult.items);
93
+ const { buildSchema } = await import("graphql");
94
+ const result = await generateClientTypesCore({
95
+ schema: buildSchema(readFileSync_(schemaPath)),
96
+ documents,
97
+ config: ctx.config.codegen?.client,
98
+ sdkConfig: ctx.config.codegen?.clientSDK,
99
+ options: { silent: options.silent }
100
+ });
101
+ if (result === false) {
102
+ if (!options.silent) logger.warn("Client type generation skipped");
103
+ return;
104
+ }
105
+ const typesConfig = ctx.config.types;
106
+ let typesPath;
107
+ if (typesConfig && typeof typesConfig === "object" && typeof typesConfig.client === "string") typesPath = resolve$1(ctx.config.rootDir, typesConfig.client);
108
+ else typesPath = join(ctx.config.typesDir, "nitro-graphql-client.d.ts");
109
+ mkdirSync_(dirname(typesPath));
110
+ writeFileSync_(typesPath, result.types);
111
+ const sdkPath = join(ctx.config.clientDir, "default", "sdk.ts");
112
+ mkdirSync_(dirname(sdkPath));
113
+ writeFileSync_(sdkPath, result.sdk);
114
+ if (!options.silent) logger.success(`Generated client types: ${relative(ctx.config.rootDir, typesPath)}`);
115
+ }
116
+ /**
117
+ * Generate runtime files (resolvers.ts, schema.ts, index.ts)
118
+ */
119
+ async function generateRuntimeFiles(ctx, options = {}) {
120
+ const scanCtx = createScanContext(ctx);
121
+ const runtimeConfig = ctx.config.runtime;
122
+ const runtimeDir = typeof runtimeConfig === "object" && runtimeConfig.outDir ? join(ctx.config.rootDir, runtimeConfig.outDir) : join(ctx.config.buildDir, "runtime");
123
+ mkdirSync_(runtimeDir);
124
+ const include = typeof runtimeConfig === "object" && runtimeConfig.include ? runtimeConfig.include : {
125
+ resolvers: true,
126
+ schema: true,
127
+ index: true
128
+ };
129
+ if (include.resolvers !== false) {
130
+ const resolversResult = await scanResolversCore(scanCtx);
131
+ if (resolversResult.items.length > 0) {
132
+ const resolverCode = generateResolverModule(resolversResult.items, runtimeDir);
133
+ writeFileSync_(join(runtimeDir, "resolvers.ts"), resolverCode);
134
+ if (!options.silent) logger.success(`Generated runtime: ${relative(ctx.config.rootDir, join(runtimeDir, "resolvers.ts"))}`);
135
+ } else if (!options.silent) logger.info("No resolvers found for runtime generation");
136
+ }
137
+ if (include.schema !== false) {
138
+ const schemaPath = join(ctx.config.buildDir, "schema.graphql");
139
+ if (existsSync_(schemaPath)) {
140
+ const schemaCode = generateSchemaModule(readFileSync_(schemaPath));
141
+ writeFileSync_(join(runtimeDir, "schema.ts"), schemaCode);
142
+ if (!options.silent) logger.success(`Generated runtime: ${relative(ctx.config.rootDir, join(runtimeDir, "schema.ts"))}`);
143
+ } else if (!options.silent) logger.info("Schema not found for runtime generation. Run generate first.");
144
+ }
145
+ if (include.index !== false) {
146
+ const indexCode = generateRuntimeIndex();
147
+ writeFileSync_(join(runtimeDir, "index.ts"), indexCode);
148
+ if (!options.silent) logger.success(`Generated runtime: ${relative(ctx.config.rootDir, join(runtimeDir, "index.ts"))}`);
149
+ }
150
+ }
151
+ /**
152
+ * Watch mode - regenerate on file changes
153
+ */
154
+ async function watchAndRegenerate(ctx, options = {}) {
155
+ const { watch } = await import("chokidar");
156
+ const watchDirs = [ctx.config.serverDir, ctx.config.clientDir];
157
+ const watcher = watch(watchDirs, {
158
+ ignoreInitial: true,
159
+ ignored: [
160
+ ...ctx.config.ignore || [],
161
+ /node_modules/,
162
+ /\.git/
163
+ ],
164
+ persistent: true
165
+ });
166
+ await new Promise((resolve) => {
167
+ watcher.on("ready", resolve);
168
+ watcher.on("error", (error) => logger.error("Watcher error:", error));
169
+ });
170
+ const relPath = (p) => relative(ctx.config.rootDir, p) || ".";
171
+ logger.info(`Watching: ${watchDirs.map(relPath).join(", ")}`);
172
+ let debounceTimer = null;
173
+ const debounceMs = ctx.config.watch?.debounce ?? 300;
174
+ watcher.on("all", (event, filePath) => {
175
+ if (!filePath.endsWith(".graphql") && !filePath.endsWith(".resolver.ts")) return;
176
+ if (debounceTimer) clearTimeout(debounceTimer);
177
+ debounceTimer = setTimeout(async () => {
178
+ try {
179
+ await generateAll(ctx, {
180
+ silent: options.silent ?? true,
181
+ watch: false
182
+ });
183
+ logger.success(`Types regenerated (${relPath(filePath)})`);
184
+ } catch (error) {
185
+ logger.error("Regeneration failed:", error);
186
+ }
187
+ }, debounceMs);
188
+ });
189
+ await new Promise((resolvePromise) => {
190
+ onSignal("SIGINT", () => {
191
+ watcher.close();
192
+ resolvePromise();
193
+ });
194
+ });
195
+ }
196
+
197
+ //#endregion
198
+ export { generateAll, generateClient, generateServer };
@@ -0,0 +1,5 @@
1
+ import { buildCommand } from "./build.mjs";
2
+ import { generateAll, generateClient, generateServer } from "./generate.mjs";
3
+ import { init } from "./init.mjs";
4
+ import { validate } from "./validate.mjs";
5
+ export { buildCommand, generateAll, generateClient, generateServer, init, validate };
@@ -0,0 +1,6 @@
1
+ import { init } from "./init.mjs";
2
+ import { generateAll, generateClient, generateServer } from "./generate.mjs";
3
+ import { validate } from "./validate.mjs";
4
+ import { buildCommand } from "./build.mjs";
5
+
6
+ export { buildCommand, generateAll, generateClient, generateServer, init, validate };
@@ -0,0 +1,45 @@
1
+ import { CLIContext } from "../index.mjs";
2
+
3
+ //#region src/cli/commands/init.d.ts
4
+ /**
5
+ * Available templates from the examples directory
6
+ */
7
+ declare const AVAILABLE_TEMPLATES: readonly [{
8
+ readonly name: "nitro";
9
+ readonly description: "Minimal Nitro + GraphQL starter";
10
+ }, {
11
+ readonly name: "drizzle-orm";
12
+ readonly description: "Nitro + GraphQL + Drizzle ORM with PostgreSQL";
13
+ }, {
14
+ readonly name: "vite";
15
+ readonly description: "Vite + Nitro GraphQL integration";
16
+ }, {
17
+ readonly name: "vite-react";
18
+ readonly description: "Vite + React + Nitro GraphQL";
19
+ }, {
20
+ readonly name: "vite-vue";
21
+ readonly description: "Vite + Vue + Nitro GraphQL";
22
+ }, {
23
+ readonly name: "better-auth";
24
+ readonly description: "Nitro + GraphQL + Better Auth integration";
25
+ }];
26
+ type TemplateName = typeof AVAILABLE_TEMPLATES[number]['name'];
27
+ /**
28
+ * List available templates
29
+ */
30
+ declare function listTemplates(): void;
31
+ /**
32
+ * Initialize project from template
33
+ */
34
+ declare function initFromTemplate(projectName: string, templateName: string, options?: {
35
+ force?: boolean;
36
+ cwd?: string;
37
+ }): Promise<void>;
38
+ /**
39
+ * Initialize project structure (basic scaffolding)
40
+ */
41
+ declare function init(ctx: CLIContext, options?: {
42
+ force?: boolean;
43
+ }): Promise<void>;
44
+ //#endregion
45
+ export { AVAILABLE_TEMPLATES, TemplateName, init, initFromTemplate, listTemplates };