nitro-graphql 2.0.0-beta.7 → 2.0.0-beta.72

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 (242) hide show
  1. package/README.md +31 -1196
  2. package/dist/cli/adapter.d.mts +13 -0
  3. package/dist/cli/adapter.mjs +67 -0
  4. package/dist/cli/commands/build.d.mts +21 -0
  5. package/dist/cli/commands/build.mjs +50 -0
  6. package/dist/cli/commands/dev.d.mts +40 -0
  7. package/dist/cli/commands/dev.mjs +74 -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 +5 -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 +65 -0
  16. package/dist/cli/completions.d.mts +6 -0
  17. package/dist/cli/completions.mjs +32 -0
  18. package/dist/cli/config.d.mts +18 -0
  19. package/dist/cli/config.mjs +19 -0
  20. package/dist/cli/index.d.mts +26 -0
  21. package/dist/cli/index.mjs +315 -0
  22. package/dist/cli/server/debug-handler.d.mts +9 -0
  23. package/dist/cli/server/debug-handler.mjs +68 -0
  24. package/dist/cli/server/dev-server.d.mts +29 -0
  25. package/dist/cli/server/dev-server.mjs +62 -0
  26. package/dist/cli/server/graphql-handler.d.mts +21 -0
  27. package/dist/cli/server/graphql-handler.mjs +43 -0
  28. package/dist/cli/server/health-handler.d.mts +12 -0
  29. package/dist/cli/server/health-handler.mjs +29 -0
  30. package/dist/cli/server/loader.d.mts +33 -0
  31. package/dist/cli/server/loader.mjs +144 -0
  32. package/dist/cli/server/sandbox-handler.d.mts +12 -0
  33. package/dist/cli/server/sandbox-handler.mjs +17 -0
  34. package/dist/cli/server/watcher.d.mts +20 -0
  35. package/dist/cli/server/watcher.mjs +64 -0
  36. package/dist/cli/server/ws-handler.d.mts +28 -0
  37. package/dist/cli/server/ws-handler.mjs +48 -0
  38. package/dist/config.d.mts +2 -0
  39. package/dist/config.mjs +2 -0
  40. package/dist/core/codegen/client.d.mts +42 -0
  41. package/dist/core/codegen/client.mjs +551 -0
  42. package/dist/core/codegen/document-loader.d.mts +9 -0
  43. package/dist/core/codegen/document-loader.mjs +16 -0
  44. package/dist/core/codegen/index.d.mts +8 -0
  45. package/dist/core/codegen/index.mjs +8 -0
  46. package/dist/core/codegen/plugin.d.mts +19 -0
  47. package/dist/core/codegen/plugin.mjs +29 -0
  48. package/dist/core/codegen/runtime.d.mts +17 -0
  49. package/dist/core/codegen/runtime.mjs +61 -0
  50. package/dist/core/codegen/schema-loader.d.mts +27 -0
  51. package/dist/core/codegen/schema-loader.mjs +126 -0
  52. package/dist/core/codegen/server.d.mts +27 -0
  53. package/dist/core/codegen/server.mjs +142 -0
  54. package/dist/core/codegen/validation.d.mts +17 -0
  55. package/dist/core/codegen/validation.mjs +33 -0
  56. package/dist/core/config.d.mts +45 -0
  57. package/dist/core/config.mjs +76 -0
  58. package/dist/core/constants.d.mts +188 -0
  59. package/dist/core/constants.mjs +208 -0
  60. package/dist/core/debug/index.d.mts +2 -0
  61. package/dist/core/debug/index.mjs +2 -0
  62. package/dist/core/debug/template.d.mts +52 -0
  63. package/dist/core/debug/template.mjs +384 -0
  64. package/dist/core/extend/index.d.mts +2 -0
  65. package/dist/core/extend/index.mjs +2 -0
  66. package/dist/core/extend/loader.d.mts +40 -0
  67. package/dist/core/extend/loader.mjs +196 -0
  68. package/dist/core/index.d.mts +33 -0
  69. package/dist/core/index.mjs +28 -0
  70. package/dist/core/manifest.d.mts +56 -0
  71. package/dist/core/manifest.mjs +100 -0
  72. package/dist/core/pubsub/index.d.mts +109 -0
  73. package/dist/core/pubsub/index.mjs +146 -0
  74. package/dist/core/scanning/ast-scanner.d.mts +27 -0
  75. package/dist/core/scanning/ast-scanner.mjs +114 -0
  76. package/dist/core/scanning/common.d.mts +25 -0
  77. package/dist/core/scanning/common.mjs +57 -0
  78. package/dist/core/scanning/directives.d.mts +13 -0
  79. package/dist/core/scanning/directives.mjs +28 -0
  80. package/dist/core/scanning/documents.d.mts +20 -0
  81. package/dist/core/scanning/documents.mjs +36 -0
  82. package/dist/core/scanning/index.d.mts +7 -0
  83. package/dist/core/scanning/index.mjs +7 -0
  84. package/dist/core/scanning/resolvers.d.mts +14 -0
  85. package/dist/core/scanning/resolvers.mjs +58 -0
  86. package/dist/core/scanning/schemas.d.mts +13 -0
  87. package/dist/core/scanning/schemas.mjs +50 -0
  88. package/dist/core/schema/builder.d.mts +59 -0
  89. package/dist/core/schema/builder.mjs +76 -0
  90. package/dist/core/schema/federation.d.mts +33 -0
  91. package/dist/core/schema/federation.mjs +38 -0
  92. package/dist/core/schema/index.d.mts +3 -0
  93. package/dist/core/schema/index.mjs +3 -0
  94. package/dist/core/server/index.d.mts +4 -0
  95. package/dist/core/server/index.mjs +3 -0
  96. package/dist/core/server/sandbox.d.mts +18 -0
  97. package/dist/core/server/sandbox.mjs +38 -0
  98. package/dist/core/server/types.d.mts +54 -0
  99. package/dist/core/server/types.mjs +1 -0
  100. package/dist/core/server/yoga.d.mts +42 -0
  101. package/dist/core/server/yoga.mjs +87 -0
  102. package/dist/core/types/adapter.d.mts +55 -0
  103. package/dist/core/types/adapter.mjs +1 -0
  104. package/dist/core/types/codegen.d.mts +136 -0
  105. package/dist/core/types/codegen.mjs +1 -0
  106. package/dist/core/types/config.d.mts +188 -0
  107. package/dist/core/types/config.mjs +1 -0
  108. package/dist/{utils/define.d.ts → core/types/define.d.mts} +2 -30
  109. package/dist/core/types/define.mjs +1 -0
  110. package/dist/core/types/index.d.mts +5 -0
  111. package/dist/core/types/index.mjs +1 -0
  112. package/dist/core/types/scanning.d.mts +64 -0
  113. package/dist/core/types/scanning.mjs +1 -0
  114. package/dist/{utils/directive-parser.d.ts → core/utils/directive-parser.d.mts} +18 -4
  115. package/dist/{utils/directive-parser.js → core/utils/directive-parser.mjs} +29 -36
  116. package/dist/core/utils/errors.d.mts +77 -0
  117. package/dist/core/utils/errors.mjs +91 -0
  118. package/dist/core/utils/file-io.d.mts +24 -0
  119. package/dist/core/utils/file-io.mjs +45 -0
  120. package/dist/core/utils/imports.d.mts +15 -0
  121. package/dist/core/utils/imports.mjs +24 -0
  122. package/dist/core/utils/index.d.mts +7 -0
  123. package/dist/core/utils/index.mjs +7 -0
  124. package/dist/core/utils/logger.d.mts +18 -0
  125. package/dist/core/utils/logger.mjs +36 -0
  126. package/dist/core/utils/ofetch-templates.d.mts +30 -0
  127. package/dist/core/utils/ofetch-templates.mjs +134 -0
  128. package/dist/core/utils/runtime.d.mts +74 -0
  129. package/dist/core/utils/runtime.mjs +109 -0
  130. package/dist/core/utils/subscribe-templates.d.mts +8 -0
  131. package/dist/core/utils/subscribe-templates.mjs +58 -0
  132. package/dist/core/validation/external-services.d.mts +11 -0
  133. package/dist/core/validation/external-services.mjs +33 -0
  134. package/dist/core/validation/index.d.mts +2 -0
  135. package/dist/core/validation/index.mjs +2 -0
  136. package/dist/core/watcher/index.d.mts +107 -0
  137. package/dist/core/watcher/index.mjs +140 -0
  138. package/dist/define.d.mts +294 -0
  139. package/dist/define.mjs +323 -0
  140. package/dist/index.d.mts +6 -0
  141. package/dist/index.mjs +5 -0
  142. package/dist/nitro/adapter.d.mts +28 -0
  143. package/dist/nitro/adapter.mjs +90 -0
  144. package/dist/{utils/apollo.d.ts → nitro/apollo.d.mts} +3 -3
  145. package/dist/nitro/apollo.mjs +57 -0
  146. package/dist/nitro/codegen.d.mts +18 -0
  147. package/dist/nitro/codegen.mjs +171 -0
  148. package/dist/nitro/config.d.mts +50 -0
  149. package/dist/nitro/config.mjs +55 -0
  150. package/dist/nitro/index.d.mts +45 -0
  151. package/dist/nitro/index.mjs +63 -0
  152. package/dist/{utils/path-resolver.d.ts → nitro/paths.d.mts} +8 -25
  153. package/dist/nitro/paths.mjs +97 -0
  154. package/dist/nitro/rollup.d.mts +6 -0
  155. package/dist/nitro/rollup.mjs +52 -0
  156. package/dist/nitro/routes/apollo-sandbox-script.d.mts +6 -0
  157. package/dist/nitro/routes/apollo-sandbox-script.mjs +12 -0
  158. package/dist/nitro/routes/apollo-server-ws.d.mts +15 -0
  159. package/dist/nitro/routes/apollo-server-ws.mjs +50 -0
  160. package/dist/nitro/routes/apollo-server.d.mts +6 -0
  161. package/dist/nitro/routes/apollo-server.mjs +69 -0
  162. package/dist/{routes/debug.d.ts → nitro/routes/debug.d.mts} +12 -19
  163. package/dist/nitro/routes/debug.mjs +98 -0
  164. package/dist/nitro/routes/graphql-yoga-ws.d.mts +12 -0
  165. package/dist/nitro/routes/graphql-yoga-ws.mjs +50 -0
  166. package/dist/nitro/routes/graphql-yoga.d.mts +12 -0
  167. package/dist/nitro/routes/graphql-yoga.mjs +39 -0
  168. package/dist/nitro/routes/health.d.mts +10 -0
  169. package/dist/{routes/health.js → nitro/routes/health.mjs} +5 -6
  170. package/dist/nitro/setup/extend-loader.d.mts +16 -0
  171. package/dist/nitro/setup/extend-loader.mjs +80 -0
  172. package/dist/nitro/setup/file-watcher.d.mts +18 -0
  173. package/dist/nitro/setup/file-watcher.mjs +62 -0
  174. package/dist/nitro/setup/logging.d.mts +16 -0
  175. package/dist/nitro/setup/logging.mjs +64 -0
  176. package/dist/nitro/setup/rollup-integration.d.mts +24 -0
  177. package/dist/nitro/setup/rollup-integration.mjs +64 -0
  178. package/dist/nitro/setup/routes.d.mts +13 -0
  179. package/dist/nitro/setup/routes.mjs +69 -0
  180. package/dist/nitro/setup/scanner.d.mts +59 -0
  181. package/dist/nitro/setup/scanner.mjs +118 -0
  182. package/dist/nitro/setup/ts-config.d.mts +10 -0
  183. package/dist/nitro/setup/ts-config.mjs +67 -0
  184. package/dist/nitro/setup.d.mts +11 -0
  185. package/dist/nitro/setup.mjs +189 -0
  186. package/dist/nitro/types.d.mts +549 -0
  187. package/dist/nitro/types.mjs +1 -0
  188. package/dist/nitro/virtual/generators.d.mts +38 -0
  189. package/dist/nitro/virtual/generators.mjs +190 -0
  190. package/dist/nitro/virtual/stubs.d.mts +21 -0
  191. package/dist/nitro/virtual/stubs.mjs +31 -0
  192. package/dist/{ecosystem/nuxt.d.ts → nuxt.d.mts} +1 -1
  193. package/dist/nuxt.mjs +111 -0
  194. package/dist/{graphql/server.d.ts → stubs/index.d.mts} +5 -1
  195. package/dist/stubs/index.mjs +1 -0
  196. package/dist/subscribe/index.d.mts +78 -0
  197. package/dist/subscribe/index.mjs +205 -0
  198. package/native/index.d.ts +20 -0
  199. package/native/index.js +585 -0
  200. package/package.json +202 -112
  201. package/dist/ecosystem/nuxt.js +0 -67
  202. package/dist/graphql/index.d.ts +0 -5
  203. package/dist/graphql/index.js +0 -1
  204. package/dist/graphql/server.js +0 -1
  205. package/dist/index.d.ts +0 -8
  206. package/dist/index.js +0 -318
  207. package/dist/rollup.js +0 -277
  208. package/dist/routes/apollo-server.d.ts +0 -6
  209. package/dist/routes/apollo-server.js +0 -89
  210. package/dist/routes/debug.js +0 -449
  211. package/dist/routes/graphql-yoga.d.ts +0 -6
  212. package/dist/routes/graphql-yoga.js +0 -91
  213. package/dist/routes/health.d.ts +0 -10
  214. package/dist/types/index.d.ts +0 -246
  215. package/dist/types/standard-schema.d.ts +0 -59
  216. package/dist/utils/apollo.js +0 -61
  217. package/dist/utils/client-codegen.d.ts +0 -38
  218. package/dist/utils/client-codegen.js +0 -290
  219. package/dist/utils/define.js +0 -57
  220. package/dist/utils/file-generator.d.ts +0 -37
  221. package/dist/utils/file-generator.js +0 -72
  222. package/dist/utils/index.d.ts +0 -39
  223. package/dist/utils/index.js +0 -278
  224. package/dist/utils/path-resolver.js +0 -127
  225. package/dist/utils/server-codegen.d.ts +0 -7
  226. package/dist/utils/server-codegen.js +0 -136
  227. package/dist/utils/type-generation.d.ts +0 -7
  228. package/dist/utils/type-generation.js +0 -360
  229. package/dist/virtual/debug-info.d.ts +0 -9
  230. package/dist/virtual/debug-info.js +0 -26
  231. package/dist/virtual/graphql-config.d.ts +0 -9
  232. package/dist/virtual/graphql-config.js +0 -10
  233. package/dist/virtual/module-config.d.ts +0 -9
  234. package/dist/virtual/module-config.js +0 -10
  235. package/dist/virtual/server-directives.d.ts +0 -11
  236. package/dist/virtual/server-directives.js +0 -10
  237. package/dist/virtual/server-resolvers.d.ts +0 -11
  238. package/dist/virtual/server-resolvers.js +0 -10
  239. package/dist/virtual/server-schemas.d.ts +0 -11
  240. package/dist/virtual/server-schemas.js +0 -10
  241. package/dist/vite.d.ts +0 -25
  242. package/dist/vite.js +0 -40
@@ -0,0 +1,9 @@
1
+ import { CLIContext } from "../index.mjs";
2
+
3
+ //#region src/cli/server/debug-handler.d.ts
4
+ /**
5
+ * Create a debug handler for the CLI dev server
6
+ */
7
+ declare function createDebugHandler(ctx: CLIContext): (request: Request) => Promise<Response>;
8
+ //#endregion
9
+ export { createDebugHandler };
@@ -0,0 +1,68 @@
1
+ import { scanDirectivesCore } from "../../core/scanning/directives.mjs";
2
+ import { scanDocumentsCore } from "../../core/scanning/documents.mjs";
3
+ import { scanResolversCore } from "../../core/scanning/resolvers.mjs";
4
+ import { scanSchemasCore } from "../../core/scanning/schemas.mjs";
5
+ import { CLIAdapter } from "../adapter.mjs";
6
+ import { generateDebugHtml } from "../../core/debug/template.mjs";
7
+ //#region src/cli/server/debug-handler.ts
8
+ /**
9
+ * Create a debug handler for the CLI dev server
10
+ */
11
+ function createDebugHandler(ctx) {
12
+ return async (request) => {
13
+ const debugInfo = await collectDebugInfo(ctx);
14
+ if (new URL(request.url).searchParams.get("format") === "json") return Response.json(debugInfo);
15
+ return new Response(generateDebugHtml(debugInfo), { headers: { "Content-Type": "text/html" } });
16
+ };
17
+ }
18
+ /**
19
+ * Collect debug information from CLI context
20
+ */
21
+ async function collectDebugInfo(ctx) {
22
+ const scanCtx = CLIAdapter.createScanContext(ctx);
23
+ const [schemasResult, resolversResult, directivesResult, documentsResult] = await Promise.all([
24
+ scanSchemasCore(scanCtx),
25
+ scanResolversCore(scanCtx),
26
+ scanDirectivesCore(scanCtx),
27
+ scanDocumentsCore(scanCtx, { externalServices: ctx.config.externalServices })
28
+ ]);
29
+ const resolverFiles = resolversResult.items.map((r) => {
30
+ return {
31
+ file: r.specifier.split("/").at(-1) || r.specifier,
32
+ exports: r.imports.map((i) => ({
33
+ name: i.name,
34
+ type: i.type
35
+ }))
36
+ };
37
+ });
38
+ const schemaFiles = schemasResult.items.map((s) => {
39
+ return s.split("/").slice(-3).join("/");
40
+ });
41
+ const documentFiles = documentsResult.items.map((d) => {
42
+ return d.split("/").slice(-3).join("/");
43
+ });
44
+ return {
45
+ environment: {
46
+ dev: true,
47
+ framework: "cli"
48
+ },
49
+ graphql: { framework: ctx.config.framework || "graphql-yoga" },
50
+ scanned: {
51
+ schemas: schemasResult.items.length,
52
+ resolvers: resolversResult.items.length,
53
+ directives: directivesResult.items.length,
54
+ documents: documentsResult.items.length,
55
+ schemaFiles,
56
+ resolverFiles,
57
+ documentFiles
58
+ },
59
+ runtime: {
60
+ loadedResolvers: resolversResult.items.length,
61
+ loadedSchemas: schemasResult.items.length,
62
+ loadedDirectives: directivesResult.items.length
63
+ },
64
+ virtualModules: { "cli-config": JSON.stringify(ctx.config, null, 2) }
65
+ };
66
+ }
67
+ //#endregion
68
+ export { createDebugHandler };
@@ -0,0 +1,29 @@
1
+ import { CLIContext } from "../index.mjs";
2
+ import { serve } from "srvx";
3
+
4
+ //#region src/cli/server/dev-server.d.ts
5
+ interface DevServerOptions {
6
+ /** Server port (default: 4000) */
7
+ port?: number;
8
+ /** Server hostname (default: localhost) */
9
+ hostname?: string;
10
+ /** Open browser after start */
11
+ open?: boolean;
12
+ }
13
+ interface DevServerInstance {
14
+ /** The srvx server instance */
15
+ server: ReturnType<typeof serve>;
16
+ /** Reload the GraphQL schema (for hot reload) */
17
+ reload: () => Promise<void>;
18
+ /** Stop the server */
19
+ close: () => Promise<void>;
20
+ }
21
+ /**
22
+ * Start the CLI development server
23
+ *
24
+ * Uses srvx for runtime-agnostic HTTP server.
25
+ * GraphQL handled by the same core factory that Nitro uses.
26
+ */
27
+ declare function startDevServer(ctx: CLIContext, options?: DevServerOptions): Promise<DevServerInstance>;
28
+ //#endregion
29
+ export { DevServerInstance, DevServerOptions, startDevServer };
@@ -0,0 +1,62 @@
1
+ import { createDebugHandler } from "./debug-handler.mjs";
2
+ import { createGraphQLHandler, getServerInstance, reloadGraphQLHandler } from "./graphql-handler.mjs";
3
+ import { createHealthHandler } from "./health-handler.mjs";
4
+ import { createSandboxHandler } from "./sandbox-handler.mjs";
5
+ import { createWebSocketPlugin } from "./ws-handler.mjs";
6
+ import consola from "consola";
7
+ import { plugin } from "crossws/server";
8
+ import { serve } from "srvx";
9
+ //#region src/cli/server/dev-server.ts
10
+ const logger = consola.withTag("nitro-graphql");
11
+ /**
12
+ * Start the CLI development server
13
+ *
14
+ * Uses srvx for runtime-agnostic HTTP server.
15
+ * GraphQL handled by the same core factory that Nitro uses.
16
+ */
17
+ async function startDevServer(ctx, options = {}) {
18
+ const port = options.port || 4e3;
19
+ const hostname = options.hostname || "localhost";
20
+ const endpoint = ctx.config.endpoint?.graphql || "/graphql";
21
+ logger.info("Starting GraphQL dev server...");
22
+ let graphqlHandler = await createGraphQLHandler(ctx);
23
+ const healthHandler = createHealthHandler();
24
+ const sandboxHandler = createSandboxHandler();
25
+ const debugHandler = createDebugHandler(ctx);
26
+ const server = serve({
27
+ port,
28
+ hostname,
29
+ plugins: [plugin(createWebSocketPlugin(() => {
30
+ const instance = getServerInstance();
31
+ if (!instance) throw new Error("GraphQL server not initialized");
32
+ return instance.schema;
33
+ }))],
34
+ async fetch(request) {
35
+ const path = new URL(request.url).pathname;
36
+ if (path === endpoint || path === "/api/graphql") return graphqlHandler(request);
37
+ if (path === "/api/graphql/sandbox.js" || path === `${endpoint}/sandbox.js`) return sandboxHandler(request);
38
+ if (path === "/health" || path === "/api/graphql/health") return healthHandler(request);
39
+ if (path === "/_nitro/graphql/debug") return debugHandler(request);
40
+ return new Response("Not Found", { status: 404 });
41
+ }
42
+ });
43
+ await server.ready();
44
+ logger.success(`GraphQL server running at http://${hostname}:${port}${endpoint}`);
45
+ logger.info(`Health check at http://${hostname}:${port}/health`);
46
+ logger.info(`Debug dashboard at http://${hostname}:${port}/_nitro/graphql/debug`);
47
+ return {
48
+ server,
49
+ async reload() {
50
+ logger.info("Reloading GraphQL schema...");
51
+ graphqlHandler = await reloadGraphQLHandler(ctx);
52
+ logger.success("Schema reloaded!");
53
+ },
54
+ async close() {
55
+ logger.info("Shutting down server...");
56
+ await server.close();
57
+ logger.success("Server stopped");
58
+ }
59
+ };
60
+ }
61
+ //#endregion
62
+ export { startDevServer };
@@ -0,0 +1,21 @@
1
+ import { CLIContext } from "../index.mjs";
2
+ import { CoreServerInstance } from "../../core/server/types.mjs";
3
+
4
+ //#region src/cli/server/graphql-handler.d.ts
5
+ /**
6
+ * Create the GraphQL request handler
7
+ *
8
+ * Uses the same createYogaServer() from core that Nitro uses,
9
+ * ensuring 100% consistent behavior between CLI and Nitro module.
10
+ */
11
+ declare function createGraphQLHandler(ctx: CLIContext): Promise<(request: Request) => Promise<Response>>;
12
+ /**
13
+ * Reload the GraphQL handler (for hot reload)
14
+ */
15
+ declare function reloadGraphQLHandler(ctx: CLIContext): Promise<(request: Request) => Promise<Response>>;
16
+ /**
17
+ * Get the current server instance (for WebSocket setup, etc.)
18
+ */
19
+ declare function getServerInstance(): CoreServerInstance | null;
20
+ //#endregion
21
+ export { createGraphQLHandler, getServerInstance, reloadGraphQLHandler };
@@ -0,0 +1,43 @@
1
+ import { BASE_SCHEMA, createYogaServer } from "../../core/server/yoga.mjs";
2
+ import { loadDirectiveDefinitions, loadResolverDefinitions, loadSchemaDefinitions } from "./loader.mjs";
3
+ import consola from "consola";
4
+ //#region src/cli/server/graphql-handler.ts
5
+ const logger = consola.withTag("nitro-graphql");
6
+ let serverInstance = null;
7
+ /**
8
+ * Create the GraphQL request handler
9
+ *
10
+ * Uses the same createYogaServer() from core that Nitro uses,
11
+ * ensuring 100% consistent behavior between CLI and Nitro module.
12
+ */
13
+ async function createGraphQLHandler(ctx) {
14
+ const loadedSchemas = await loadSchemaDefinitions(ctx);
15
+ const resolvers = await loadResolverDefinitions(ctx);
16
+ const directives = await loadDirectiveDefinitions(ctx);
17
+ const schemas = [BASE_SCHEMA, ...loadedSchemas];
18
+ serverInstance = await createYogaServer({
19
+ schemas,
20
+ resolvers,
21
+ directives,
22
+ moduleConfig: { federation: ctx.config.federation },
23
+ endpoint: ctx.config.endpoint?.graphql || "/graphql",
24
+ security: ctx.config.security
25
+ });
26
+ logger.success(`GraphQL server created with ${schemas.length} schema(s) and ${resolvers.length} resolver(s)`);
27
+ return (request) => serverInstance.fetch(request);
28
+ }
29
+ /**
30
+ * Reload the GraphQL handler (for hot reload)
31
+ */
32
+ async function reloadGraphQLHandler(ctx) {
33
+ serverInstance = null;
34
+ return createGraphQLHandler(ctx);
35
+ }
36
+ /**
37
+ * Get the current server instance (for WebSocket setup, etc.)
38
+ */
39
+ function getServerInstance() {
40
+ return serverInstance;
41
+ }
42
+ //#endregion
43
+ export { createGraphQLHandler, getServerInstance, reloadGraphQLHandler };
@@ -0,0 +1,12 @@
1
+ //#region src/cli/server/health-handler.d.ts
2
+ /**
3
+ * CLI Health Handler
4
+ *
5
+ * Simple health check endpoint for the CLI dev server.
6
+ */
7
+ /**
8
+ * Create a health check handler
9
+ */
10
+ declare function createHealthHandler(): (request: Request) => Response;
11
+ //#endregion
12
+ export { createHealthHandler };
@@ -0,0 +1,29 @@
1
+ //#region src/cli/server/health-handler.ts
2
+ /**
3
+ * CLI Health Handler
4
+ *
5
+ * Simple health check endpoint for the CLI dev server.
6
+ */
7
+ /**
8
+ * Create a health check handler
9
+ */
10
+ function createHealthHandler() {
11
+ return (_request) => {
12
+ return Response.json({
13
+ status: "ok",
14
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
15
+ runtime: detectRuntime()
16
+ });
17
+ };
18
+ }
19
+ /**
20
+ * Detect the current JavaScript runtime
21
+ */
22
+ function detectRuntime() {
23
+ if (typeof Bun !== "undefined") return "bun";
24
+ if (typeof Deno !== "undefined") return "deno";
25
+ if (typeof process !== "undefined" && process.versions?.node) return `node/${process.versions.node}`;
26
+ return "unknown";
27
+ }
28
+ //#endregion
29
+ export { createHealthHandler };
@@ -0,0 +1,33 @@
1
+ import { CLIContext } from "../index.mjs";
2
+ import { DirectiveWrapper, ResolverDefinition, SchemaDefinition } from "../../core/schema/builder.mjs";
3
+
4
+ //#region src/cli/server/loader.d.ts
5
+ /**
6
+ * Clear extend cache (for hot reload)
7
+ */
8
+ declare function clearExtendCache(): void;
9
+ /**
10
+ * Load schema definitions from GraphQL files
11
+ * Includes schemas from extend sources
12
+ */
13
+ declare function loadSchemaDefinitions(ctx: CLIContext): Promise<SchemaDefinition[]>;
14
+ /**
15
+ * Load resolver definitions by dynamically importing resolver modules
16
+ * Includes resolvers from extend sources
17
+ */
18
+ declare function loadResolverDefinitions(ctx: CLIContext): Promise<ResolverDefinition[]>;
19
+ /**
20
+ * Load directive definitions by dynamically importing directive modules
21
+ * Includes directives from extend sources
22
+ */
23
+ declare function loadDirectiveDefinitions(ctx: CLIContext): Promise<DirectiveWrapper[]>;
24
+ /**
25
+ * Load all GraphQL components (schemas, resolvers, directives)
26
+ */
27
+ declare function loadAllComponents(ctx: CLIContext): Promise<{
28
+ schemas: SchemaDefinition[];
29
+ resolvers: ResolverDefinition[];
30
+ directives: DirectiveWrapper[];
31
+ }>;
32
+ //#endregion
33
+ export { clearExtendCache, loadAllComponents, loadDirectiveDefinitions, loadResolverDefinitions, loadSchemaDefinitions };
@@ -0,0 +1,144 @@
1
+ import { scanDirectivesCore } from "../../core/scanning/directives.mjs";
2
+ import { scanResolversCore } from "../../core/scanning/resolvers.mjs";
3
+ import { scanSchemasCore } from "../../core/scanning/schemas.mjs";
4
+ import { pathToFileURL, readFileSync_ } from "../../core/utils/runtime.mjs";
5
+ import { scanAllExtendSources } from "../../core/extend/loader.mjs";
6
+ import { CLIAdapter } from "../adapter.mjs";
7
+ import consola from "consola";
8
+ //#region src/cli/server/loader.ts
9
+ const logger = consola.withTag("nitro-graphql");
10
+ let cachedExtendResult = null;
11
+ /**
12
+ * Get extend scan result (cached)
13
+ */
14
+ async function getExtendResult(ctx) {
15
+ if (!cachedExtendResult) cachedExtendResult = await scanAllExtendSources(ctx.config.extend, ctx.config.rootDir);
16
+ return cachedExtendResult;
17
+ }
18
+ /**
19
+ * Clear extend cache (for hot reload)
20
+ */
21
+ function clearExtendCache() {
22
+ cachedExtendResult = null;
23
+ }
24
+ /**
25
+ * Load schema definitions from GraphQL files
26
+ * Includes schemas from extend sources
27
+ */
28
+ async function loadSchemaDefinitions(ctx) {
29
+ const result = await scanSchemasCore(CLIAdapter.createScanContext(ctx));
30
+ const extendResult = await getExtendResult(ctx);
31
+ const allSchemas = [...result.items, ...extendResult.schemas];
32
+ if (allSchemas.length === 0) {
33
+ logger.warn("No GraphQL schema files found");
34
+ return [];
35
+ }
36
+ logger.debug(`Found ${allSchemas.length} schema file(s)`);
37
+ return allSchemas.map((schemaPath) => ({ def: readFileSync_(schemaPath) }));
38
+ }
39
+ /**
40
+ * Load resolver from a scanned item
41
+ */
42
+ async function loadResolverFromItem(item) {
43
+ const filePath = item.specifier;
44
+ if (!filePath) {
45
+ logger.warn("Resolver item has no specifier, skipping");
46
+ return [];
47
+ }
48
+ const resolvers = [];
49
+ try {
50
+ const module = await import(`${pathToFileURL(filePath).href}?t=${Date.now()}`);
51
+ for (const imp of item.imports) {
52
+ const exported = module[imp.name];
53
+ if (exported && typeof exported === "object") {
54
+ resolvers.push({ resolver: exported });
55
+ logger.debug(`Loaded resolver: ${imp.name} from ${filePath}`);
56
+ }
57
+ }
58
+ } catch (error) {
59
+ logger.error(`Failed to load resolver from ${filePath}:`, error);
60
+ }
61
+ return resolvers;
62
+ }
63
+ /**
64
+ * Load resolver definitions by dynamically importing resolver modules
65
+ * Includes resolvers from extend sources
66
+ */
67
+ async function loadResolverDefinitions(ctx) {
68
+ const result = await scanResolversCore(CLIAdapter.createScanContext(ctx));
69
+ const extendResult = await getExtendResult(ctx);
70
+ const allItems = [...result.items, ...extendResult.resolvers];
71
+ if (allItems.length === 0) {
72
+ logger.warn("No resolver files found");
73
+ return [];
74
+ }
75
+ logger.debug(`Found ${allItems.length} resolver file(s)`);
76
+ const resolvers = [];
77
+ for (const item of allItems) {
78
+ const loaded = await loadResolverFromItem(item);
79
+ resolvers.push(...loaded);
80
+ }
81
+ return resolvers;
82
+ }
83
+ /**
84
+ * Load directive from a scanned item
85
+ */
86
+ async function loadDirectiveFromItem(item) {
87
+ const filePath = item.specifier;
88
+ if (!filePath) {
89
+ logger.warn("Directive item has no specifier, skipping");
90
+ return [];
91
+ }
92
+ const directives = [];
93
+ try {
94
+ const module = await import(`${pathToFileURL(filePath).href}?t=${Date.now()}`);
95
+ for (const imp of item.imports) {
96
+ const exported = module[imp.name];
97
+ if (exported && typeof exported === "object") {
98
+ directives.push({ directive: exported });
99
+ logger.debug(`Loaded directive: ${imp.name} from ${filePath}`);
100
+ }
101
+ }
102
+ } catch (error) {
103
+ logger.error(`Failed to load directive from ${filePath}:`, error);
104
+ }
105
+ return directives;
106
+ }
107
+ /**
108
+ * Load directive definitions by dynamically importing directive modules
109
+ * Includes directives from extend sources
110
+ */
111
+ async function loadDirectiveDefinitions(ctx) {
112
+ const result = await scanDirectivesCore(CLIAdapter.createScanContext(ctx));
113
+ const extendResult = await getExtendResult(ctx);
114
+ const allItems = [...result.items, ...extendResult.directives];
115
+ if (allItems.length === 0) {
116
+ logger.debug("No directive files found");
117
+ return [];
118
+ }
119
+ logger.debug(`Found ${allItems.length} directive file(s)`);
120
+ const directives = [];
121
+ for (const item of allItems) {
122
+ const loaded = await loadDirectiveFromItem(item);
123
+ directives.push(...loaded);
124
+ }
125
+ return directives;
126
+ }
127
+ /**
128
+ * Load all GraphQL components (schemas, resolvers, directives)
129
+ */
130
+ async function loadAllComponents(ctx) {
131
+ clearExtendCache();
132
+ const [schemas, resolvers, directives] = await Promise.all([
133
+ loadSchemaDefinitions(ctx),
134
+ loadResolverDefinitions(ctx),
135
+ loadDirectiveDefinitions(ctx)
136
+ ]);
137
+ return {
138
+ schemas,
139
+ resolvers,
140
+ directives
141
+ };
142
+ }
143
+ //#endregion
144
+ export { clearExtendCache, loadAllComponents, loadDirectiveDefinitions, loadResolverDefinitions, loadSchemaDefinitions };
@@ -0,0 +1,12 @@
1
+ //#region src/cli/server/sandbox-handler.d.ts
2
+ /**
3
+ * CLI Sandbox Script Handler
4
+ *
5
+ * Uses core sandbox handler.
6
+ */
7
+ /**
8
+ * Create a handler that serves the Apollo Sandbox script
9
+ */
10
+ declare function createSandboxHandler(): (request: Request) => Promise<Response>;
11
+ //#endregion
12
+ export { createSandboxHandler };
@@ -0,0 +1,17 @@
1
+ import { createSandboxResponse } from "../../core/server/sandbox.mjs";
2
+ //#region src/cli/server/sandbox-handler.ts
3
+ /**
4
+ * CLI Sandbox Script Handler
5
+ *
6
+ * Uses core sandbox handler.
7
+ */
8
+ /**
9
+ * Create a handler that serves the Apollo Sandbox script
10
+ */
11
+ function createSandboxHandler() {
12
+ return async (_request) => {
13
+ return createSandboxResponse();
14
+ };
15
+ }
16
+ //#endregion
17
+ export { createSandboxHandler };
@@ -0,0 +1,20 @@
1
+ import { CLIContext } from "../index.mjs";
2
+
3
+ //#region src/cli/server/watcher.d.ts
4
+ interface WatcherInstance {
5
+ /** Close the watcher */
6
+ close: () => Promise<void>;
7
+ }
8
+ /**
9
+ * Create a file watcher for the dev server
10
+ *
11
+ * Uses core watcher module with CLI-specific callbacks.
12
+ * Watches for changes in:
13
+ * - GraphQL schema files (*.graphql)
14
+ * - Resolver files (*.resolver.ts)
15
+ * - Directive files (*.directive.ts)
16
+ * - Client documents (*.graphql in client dir)
17
+ */
18
+ declare function createDevWatcher(ctx: CLIContext, onReload: () => Promise<void>): WatcherInstance;
19
+ //#endregion
20
+ export { WatcherInstance, createDevWatcher };
@@ -0,0 +1,64 @@
1
+ import { LOG_TAG } from "../../core/constants.mjs";
2
+ import { closeWatcher, createCoreWatcher } from "../../core/watcher/index.mjs";
3
+ import { generateAll } from "../commands/generate.mjs";
4
+ import consola from "consola";
5
+ //#region src/cli/server/watcher.ts
6
+ const logger = consola.withTag(LOG_TAG);
7
+ /**
8
+ * Create a file watcher for the dev server
9
+ *
10
+ * Uses core watcher module with CLI-specific callbacks.
11
+ * Watches for changes in:
12
+ * - GraphQL schema files (*.graphql)
13
+ * - Resolver files (*.resolver.ts)
14
+ * - Directive files (*.directive.ts)
15
+ * - Client documents (*.graphql in client dir)
16
+ */
17
+ function createDevWatcher(ctx, onReload) {
18
+ const serverDir = ctx.config.serverDir;
19
+ const clientDir = ctx.config.clientDir;
20
+ const watchDirs = [serverDir];
21
+ if (clientDir !== serverDir) watchDirs.push(clientDir);
22
+ logger.info("Watching for changes in:", watchDirs.join(", "));
23
+ const watcher = createCoreWatcher({
24
+ watchDirs,
25
+ serverDir,
26
+ debounceMs: 150
27
+ }, {
28
+ onServerChange: async () => {
29
+ logger.info("Server files changed, regenerating...");
30
+ try {
31
+ await generateAll(ctx, {
32
+ silent: true,
33
+ runtime: false
34
+ });
35
+ await onReload();
36
+ } catch (error) {
37
+ logger.error("Hot reload failed:", error);
38
+ }
39
+ },
40
+ onClientChange: async () => {
41
+ logger.info("Client files changed, regenerating...");
42
+ try {
43
+ await generateAll(ctx, {
44
+ silent: true,
45
+ runtime: false
46
+ });
47
+ } catch (error) {
48
+ logger.error("Client type generation failed:", error);
49
+ }
50
+ },
51
+ onReady: () => {
52
+ logger.success("File watcher ready");
53
+ },
54
+ onError: (error) => {
55
+ logger.error("Watcher error:", error);
56
+ }
57
+ });
58
+ return { async close() {
59
+ await closeWatcher(watcher);
60
+ logger.debug("File watcher closed");
61
+ } };
62
+ }
63
+ //#endregion
64
+ export { createDevWatcher };
@@ -0,0 +1,28 @@
1
+ import { GraphQLSchema } from "graphql";
2
+ import { Hooks } from "crossws";
3
+
4
+ //#region src/cli/server/ws-handler.d.ts
5
+ /**
6
+ * Create WebSocket hooks for GraphQL subscriptions
7
+ *
8
+ * @param getSchema - Function to get the GraphQL schema
9
+ * @param context - Optional context to pass to resolvers
10
+ */
11
+ declare function createGraphQLWebSocketHooks(getSchema: () => Promise<GraphQLSchema> | GraphQLSchema, context?: Record<string, unknown>): Partial<Hooks>;
12
+ /**
13
+ * Create crossws plugin configuration for srvx
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * import { plugin as ws } from 'crossws/server'
18
+ * import { createWebSocketPlugin } from './ws-handler'
19
+ *
20
+ * const server = serve({
21
+ * plugins: [ws(createWebSocketPlugin(getSchema))],
22
+ * fetch(req) { ... }
23
+ * })
24
+ * ```
25
+ */
26
+ declare function createWebSocketPlugin(getSchema: () => Promise<GraphQLSchema> | GraphQLSchema, context?: Record<string, unknown>): Partial<Hooks>;
27
+ //#endregion
28
+ export { createGraphQLWebSocketHooks, createWebSocketPlugin };
@@ -0,0 +1,48 @@
1
+ import { handleProtocols } from "graphql-ws";
2
+ import { makeHooks } from "graphql-ws/use/crossws";
3
+ //#region src/cli/server/ws-handler.ts
4
+ /**
5
+ * Create WebSocket hooks for GraphQL subscriptions
6
+ *
7
+ * @param getSchema - Function to get the GraphQL schema
8
+ * @param context - Optional context to pass to resolvers
9
+ */
10
+ function createGraphQLWebSocketHooks(getSchema, context) {
11
+ return {
12
+ upgrade(request) {
13
+ const selected = handleProtocols(request.headers.get("sec-websocket-protocol") || "");
14
+ if (selected) return { headers: { "Sec-WebSocket-Protocol": selected } };
15
+ return {};
16
+ },
17
+ ...makeHooks({
18
+ schema: getSchema,
19
+ context: async (ctx) => {
20
+ const baseContext = { connectionParams: ctx.connectionParams };
21
+ if (context) return {
22
+ ...baseContext,
23
+ ...context
24
+ };
25
+ return baseContext;
26
+ }
27
+ })
28
+ };
29
+ }
30
+ /**
31
+ * Create crossws plugin configuration for srvx
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * import { plugin as ws } from 'crossws/server'
36
+ * import { createWebSocketPlugin } from './ws-handler'
37
+ *
38
+ * const server = serve({
39
+ * plugins: [ws(createWebSocketPlugin(getSchema))],
40
+ * fetch(req) { ... }
41
+ * })
42
+ * ```
43
+ */
44
+ function createWebSocketPlugin(getSchema, context) {
45
+ return createGraphQLWebSocketHooks(getSchema, context);
46
+ }
47
+ //#endregion
48
+ export { createGraphQLWebSocketHooks, createWebSocketPlugin };
@@ -0,0 +1,2 @@
1
+ import { CLIConfig, DEFAULT_CLI_CONFIG, defineConfig } from "./cli/config.mjs";
2
+ export { type CLIConfig, DEFAULT_CLI_CONFIG, defineConfig };
@@ -0,0 +1,2 @@
1
+ import { DEFAULT_CLI_CONFIG, defineConfig } from "./cli/config.mjs";
2
+ export { DEFAULT_CLI_CONFIG, defineConfig };