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,82 @@
1
+ import { LOG_TAG } from "../../core/constants.mjs";
2
+ import { generateDirectiveSchemas } from "../../core/utils/directive-parser.mjs";
3
+ import { resolveExtendDirs as resolveExtendDirs$1, scanAllExtendSources } from "../../core/extend/loader.mjs";
4
+ import consola from "consola";
5
+
6
+ //#region src/nitro/setup/extend-loader.ts
7
+ const logger = consola.withTag(LOG_TAG);
8
+ /**
9
+ * Resolve extend directories for file watching
10
+ */
11
+ async function resolveExtendDirs(nitro) {
12
+ const extend = nitro.options.graphql?.extend;
13
+ return resolveExtendDirs$1(extend, nitro.options.rootDir);
14
+ }
15
+ /**
16
+ * Resolve extend configuration and add files to Nitro scan results
17
+ */
18
+ async function resolveExtendConfig(nitro, options = {}) {
19
+ const extend = nitro.options.graphql?.extend;
20
+ if (!extend || !Array.isArray(extend) || extend.length === 0) return;
21
+ const stats = applyExtendResult(nitro, await scanAllExtendSources(extend, nitro.options.rootDir));
22
+ if (stats.directives > 0) {
23
+ const directiveSchemas = await generateDirectiveSchemas(nitro.scanDirectives, nitro.graphql.buildDir);
24
+ nitro.graphql.directiveSchemas = directiveSchemas;
25
+ }
26
+ if (!options.silent && (stats.schemas > 0 || stats.resolvers > 0 || stats.directives > 0 || stats.documents > 0)) {
27
+ const parts = [];
28
+ if (stats.schemas > 0) parts.push(`${stats.schemas} schema(s)`);
29
+ if (stats.resolvers > 0) parts.push(`${stats.resolvers} resolver(s)`);
30
+ if (stats.directives > 0) parts.push(`${stats.directives} directive(s)`);
31
+ if (stats.documents > 0) parts.push(`${stats.documents} document(s)`);
32
+ if (stats.configs > 0) parts.push(`${stats.configs} config(s)`);
33
+ if (stats.programmaticSchemas > 0) parts.push(`${stats.programmaticSchemas} programmatic schema(s)`);
34
+ logger.info(`Extended with ${parts.join(", ")}`);
35
+ }
36
+ }
37
+ /**
38
+ * Apply extend scan result to Nitro state
39
+ */
40
+ function applyExtendResult(nitro, result) {
41
+ let schemasAdded = 0;
42
+ let resolversAdded = 0;
43
+ let directivesAdded = 0;
44
+ let documentsAdded = 0;
45
+ let configsAdded = 0;
46
+ let programmaticSchemasAdded = 0;
47
+ for (const schemaPath of result.schemas) if (!nitro.scanSchemas.includes(schemaPath)) {
48
+ nitro.scanSchemas.push(schemaPath);
49
+ schemasAdded++;
50
+ }
51
+ for (const resolver of result.resolvers) if (!nitro.scanResolvers.some((r) => r.specifier === resolver.specifier)) {
52
+ nitro.scanResolvers.push(resolver);
53
+ resolversAdded++;
54
+ }
55
+ for (const directive of result.directives) if (!nitro.scanDirectives.some((d) => d.specifier === directive.specifier)) {
56
+ nitro.scanDirectives.push(directive);
57
+ directivesAdded++;
58
+ }
59
+ for (const docPath of result.documents) if (!nitro.scanDocuments.includes(docPath)) {
60
+ nitro.scanDocuments.push(docPath);
61
+ documentsAdded++;
62
+ }
63
+ if (result.configPath && !nitro.graphql.extendConfigs.includes(result.configPath)) {
64
+ nitro.graphql.extendConfigs.push(result.configPath);
65
+ configsAdded++;
66
+ }
67
+ if (result.schemaPath && !nitro.graphql.extendSchemas.includes(result.schemaPath)) {
68
+ nitro.graphql.extendSchemas.push(result.schemaPath);
69
+ programmaticSchemasAdded++;
70
+ }
71
+ return {
72
+ schemas: schemasAdded,
73
+ resolvers: resolversAdded,
74
+ directives: directivesAdded,
75
+ documents: documentsAdded,
76
+ configs: configsAdded,
77
+ programmaticSchemas: programmaticSchemasAdded
78
+ };
79
+ }
80
+
81
+ //#endregion
82
+ export { resolveExtendConfig, resolveExtendDirs };
@@ -0,0 +1,18 @@
1
+ import { FSWatcher } from "chokidar";
2
+ import { Nitro } from "nitro/types";
3
+
4
+ //#region src/nitro/setup/file-watcher.d.ts
5
+ /**
6
+ * Setup file watcher for GraphQL files (schemas, resolvers, directives, documents)
7
+ * Watches for changes and triggers type regeneration and dev server reload
8
+ *
9
+ * Uses core watcher module with Nitro-specific callbacks.
10
+ */
11
+ declare function setupFileWatcher(nitro: Nitro, watchDirs: string[]): FSWatcher;
12
+ /**
13
+ * Determine which directories to watch based on framework and configuration
14
+ * Note: Layer directories are now handled via extendDirs (passed from extend-loader)
15
+ */
16
+ declare function getWatchDirectories(nitro: Nitro, extendDirs?: string[]): string[];
17
+ //#endregion
18
+ export { getWatchDirectories, setupFileWatcher };
@@ -0,0 +1,63 @@
1
+ import { LOG_TAG } from "../../core/constants.mjs";
2
+ import { generateClientTypes, generateServerTypes } from "../codegen.mjs";
3
+ import { createCoreWatcher } from "../../core/watcher/index.mjs";
4
+ import { performGraphQLScan, shouldScanLocalFiles } from "./scanner.mjs";
5
+ import consola from "consola";
6
+ import { join } from "pathe";
7
+
8
+ //#region src/nitro/setup/file-watcher.ts
9
+ const logger = consola.withTag(LOG_TAG);
10
+ /**
11
+ * Setup file watcher for GraphQL files (schemas, resolvers, directives, documents)
12
+ * Watches for changes and triggers type regeneration and dev server reload
13
+ *
14
+ * Uses core watcher module with Nitro-specific callbacks.
15
+ */
16
+ function setupFileWatcher(nitro, watchDirs) {
17
+ return createCoreWatcher({
18
+ watchDirs,
19
+ serverDir: nitro.graphql.serverDir,
20
+ debounceMs: 150
21
+ }, {
22
+ onServerChange: async () => {
23
+ await performGraphQLScan(nitro, {
24
+ silent: true,
25
+ isRescan: true
26
+ });
27
+ await generateServerTypes(nitro, { silent: true });
28
+ await generateClientTypes(nitro, { silent: true });
29
+ logger.success("Types regenerated");
30
+ await nitro.hooks.callHook("dev:reload");
31
+ },
32
+ onClientChange: async () => {
33
+ await generateClientTypes(nitro, { silent: true });
34
+ logger.success("Client types regenerated");
35
+ },
36
+ onError: (error) => {
37
+ logger.error("Watcher error:", error);
38
+ }
39
+ });
40
+ }
41
+ /**
42
+ * Determine which directories to watch based on framework and configuration
43
+ * Note: Layer directories are now handled via extendDirs (passed from extend-loader)
44
+ */
45
+ function getWatchDirectories(nitro, extendDirs = []) {
46
+ const watchDirs = [];
47
+ const scanLocal = shouldScanLocalFiles(nitro);
48
+ watchDirs.push(nitro.graphql.clientDir);
49
+ if (scanLocal) watchDirs.push(nitro.graphql.serverDir);
50
+ for (const dir of extendDirs) if (!watchDirs.includes(dir)) watchDirs.push(dir);
51
+ if (nitro.options.graphql?.externalServices?.length) {
52
+ for (const service of nitro.options.graphql.externalServices) if (service.documents?.length) for (const pattern of service.documents) {
53
+ if (!pattern) continue;
54
+ const baseDir = pattern.split("**")[0]?.replace(/\/$/, "") || ".";
55
+ const resolvedDir = join(nitro.options.rootDir, baseDir);
56
+ if (!watchDirs.includes(resolvedDir)) watchDirs.push(resolvedDir);
57
+ }
58
+ }
59
+ return watchDirs;
60
+ }
61
+
62
+ //#endregion
63
+ export { getWatchDirectories, setupFileWatcher };
@@ -0,0 +1,16 @@
1
+ import { SecurityConfig } from "../types.mjs";
2
+ import { Nitro } from "nitro/types";
3
+
4
+ //#region src/nitro/setup/logging.d.ts
5
+ /**
6
+ * Resolves security configuration with environment-aware defaults
7
+ * In production: introspection off, playground off, errors masked, suggestions disabled
8
+ * In development: introspection on, playground on, errors shown, suggestions enabled
9
+ */
10
+ declare function resolveSecurityConfig(config?: SecurityConfig): Required<SecurityConfig>;
11
+ /**
12
+ * Log startup information
13
+ */
14
+ declare function logStartupInfo(nitro: Nitro, serverEnabled: boolean): void;
15
+ //#endregion
16
+ export { logStartupInfo, resolveSecurityConfig };
@@ -0,0 +1,66 @@
1
+ import consola from "consola";
2
+
3
+ //#region src/nitro/setup/logging.ts
4
+ /**
5
+ * Resolves security configuration with environment-aware defaults
6
+ * In production: introspection off, playground off, errors masked, suggestions disabled
7
+ * In development: introspection on, playground on, errors shown, suggestions enabled
8
+ */
9
+ function resolveSecurityConfig(config) {
10
+ const isProd = process.env.NODE_ENV === "production";
11
+ return {
12
+ introspection: config?.introspection ?? !isProd,
13
+ playground: config?.playground ?? !isProd,
14
+ maskErrors: config?.maskErrors ?? isProd,
15
+ disableSuggestions: config?.disableSuggestions ?? isProd
16
+ };
17
+ }
18
+ /**
19
+ * Log startup information
20
+ */
21
+ function logStartupInfo(nitro, serverEnabled) {
22
+ const externalServicesCount = nitro.options.graphql?.externalServices?.length || 0;
23
+ const docs = nitro.scanDocuments || [];
24
+ const isProd = process.env.NODE_ENV === "production";
25
+ if (serverEnabled) {
26
+ const securityConfig = resolveSecurityConfig(nitro.options.graphql?.security);
27
+ const framework = nitro.options.graphql?.framework || "unknown";
28
+ const schemas = nitro.scanSchemas?.length || 0;
29
+ const resolvers = nitro.scanResolvers?.length || 0;
30
+ consola.box({
31
+ title: "Nitro GraphQL",
32
+ message: [
33
+ `Framework: ${framework}`,
34
+ `Environment: ${isProd ? "production" : "development"}`,
35
+ `Schemas: ${schemas}`,
36
+ `Resolvers: ${resolvers}`,
37
+ externalServicesCount > 0 ? `External Services: ${externalServicesCount}` : "",
38
+ docs.length > 0 ? `Documents: ${docs.length}` : "",
39
+ "",
40
+ "Security:",
41
+ `├─ Introspection: ${securityConfig.introspection ? "enabled" : "disabled"}`,
42
+ `├─ Playground: ${securityConfig.playground ? "enabled" : "disabled"}`,
43
+ `├─ Error Masking: ${securityConfig.maskErrors ? "enabled" : "disabled"}`,
44
+ `└─ Field Suggestions: ${securityConfig.disableSuggestions ? "disabled" : "enabled"}`
45
+ ].filter(Boolean).join("\n"),
46
+ style: {
47
+ borderColor: isProd ? "yellow" : "cyan",
48
+ borderStyle: "rounded"
49
+ }
50
+ });
51
+ } else consola.box({
52
+ title: "Nitro GraphQL (Client Only)",
53
+ message: [
54
+ "Server mode: disabled",
55
+ `External Services: ${externalServicesCount}`,
56
+ `Documents: ${docs.length}`
57
+ ].join("\n"),
58
+ style: {
59
+ borderColor: "blue",
60
+ borderStyle: "rounded"
61
+ }
62
+ });
63
+ }
64
+
65
+ //#endregion
66
+ export { logStartupInfo, resolveSecurityConfig };
@@ -0,0 +1,24 @@
1
+ import { Nitro } from "nitro/types";
2
+
3
+ //#region src/nitro/setup/rollup-integration.d.ts
4
+ /**
5
+ * Configure noExternals to ensure nitro-graphql route handlers are bundled
6
+ * This is critical for Nuxt integration where node_modules are externalized by default.
7
+ * Without this, the #nitro-graphql/* virtual imports in handlers would fail at runtime.
8
+ */
9
+ declare function setupNoExternals(nitro: Nitro): void;
10
+ /**
11
+ * Setup Rollup/Rolldown chunking configuration for GraphQL files
12
+ * Creates separate chunks for schemas and resolvers to optimize bundle size
13
+ *
14
+ * Note: For Rolldown, we only use manualChunks (not advancedChunks) to avoid
15
+ * interfering with Nitro's node_modules chunking which uses advancedChunks.
16
+ */
17
+ declare function setupRollupChunking(nitro: Nitro): void;
18
+ /**
19
+ * Configure external dependencies for Rollup
20
+ * Marks codegen and federation packages as external
21
+ */
22
+ declare function setupRollupExternals(nitro: Nitro): void;
23
+ //#endregion
24
+ export { setupNoExternals, setupRollupChunking, setupRollupExternals };
@@ -0,0 +1,63 @@
1
+ //#region src/nitro/setup/rollup-integration.ts
2
+ /**
3
+ * Configure noExternals to ensure nitro-graphql route handlers are bundled
4
+ * This is critical for Nuxt integration where node_modules are externalized by default.
5
+ * Without this, the #nitro-graphql/* virtual imports in handlers would fail at runtime.
6
+ */
7
+ function setupNoExternals(nitro) {
8
+ const routePatterns = [/nitro-graphql[/\\]dist[/\\]nitro[/\\]routes/, /nitro-graphql[/\\]dist[/\\]core[/\\]schema/];
9
+ if (nitro.options.noExternals === true) return;
10
+ if (!Array.isArray(nitro.options.noExternals)) nitro.options.noExternals = [];
11
+ nitro.options.noExternals.push(...routePatterns);
12
+ }
13
+ /**
14
+ * Setup Rollup/Rolldown chunking configuration for GraphQL files
15
+ * Creates separate chunks for schemas and resolvers to optimize bundle size
16
+ *
17
+ * Note: For Rolldown, we only use manualChunks (not advancedChunks) to avoid
18
+ * interfering with Nitro's node_modules chunking which uses advancedChunks.
19
+ */
20
+ function setupRollupChunking(nitro) {
21
+ nitro.hooks.hook("rollup:before", (_, rollupConfig) => {});
22
+ }
23
+ /**
24
+ * Configure external dependencies for Rollup
25
+ * Marks codegen and federation packages as external
26
+ */
27
+ function setupRollupExternals(nitro) {
28
+ nitro.hooks.hook("rollup:before", (_, rollupConfig) => {
29
+ rollupConfig.external = rollupConfig.external || [];
30
+ const allExternals = [...[
31
+ "oxc-parser",
32
+ "@oxc-parser",
33
+ "nitro-graphql/native",
34
+ "nitro-graphql-darwin-arm64",
35
+ "nitro-graphql-darwin-x64",
36
+ "nitro-graphql-darwin-universal",
37
+ "nitro-graphql-linux-x64-gnu",
38
+ "nitro-graphql-linux-x64-musl",
39
+ "nitro-graphql-linux-arm64-gnu",
40
+ "nitro-graphql-linux-arm64-musl",
41
+ "nitro-graphql-win32-x64-msvc",
42
+ "nitro-graphql-win32-x64-gnu",
43
+ "nitro-graphql-win32-arm64-msvc",
44
+ "nitro-graphql-win32-ia32-msvc"
45
+ ]];
46
+ if (!nitro.options.graphql?.federation?.enabled) allExternals.push(...[
47
+ "@apollo/subgraph",
48
+ "@apollo/federation-internals",
49
+ "@apollo/cache-control-types"
50
+ ]);
51
+ if (Array.isArray(rollupConfig.external)) rollupConfig.external.push(...allExternals);
52
+ else if (typeof rollupConfig.external === "function") {
53
+ const originalExternal = rollupConfig.external;
54
+ rollupConfig.external = (id, parent, isResolved) => {
55
+ if (allExternals.some((external) => id.includes(external))) return true;
56
+ return originalExternal(id, parent, isResolved);
57
+ };
58
+ }
59
+ });
60
+ }
61
+
62
+ //#endregion
63
+ export { setupNoExternals, setupRollupChunking, setupRollupExternals };
@@ -0,0 +1,13 @@
1
+ import { Nitro } from "nitro/types";
2
+
3
+ //#region src/nitro/setup/routes.d.ts
4
+ /**
5
+ * Register GraphQL route handlers
6
+ *
7
+ * Uses import.meta.resolve() to convert module specifiers to absolute paths.
8
+ * This ensures handlers are resolved correctly both in local development
9
+ * (monorepo symlink) and in CI/production (installed from npm).
10
+ */
11
+ declare function registerRouteHandlers(nitro: Nitro): void;
12
+ //#endregion
13
+ export { registerRouteHandlers };
@@ -0,0 +1,71 @@
1
+ import { ENDPOINT_DEBUG, GRAPHQL_HTTP_METHODS } from "../../core/constants.mjs";
2
+ import { fileURLToPath } from "node:url";
3
+
4
+ //#region src/nitro/setup/routes.ts
5
+ /**
6
+ * Resolve a module specifier to an absolute filesystem path.
7
+ * Uses import.meta.resolve() to handle both:
8
+ * - Local development (monorepo symlinks resolve to local source)
9
+ * - CI/Production (npm install resolves to node_modules)
10
+ */
11
+ function resolveHandler(specifier) {
12
+ return fileURLToPath(import.meta.resolve(specifier));
13
+ }
14
+ /**
15
+ * Register GraphQL route handlers
16
+ *
17
+ * Uses import.meta.resolve() to convert module specifiers to absolute paths.
18
+ * This ensures handlers are resolved correctly both in local development
19
+ * (monorepo symlink) and in CI/production (installed from npm).
20
+ */
21
+ function registerRouteHandlers(nitro) {
22
+ const framework = nitro.options.graphql?.framework;
23
+ const subscriptions = nitro.options.graphql?.subscriptions;
24
+ const endpoint = nitro.options.runtimeConfig.graphql?.endpoint?.graphql || "/api/graphql";
25
+ if (framework === "graphql-yoga") {
26
+ for (const method of GRAPHQL_HTTP_METHODS) nitro.options.handlers.push({
27
+ route: endpoint,
28
+ handler: resolveHandler("nitro-graphql/nitro/routes/graphql-yoga"),
29
+ method
30
+ });
31
+ nitro.options.handlers.push({
32
+ route: `${endpoint}/sandbox.js`,
33
+ handler: resolveHandler("nitro-graphql/nitro/routes/apollo-sandbox-script"),
34
+ method: "GET"
35
+ });
36
+ if (subscriptions?.enabled && subscriptions.websocket?.enabled !== false) {
37
+ const wsPath = subscriptions.websocket?.path || `${endpoint}/ws`;
38
+ nitro.options.handlers.push({
39
+ route: wsPath,
40
+ handler: resolveHandler("nitro-graphql/nitro/routes/graphql-yoga-ws")
41
+ });
42
+ }
43
+ }
44
+ if (framework === "apollo-server") {
45
+ for (const method of GRAPHQL_HTTP_METHODS) nitro.options.handlers.push({
46
+ route: endpoint,
47
+ handler: resolveHandler("nitro-graphql/nitro/routes/apollo-server"),
48
+ method
49
+ });
50
+ if (subscriptions?.enabled && subscriptions.websocket?.enabled !== false) {
51
+ const wsPath = subscriptions.websocket?.path || `${endpoint}/ws`;
52
+ nitro.options.handlers.push({
53
+ route: wsPath,
54
+ handler: resolveHandler("nitro-graphql/nitro/routes/apollo-server-ws")
55
+ });
56
+ }
57
+ }
58
+ nitro.options.handlers.push({
59
+ route: nitro.options.runtimeConfig.graphql?.endpoint?.healthCheck || "/api/graphql/health",
60
+ handler: resolveHandler("nitro-graphql/nitro/routes/health"),
61
+ method: "GET"
62
+ });
63
+ if (nitro.options.dev) nitro.options.handlers.push({
64
+ route: ENDPOINT_DEBUG,
65
+ handler: resolveHandler("nitro-graphql/nitro/routes/debug"),
66
+ method: "GET"
67
+ });
68
+ }
69
+
70
+ //#endregion
71
+ export { registerRouteHandlers };
@@ -0,0 +1,59 @@
1
+ import { ExtendSource } from "../types.mjs";
2
+ import { Nitro } from "nitro/types";
3
+
4
+ //#region src/nitro/setup/scanner.d.ts
5
+ interface ScanOptions {
6
+ /** Silent mode - suppress logging */
7
+ silent?: boolean;
8
+ /** Is this a rescan (dev mode hot reload) */
9
+ isRescan?: boolean;
10
+ }
11
+ interface ScanResult {
12
+ schemas: number;
13
+ resolvers: number;
14
+ directives: number;
15
+ documents: number;
16
+ }
17
+ /**
18
+ * Check if local file scanning should be performed
19
+ * Centralized helper to avoid scattered skipLocalScan checks
20
+ */
21
+ declare function shouldScanLocalFiles(nitro: Nitro): boolean;
22
+ /**
23
+ * Check if server-side GraphQL is enabled
24
+ */
25
+ declare function isServerEnabled(nitro: Nitro): boolean;
26
+ /**
27
+ * Get extend sources from config
28
+ */
29
+ declare function getExtendSources(nitro: Nitro): ExtendSource[] | undefined;
30
+ /**
31
+ * Scan local GraphQL files (schemas, resolvers, directives, documents)
32
+ * This is the low-level scan function - use performGraphQLScan for full workflow
33
+ */
34
+ declare function scanLocalFiles(nitro: Nitro): Promise<ScanResult>;
35
+ /**
36
+ * Scan only client documents (for external services or client-only mode)
37
+ */
38
+ declare function scanDocumentsOnly(nitro: Nitro): Promise<number>;
39
+ /**
40
+ * Initialize empty scan results (for skipLocalScan mode)
41
+ */
42
+ declare function initializeEmptyScanResults(nitro: Nitro): void;
43
+ /**
44
+ * Perform complete GraphQL scan workflow
45
+ * This is the main entry point for both initial setup and dev mode rescan
46
+ *
47
+ * Workflow:
48
+ * 1. Check skipLocalScan flag
49
+ * 2. Scan local files if enabled
50
+ * 3. Resolve extend config (append to results)
51
+ * 4. Log diagnostics if needed
52
+ */
53
+ declare function performGraphQLScan(nitro: Nitro, options?: ScanOptions): Promise<void>;
54
+ /**
55
+ * Log resolver diagnostics for development
56
+ */
57
+ declare function logResolverDiagnostics(nitro: Nitro): void;
58
+ //#endregion
59
+ export { ScanOptions, ScanResult, getExtendSources, initializeEmptyScanResults, isServerEnabled, logResolverDiagnostics, performGraphQLScan, scanDocumentsOnly, scanLocalFiles, shouldScanLocalFiles };
@@ -0,0 +1,120 @@
1
+ import { LOG_TAG } from "../../core/constants.mjs";
2
+ import { generateDirectiveSchemas } from "../../core/utils/directive-parser.mjs";
3
+ import { NitroAdapter } from "../adapter.mjs";
4
+ import { resolveExtendConfig } from "./extend-loader.mjs";
5
+ import consola from "consola";
6
+
7
+ //#region src/nitro/setup/scanner.ts
8
+ const logger = consola.withTag(LOG_TAG);
9
+ /**
10
+ * Check if local file scanning should be performed
11
+ * Centralized helper to avoid scattered skipLocalScan checks
12
+ */
13
+ function shouldScanLocalFiles(nitro) {
14
+ return nitro.options.graphql?.skipLocalScan !== true;
15
+ }
16
+ /**
17
+ * Check if server-side GraphQL is enabled
18
+ */
19
+ function isServerEnabled(nitro) {
20
+ return nitro.options.graphql?.server !== false;
21
+ }
22
+ /**
23
+ * Get extend sources from config
24
+ */
25
+ function getExtendSources(nitro) {
26
+ const extend = nitro.options.graphql?.extend;
27
+ return Array.isArray(extend) ? extend : void 0;
28
+ }
29
+ /**
30
+ * Scan local GraphQL files (schemas, resolvers, directives, documents)
31
+ * This is the low-level scan function - use performGraphQLScan for full workflow
32
+ */
33
+ async function scanLocalFiles(nitro) {
34
+ const directivesResult = await NitroAdapter.scanDirectives(nitro);
35
+ nitro.scanDirectives = directivesResult.items;
36
+ const directiveSchemas = await generateDirectiveSchemas(directivesResult.items, nitro.graphql.buildDir);
37
+ nitro.graphql.directiveSchemas = directiveSchemas;
38
+ const schemasResult = await NitroAdapter.scanSchemas(nitro);
39
+ nitro.scanSchemas = schemasResult.items;
40
+ const docsResult = await NitroAdapter.scanDocuments(nitro);
41
+ nitro.scanDocuments = docsResult.items;
42
+ const resolversResult = await NitroAdapter.scanResolvers(nitro);
43
+ nitro.scanResolvers = resolversResult.items;
44
+ return {
45
+ schemas: schemasResult.items.length,
46
+ resolvers: resolversResult.items.length,
47
+ directives: directivesResult.items.length,
48
+ documents: docsResult.items.length
49
+ };
50
+ }
51
+ /**
52
+ * Scan only client documents (for external services or client-only mode)
53
+ */
54
+ async function scanDocumentsOnly(nitro) {
55
+ const result = await NitroAdapter.scanDocuments(nitro);
56
+ nitro.scanDocuments = result.items;
57
+ return result.items.length;
58
+ }
59
+ /**
60
+ * Initialize empty scan results (for skipLocalScan mode)
61
+ */
62
+ function initializeEmptyScanResults(nitro) {
63
+ nitro.scanSchemas = [];
64
+ nitro.scanResolvers = [];
65
+ nitro.scanDirectives = [];
66
+ }
67
+ /**
68
+ * Perform complete GraphQL scan workflow
69
+ * This is the main entry point for both initial setup and dev mode rescan
70
+ *
71
+ * Workflow:
72
+ * 1. Check skipLocalScan flag
73
+ * 2. Scan local files if enabled
74
+ * 3. Resolve extend config (append to results)
75
+ * 4. Log diagnostics if needed
76
+ */
77
+ async function performGraphQLScan(nitro, options = {}) {
78
+ const { silent = false, isRescan = false } = options;
79
+ const serverEnabled = isServerEnabled(nitro);
80
+ const scanLocal = shouldScanLocalFiles(nitro);
81
+ const extendSources = getExtendSources(nitro);
82
+ if (isRescan && !scanLocal && extendSources?.length) return;
83
+ if (!scanLocal) {
84
+ if (!isRescan && !silent) if (extendSources?.length) logger.info(`Using ${extendSources.length} extend source(s), skipping local scanning`);
85
+ else logger.info("Skipping local scanning (skipLocalScan: true)");
86
+ initializeEmptyScanResults(nitro);
87
+ await scanDocumentsOnly(nitro);
88
+ } else if (serverEnabled) await scanLocalFiles(nitro);
89
+ else await scanDocumentsOnly(nitro);
90
+ await resolveExtendConfig(nitro, { silent: silent || isRescan });
91
+ }
92
+ /**
93
+ * Log resolver diagnostics for development
94
+ */
95
+ function logResolverDiagnostics(nitro) {
96
+ const resolvers = nitro.scanResolvers || [];
97
+ if (resolvers.length > 0) {
98
+ const totalExports = resolvers.reduce((sum, r) => sum + r.imports.length, 0);
99
+ const typeCount = {
100
+ query: 0,
101
+ mutation: 0,
102
+ resolver: 0,
103
+ type: 0,
104
+ subscription: 0,
105
+ directive: 0
106
+ };
107
+ for (const resolver of resolvers) for (const imp of resolver.imports) if (imp.type in typeCount) typeCount[imp.type]++;
108
+ const breakdown = [];
109
+ if (typeCount.query > 0) breakdown.push(`${typeCount.query} query`);
110
+ if (typeCount.mutation > 0) breakdown.push(`${typeCount.mutation} mutation`);
111
+ if (typeCount.resolver > 0) breakdown.push(`${typeCount.resolver} resolver`);
112
+ if (typeCount.type > 0) breakdown.push(`${typeCount.type} type`);
113
+ if (typeCount.subscription > 0) breakdown.push(`${typeCount.subscription} subscription`);
114
+ if (typeCount.directive > 0) breakdown.push(`${typeCount.directive} directive`);
115
+ if (breakdown.length > 0) logger.success(`${totalExports} resolver export(s): ${breakdown.join(", ")}`);
116
+ } else logger.warn("No resolvers found. Check /_nitro/graphql/debug for details.");
117
+ }
118
+
119
+ //#endregion
120
+ export { getExtendSources, initializeEmptyScanResults, isServerEnabled, logResolverDiagnostics, performGraphQLScan, scanDocumentsOnly, scanLocalFiles, shouldScanLocalFiles };
@@ -0,0 +1,10 @@
1
+ import { Nitro, NitroTypes } from "nitro/types";
2
+
3
+ //#region src/nitro/setup/ts-config.d.ts
4
+ /**
5
+ * Setup TypeScript path aliases for GraphQL types
6
+ * Called via nitro:config hook to extend tsconfig.json
7
+ */
8
+ declare function setupTypeScriptPaths(nitro: Nitro, types: NitroTypes): void;
9
+ //#endregion
10
+ export { setupTypeScriptPaths };