nitro-graphql 2.0.0-beta.70 → 2.0.0-beta.73

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (228) hide show
  1. package/README.md +1 -1
  2. package/dist/cli/adapter.d.mts +0 -3
  3. package/dist/cli/adapter.mjs +7 -32
  4. package/dist/cli/commands/build.d.mts +2 -2
  5. package/dist/cli/commands/build.mjs +1 -3
  6. package/dist/cli/commands/dev.d.mts +2 -2
  7. package/dist/cli/commands/dev.mjs +1 -3
  8. package/dist/cli/commands/generate.mjs +10 -10
  9. package/dist/cli/commands/init.mjs +4 -4
  10. package/dist/cli/commands/validate.mjs +1 -3
  11. package/dist/cli/completions.mjs +1 -3
  12. package/dist/cli/config.d.mts +4 -5
  13. package/dist/cli/config.mjs +4 -3
  14. package/dist/cli/index.d.mts +3 -6
  15. package/dist/cli/index.mjs +2 -4
  16. package/dist/cli/server/debug-handler.mjs +2 -5
  17. package/dist/cli/server/dev-server.mjs +1 -3
  18. package/dist/cli/server/graphql-handler.mjs +3 -4
  19. package/dist/cli/server/health-handler.mjs +1 -2
  20. package/dist/cli/server/loader.mjs +1 -3
  21. package/dist/cli/server/sandbox-handler.mjs +1 -3
  22. package/dist/cli/server/watcher.mjs +2 -4
  23. package/dist/cli/server/ws-handler.mjs +1 -3
  24. package/dist/config.mjs +1 -2
  25. package/dist/core/codegen/client.d.mts +4 -27
  26. package/dist/core/codegen/client.mjs +26 -447
  27. package/dist/core/codegen/document-loader.mjs +1 -3
  28. package/dist/core/codegen/file-header.d.mts +7 -0
  29. package/dist/core/codegen/file-header.mjs +12 -0
  30. package/dist/core/codegen/index.d.mts +7 -5
  31. package/dist/core/codegen/index.mjs +7 -6
  32. package/dist/core/codegen/{runtime.d.mts → runtime-generator.d.mts} +1 -3
  33. package/dist/core/codegen/{runtime.mjs → runtime-generator.mjs} +7 -6
  34. package/dist/core/codegen/schema-loader.d.mts +2 -7
  35. package/dist/core/codegen/schema-loader.mjs +66 -73
  36. package/dist/core/codegen/server-type-helpers.d.mts +14 -0
  37. package/dist/core/codegen/server-type-helpers.mjs +76 -0
  38. package/dist/core/codegen/server.d.mts +1 -15
  39. package/dist/core/codegen/server.mjs +15 -107
  40. package/dist/core/codegen/subscription-extractor.d.mts +20 -0
  41. package/dist/core/codegen/subscription-extractor.mjs +30 -0
  42. package/dist/core/codegen/validation.mjs +1 -3
  43. package/dist/core/codegen/vue-subscription-builder.d.mts +10 -0
  44. package/dist/core/codegen/vue-subscription-builder.mjs +351 -0
  45. package/dist/core/constants.d.mts +5 -53
  46. package/dist/core/constants.mjs +13 -56
  47. package/dist/core/create-config.d.mts +31 -0
  48. package/dist/core/create-config.mjs +42 -0
  49. package/dist/core/debug/index.d.mts +2 -2
  50. package/dist/core/debug/index.mjs +2 -3
  51. package/dist/core/debug/template.d.mts +1 -5
  52. package/dist/core/debug/template.mjs +5 -4
  53. package/dist/core/extend/index.mjs +1 -2
  54. package/dist/core/extend/loader.d.mts +0 -1
  55. package/dist/core/extend/loader.mjs +60 -92
  56. package/dist/core/index.d.mts +22 -21
  57. package/dist/core/index.mjs +19 -16
  58. package/dist/core/manifest.mjs +4 -4
  59. package/dist/core/pubsub/index.d.mts +2 -109
  60. package/dist/core/pubsub/index.mjs +2 -148
  61. package/dist/core/pubsub/memory-pubsub.d.mts +109 -0
  62. package/dist/core/pubsub/memory-pubsub.mjs +146 -0
  63. package/dist/core/scanning/ast-scanner.mjs +5 -5
  64. package/dist/core/scanning/directives.mjs +3 -5
  65. package/dist/core/scanning/documents.d.mts +4 -3
  66. package/dist/core/scanning/documents.mjs +4 -5
  67. package/dist/core/scanning/{common.d.mts → file-scanner.d.mts} +1 -1
  68. package/dist/core/scanning/{common.mjs → file-scanner.mjs} +3 -13
  69. package/dist/core/scanning/index.d.mts +3 -3
  70. package/dist/core/scanning/index.mjs +3 -4
  71. package/dist/core/scanning/resolvers.mjs +9 -11
  72. package/dist/core/scanning/schemas.d.mts +1 -5
  73. package/dist/core/scanning/schemas.mjs +2 -26
  74. package/dist/core/schema/builder.d.mts +4 -2
  75. package/dist/core/schema/builder.mjs +4 -4
  76. package/dist/core/schema/federation.mjs +1 -3
  77. package/dist/core/schema/index.d.mts +2 -2
  78. package/dist/core/schema/index.mjs +2 -3
  79. package/dist/core/server/apollo.d.mts +20 -0
  80. package/dist/core/server/apollo.mjs +54 -0
  81. package/dist/core/server/index.d.mts +4 -2
  82. package/dist/core/server/index.mjs +3 -3
  83. package/dist/core/server/sandbox.mjs +1 -2
  84. package/dist/core/server/types.d.mts +7 -14
  85. package/dist/core/server/types.mjs +15 -1
  86. package/dist/core/server/yoga.d.mts +1 -7
  87. package/dist/core/server/yoga.mjs +4 -15
  88. package/dist/core/types/adapter.d.mts +3 -40
  89. package/dist/core/types/adapter.mjs +1 -1
  90. package/dist/core/types/codegen.d.mts +22 -45
  91. package/dist/core/types/codegen.mjs +1 -1
  92. package/dist/core/types/config.d.mts +33 -121
  93. package/dist/core/types/config.mjs +1 -1
  94. package/dist/core/types/define.d.mts +8 -5
  95. package/dist/core/types/define.mjs +1 -1
  96. package/dist/core/types/index.d.mts +5 -4
  97. package/dist/core/types/index.mjs +1 -1
  98. package/dist/core/types/scanning.d.mts +4 -1
  99. package/dist/core/types/scanning.mjs +1 -1
  100. package/dist/core/types/standard-schema.d.mts +64 -0
  101. package/dist/core/types/standard-schema.mjs +1 -0
  102. package/dist/core/utils/directive-parser.d.mts +8 -63
  103. package/dist/core/utils/directive-parser.mjs +114 -167
  104. package/dist/core/utils/errors.mjs +1 -3
  105. package/dist/core/utils/file-io.d.mts +1 -5
  106. package/dist/core/utils/file-io.mjs +1 -13
  107. package/dist/core/utils/imports.mjs +3 -4
  108. package/dist/core/utils/index.d.mts +5 -4
  109. package/dist/core/utils/index.mjs +6 -6
  110. package/dist/core/utils/logger.d.mts +1 -10
  111. package/dist/core/utils/logger.mjs +1 -21
  112. package/dist/core/utils/ofetch-templates.mjs +4 -6
  113. package/dist/core/utils/runtime.d.mts +1 -30
  114. package/dist/core/utils/runtime.mjs +2 -46
  115. package/dist/core/utils/string.d.mts +10 -0
  116. package/dist/core/utils/string.mjs +12 -0
  117. package/dist/core/utils/subscribe-templates.mjs +1 -2
  118. package/dist/core/validation/external-services.mjs +3 -3
  119. package/dist/core/validation/index.mjs +1 -2
  120. package/dist/core/watcher/create-watcher.d.mts +103 -0
  121. package/dist/core/watcher/create-watcher.mjs +143 -0
  122. package/dist/core/watcher/index.d.mts +2 -107
  123. package/dist/core/watcher/index.mjs +2 -141
  124. package/dist/define.d.mts +4 -2
  125. package/dist/define.mjs +8 -9
  126. package/dist/index.d.mts +4 -3
  127. package/dist/index.mjs +3 -4
  128. package/dist/nitro/adapter.d.mts +6 -11
  129. package/dist/nitro/adapter.mjs +12 -45
  130. package/dist/nitro/apollo.mjs +1 -3
  131. package/dist/nitro/codegen/client-types.d.mts +12 -0
  132. package/dist/nitro/codegen/client-types.mjs +73 -0
  133. package/dist/nitro/codegen/external-types.d.mts +8 -0
  134. package/dist/nitro/codegen/external-types.mjs +47 -0
  135. package/dist/nitro/codegen/index.d.mts +4 -0
  136. package/dist/nitro/codegen/index.mjs +4 -0
  137. package/dist/nitro/codegen/server-types.d.mts +12 -0
  138. package/dist/nitro/codegen/server-types.mjs +81 -0
  139. package/dist/nitro/defaults.d.mts +28 -0
  140. package/dist/nitro/defaults.mjs +34 -0
  141. package/dist/nitro/index.d.mts +11 -3
  142. package/dist/nitro/index.mjs +4 -6
  143. package/dist/nitro/paths.d.mts +3 -2
  144. package/dist/nitro/paths.mjs +14 -5
  145. package/dist/nitro/rollup.mjs +8 -8
  146. package/dist/nitro/routes/_ws-handler.d.mts +6 -0
  147. package/dist/nitro/routes/_ws-handler.mjs +49 -0
  148. package/dist/nitro/routes/apollo-sandbox-script.d.mts +2 -2
  149. package/dist/nitro/routes/apollo-sandbox-script.mjs +1 -3
  150. package/dist/nitro/routes/apollo-server-ws.d.mts +1 -1
  151. package/dist/nitro/routes/apollo-server-ws.mjs +10 -48
  152. package/dist/nitro/routes/apollo-server.d.mts +2 -2
  153. package/dist/nitro/routes/apollo-server.mjs +17 -58
  154. package/dist/nitro/routes/debug.d.mts +2 -2
  155. package/dist/nitro/routes/debug.mjs +4 -7
  156. package/dist/nitro/routes/graphql-yoga-ws.d.mts +3 -3
  157. package/dist/nitro/routes/graphql-yoga-ws.mjs +7 -48
  158. package/dist/nitro/routes/graphql-yoga.d.mts +2 -2
  159. package/dist/nitro/routes/graphql-yoga.mjs +8 -8
  160. package/dist/nitro/routes/health.d.mts +2 -2
  161. package/dist/nitro/routes/health.mjs +23 -27
  162. package/dist/nitro/setup/extend-loader.d.mts +6 -5
  163. package/dist/nitro/setup/extend-loader.mjs +31 -61
  164. package/dist/nitro/setup/file-watcher.mjs +9 -8
  165. package/dist/nitro/setup/logging.d.mts +1 -8
  166. package/dist/nitro/setup/logging.mjs +7 -24
  167. package/dist/nitro/setup/rollup-integration.mjs +36 -4
  168. package/dist/nitro/setup/routes.mjs +1 -3
  169. package/dist/nitro/setup/scanner.d.mts +8 -43
  170. package/dist/nitro/setup/scanner.mjs +56 -60
  171. package/dist/nitro/setup/security.d.mts +10 -0
  172. package/dist/nitro/setup/security.mjs +17 -0
  173. package/dist/nitro/setup/ts-config.mjs +1 -3
  174. package/dist/nitro/setup/type-generation.d.mts +13 -0
  175. package/dist/nitro/setup/type-generation.mjs +16 -0
  176. package/dist/nitro/setup.d.mts +4 -3
  177. package/dist/nitro/setup.mjs +88 -77
  178. package/dist/nitro/state.d.mts +32 -0
  179. package/dist/nitro/state.mjs +58 -0
  180. package/dist/nitro/types/augmentation.d.mts +59 -0
  181. package/dist/nitro/types/augmentation.mjs +1 -0
  182. package/dist/nitro/types/config.d.mts +327 -0
  183. package/dist/nitro/types/config.mjs +1 -0
  184. package/dist/nitro/types/define.d.mts +13 -0
  185. package/dist/nitro/types/define.mjs +1 -0
  186. package/dist/nitro/types/index.d.mts +10 -0
  187. package/dist/nitro/types/index.mjs +1 -0
  188. package/dist/nitro/virtual/debug-info.d.mts +9 -0
  189. package/dist/nitro/virtual/debug-info.mjs +35 -0
  190. package/dist/nitro/virtual/graphql-config.d.mts +9 -0
  191. package/dist/nitro/virtual/graphql-config.mjs +33 -0
  192. package/dist/nitro/virtual/index.d.mts +25 -0
  193. package/dist/nitro/virtual/index.mjs +45 -0
  194. package/dist/nitro/virtual/module-config.d.mts +9 -0
  195. package/dist/nitro/virtual/module-config.mjs +10 -0
  196. package/dist/nitro/virtual/pubsub.d.mts +9 -0
  197. package/dist/nitro/virtual/pubsub.mjs +17 -0
  198. package/dist/nitro/virtual/server-directives.d.mts +9 -0
  199. package/dist/nitro/virtual/server-directives.mjs +12 -0
  200. package/dist/nitro/virtual/server-resolvers.d.mts +9 -0
  201. package/dist/nitro/virtual/server-resolvers.mjs +17 -0
  202. package/dist/nitro/virtual/server-schemas.d.mts +9 -0
  203. package/dist/nitro/virtual/server-schemas.mjs +31 -0
  204. package/dist/nitro/virtual/stubs.d.mts +42 -10
  205. package/dist/nitro/virtual/stubs.mjs +1 -7
  206. package/dist/nitro/virtual/utils.d.mts +15 -0
  207. package/dist/nitro/virtual/utils.mjs +26 -0
  208. package/dist/nitro/virtual/validation-schemas.d.mts +9 -0
  209. package/dist/nitro/virtual/validation-schemas.mjs +33 -0
  210. package/dist/nuxt.mjs +4 -5
  211. package/dist/stubs/index.mjs +1 -1
  212. package/dist/subscribe/index.mjs +3 -4
  213. package/native/index.js +52 -52
  214. package/package.json +41 -41
  215. package/dist/cli/commands/index.d.mts +0 -5
  216. package/dist/cli/commands/index.mjs +0 -6
  217. package/dist/core/codegen/plugin.d.mts +0 -19
  218. package/dist/core/codegen/plugin.mjs +0 -30
  219. package/dist/core/config.d.mts +0 -45
  220. package/dist/core/config.mjs +0 -78
  221. package/dist/nitro/codegen.d.mts +0 -18
  222. package/dist/nitro/codegen.mjs +0 -173
  223. package/dist/nitro/config.d.mts +0 -50
  224. package/dist/nitro/config.mjs +0 -57
  225. package/dist/nitro/types.d.mts +0 -549
  226. package/dist/nitro/types.mjs +0 -1
  227. package/dist/nitro/virtual/generators.d.mts +0 -38
  228. package/dist/nitro/virtual/generators.mjs +0 -192
@@ -1,37 +1,34 @@
1
+ import { createMergedSchema } from "../../core/schema/builder.mjs";
2
+ import { execute, parse } from "graphql";
1
3
  import { defineEventHandler } from "nitro/h3";
2
- import { useRuntimeConfig } from "nitro/runtime-config";
3
- import { $fetch } from "ofetch";
4
-
4
+ import { moduleConfig } from "#nitro-graphql/module-config";
5
+ import { directives } from "#nitro-graphql/server-directives";
6
+ import { resolvers } from "#nitro-graphql/server-resolvers";
7
+ import { schemas } from "#nitro-graphql/server-schemas";
5
8
  //#region src/nitro/routes/health.ts
9
+ let schema = null;
10
+ async function getSchema() {
11
+ if (!schema) schema = await createMergedSchema({
12
+ schemas,
13
+ resolvers,
14
+ directives,
15
+ moduleConfig
16
+ });
17
+ return schema;
18
+ }
19
+ const HEALTH_QUERY = parse("query Health { __typename }");
6
20
  var health_default = defineEventHandler(async (event) => {
7
- const runtime = useRuntimeConfig();
8
- if (!runtime.graphql || !runtime.graphql.endpoint?.graphql) {
9
- event.res.status = 404;
10
- event.res.statusText = "Not Found";
11
- return {
12
- status: "error",
13
- message: "GraphQL health check endpoint is not configured",
14
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
15
- };
16
- }
17
21
  try {
18
- const response = await $fetch(runtime.graphql.endpoint?.graphql, {
19
- method: "POST",
20
- body: {
21
- query: "query Health { __typename }",
22
- operationName: "Health"
23
- },
24
- headers: {
25
- "Content-Type": "application/json",
26
- "Accept": "application/json"
27
- }
22
+ const result = await execute({
23
+ schema: await getSchema(),
24
+ document: HEALTH_QUERY
28
25
  });
29
- if (response && typeof response === "object" && "data" in response) return {
26
+ if (result.data) return {
30
27
  status: "healthy",
31
28
  message: "GraphQL server is running",
32
29
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
33
30
  };
34
- throw new Error("Invalid response from GraphQL server");
31
+ throw new Error(result.errors?.map((e) => e.message).join(", ") || "Invalid response from GraphQL server");
35
32
  } catch (error) {
36
33
  event.res.status = 503;
37
34
  event.res.statusText = "Service Unavailable";
@@ -42,6 +39,5 @@ var health_default = defineEventHandler(async (event) => {
42
39
  };
43
40
  }
44
41
  });
45
-
46
42
  //#endregion
47
- export { health_default as default };
43
+ export { health_default as default };
@@ -1,3 +1,4 @@
1
+ import { GraphQLScanState } from "../types/augmentation.mjs";
1
2
  import { Nitro } from "nitro/types";
2
3
 
3
4
  //#region src/nitro/setup/extend-loader.d.ts
@@ -5,12 +6,12 @@ import { Nitro } from "nitro/types";
5
6
  * Resolve extend directories for file watching
6
7
  */
7
8
  declare function resolveExtendDirs(nitro: Nitro): Promise<string[]>;
8
- interface ResolveExtendOptions {
9
- silent?: boolean;
10
- }
11
9
  /**
12
- * Resolve extend configuration and add files to Nitro scan results
10
+ * Resolve extend configuration and merge into scan state.
11
+ * Returns a new frozen state — does NOT mutate nitro.
13
12
  */
14
- declare function resolveExtendConfig(nitro: Nitro, options?: ResolveExtendOptions): Promise<void>;
13
+ declare function resolveExtendConfig(nitro: Nitro, state: GraphQLScanState, options?: {
14
+ silent?: boolean;
15
+ }): Promise<GraphQLScanState>;
15
16
  //#endregion
16
17
  export { resolveExtendConfig, resolveExtendDirs };
@@ -1,8 +1,8 @@
1
1
  import { LOG_TAG } from "../../core/constants.mjs";
2
2
  import { generateDirectiveSchemas } from "../../core/utils/directive-parser.mjs";
3
3
  import { resolveExtendDirs as resolveExtendDirs$1, scanAllExtendSources } from "../../core/extend/loader.mjs";
4
+ import { mergeScanState } from "../state.mjs";
4
5
  import consola from "consola";
5
-
6
6
  //#region src/nitro/setup/extend-loader.ts
7
7
  const logger = consola.withTag(LOG_TAG);
8
8
  /**
@@ -13,70 +13,40 @@ async function resolveExtendDirs(nitro) {
13
13
  return resolveExtendDirs$1(extend, nitro.options.rootDir);
14
14
  }
15
15
  /**
16
- * Resolve extend configuration and add files to Nitro scan results
16
+ * Resolve extend configuration and merge into scan state.
17
+ * Returns a new frozen state — does NOT mutate nitro.
17
18
  */
18
- async function resolveExtendConfig(nitro, options = {}) {
19
+ async function resolveExtendConfig(nitro, state, options = {}) {
19
20
  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)) {
21
+ if (!extend || !Array.isArray(extend) || extend.length === 0) return state;
22
+ const result = await scanAllExtendSources(extend, nitro.options.rootDir);
23
+ let newState = mergeScanState(state, result);
24
+ if (result.directives.length > 0) {
25
+ const directiveSchemas = await generateDirectiveSchemas([...newState.directives], nitro.graphql.buildDir);
26
+ newState = Object.freeze({
27
+ ...newState,
28
+ directiveSchemas
29
+ });
30
+ }
31
+ const added = {
32
+ schemas: newState.schemas.length - state.schemas.length,
33
+ resolvers: newState.resolvers.length - state.resolvers.length,
34
+ directives: newState.directives.length - state.directives.length,
35
+ documents: newState.documents.length - state.documents.length,
36
+ configs: newState.extendConfigs.length - state.extendConfigs.length,
37
+ programmaticSchemas: newState.extendSchemas.length - state.extendSchemas.length
38
+ };
39
+ if (!options.silent && Object.values(added).some((v) => v > 0)) {
27
40
  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)`);
41
+ if (added.schemas > 0) parts.push(`${added.schemas} schema(s)`);
42
+ if (added.resolvers > 0) parts.push(`${added.resolvers} resolver(s)`);
43
+ if (added.directives > 0) parts.push(`${added.directives} directive(s)`);
44
+ if (added.documents > 0) parts.push(`${added.documents} document(s)`);
45
+ if (added.configs > 0) parts.push(`${added.configs} config(s)`);
46
+ if (added.programmaticSchemas > 0) parts.push(`${added.programmaticSchemas} programmatic schema(s)`);
34
47
  logger.info(`Extended with ${parts.join(", ")}`);
35
48
  }
49
+ return newState;
36
50
  }
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
51
  //#endregion
82
- export { resolveExtendConfig, resolveExtendDirs };
52
+ export { resolveExtendConfig, resolveExtendDirs };
@@ -1,11 +1,13 @@
1
1
  import { LOG_TAG } from "../../core/constants.mjs";
2
- import { generateClientTypes, generateServerTypes } from "../codegen.mjs";
3
- import { createCoreWatcher } from "../../core/watcher/index.mjs";
2
+ import { refreshVirtualModules } from "../virtual/index.mjs";
3
+ import { createCoreWatcher } from "../../core/watcher/create-watcher.mjs";
4
+ import { generateClientTypes } from "../codegen/client-types.mjs";
4
5
  import { performGraphQLScan, shouldScanLocalFiles } from "./scanner.mjs";
6
+ import { regenerateTypes } from "./type-generation.mjs";
5
7
  import consola from "consola";
6
8
  import { join } from "pathe";
7
-
8
9
  //#region src/nitro/setup/file-watcher.ts
10
+ const TRAILING_SLASH_RE = /\/$/;
9
11
  const logger = consola.withTag(LOG_TAG);
10
12
  /**
11
13
  * Setup file watcher for GraphQL files (schemas, resolvers, directives, documents)
@@ -24,8 +26,8 @@ function setupFileWatcher(nitro, watchDirs) {
24
26
  silent: true,
25
27
  isRescan: true
26
28
  });
27
- await generateServerTypes(nitro, { silent: true });
28
- await generateClientTypes(nitro, { silent: true });
29
+ refreshVirtualModules(nitro);
30
+ await regenerateTypes(nitro, { silent: true });
29
31
  logger.success("Types regenerated");
30
32
  await nitro.hooks.callHook("dev:reload");
31
33
  },
@@ -51,13 +53,12 @@ function getWatchDirectories(nitro, extendDirs = []) {
51
53
  if (nitro.options.graphql?.externalServices?.length) {
52
54
  for (const service of nitro.options.graphql.externalServices) if (service.documents?.length) for (const pattern of service.documents) {
53
55
  if (!pattern) continue;
54
- const baseDir = pattern.split("**")[0]?.replace(/\/$/, "") || ".";
56
+ const baseDir = pattern.split("**")[0]?.replace(TRAILING_SLASH_RE, "") || ".";
55
57
  const resolvedDir = join(nitro.options.rootDir, baseDir);
56
58
  if (!watchDirs.includes(resolvedDir)) watchDirs.push(resolvedDir);
57
59
  }
58
60
  }
59
61
  return watchDirs;
60
62
  }
61
-
62
63
  //#endregion
63
- export { getWatchDirectories, setupFileWatcher };
64
+ export { getWatchDirectories, setupFileWatcher };
@@ -1,16 +1,9 @@
1
- import { SecurityConfig } from "../types.mjs";
2
1
  import { Nitro } from "nitro/types";
3
2
 
4
3
  //#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
4
  /**
12
5
  * Log startup information
13
6
  */
14
7
  declare function logStartupInfo(nitro: Nitro, serverEnabled: boolean): void;
15
8
  //#endregion
16
- export { logStartupInfo, resolveSecurityConfig };
9
+ export { logStartupInfo };
@@ -1,41 +1,25 @@
1
+ import { resolveSecurityConfig } from "./security.mjs";
1
2
  import consola from "consola";
2
-
3
3
  //#region src/nitro/setup/logging.ts
4
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
5
  * Log startup information
20
6
  */
21
7
  function logStartupInfo(nitro, serverEnabled) {
8
+ const { state } = nitro.graphql;
22
9
  const externalServicesCount = nitro.options.graphql?.externalServices?.length || 0;
23
- const docs = nitro.scanDocuments || [];
24
10
  const isProd = process.env.NODE_ENV === "production";
25
11
  if (serverEnabled) {
26
12
  const securityConfig = resolveSecurityConfig(nitro.options.graphql?.security);
27
13
  const framework = nitro.options.graphql?.framework || "unknown";
28
- const schemas = nitro.scanSchemas?.length || 0;
29
- const resolvers = nitro.scanResolvers?.length || 0;
30
14
  consola.box({
31
15
  title: "Nitro GraphQL",
32
16
  message: [
33
17
  `Framework: ${framework}`,
34
18
  `Environment: ${isProd ? "production" : "development"}`,
35
- `Schemas: ${schemas}`,
36
- `Resolvers: ${resolvers}`,
19
+ `Schemas: ${state.schemas.length}`,
20
+ `Resolvers: ${state.resolvers.length}`,
37
21
  externalServicesCount > 0 ? `External Services: ${externalServicesCount}` : "",
38
- docs.length > 0 ? `Documents: ${docs.length}` : "",
22
+ state.documents.length > 0 ? `Documents: ${state.documents.length}` : "",
39
23
  "",
40
24
  "Security:",
41
25
  `├─ Introspection: ${securityConfig.introspection ? "enabled" : "disabled"}`,
@@ -53,7 +37,7 @@ function logStartupInfo(nitro, serverEnabled) {
53
37
  message: [
54
38
  "Server mode: disabled",
55
39
  `External Services: ${externalServicesCount}`,
56
- `Documents: ${docs.length}`
40
+ `Documents: ${state.documents.length}`
57
41
  ].join("\n"),
58
42
  style: {
59
43
  borderColor: "blue",
@@ -61,6 +45,5 @@ function logStartupInfo(nitro, serverEnabled) {
61
45
  }
62
46
  });
63
47
  }
64
-
65
48
  //#endregion
66
- export { logStartupInfo, resolveSecurityConfig };
49
+ export { logStartupInfo };
@@ -1,11 +1,14 @@
1
+ import { CHUNK_NAME_RESOLVERS, CHUNK_NAME_SCHEMAS, CHUNK_PATH_UNKNOWN, GRAPHQL_EXTENSIONS, RESOLVER_EXTENSIONS } from "../../core/constants.mjs";
1
2
  //#region src/nitro/setup/rollup-integration.ts
3
+ const NITRO_GRAPHQL_ROUTES_RE = /nitro-graphql[/\\]dist[/\\]nitro[/\\]routes/;
4
+ const NITRO_GRAPHQL_SCHEMA_RE = /nitro-graphql[/\\]dist[/\\]core[/\\]schema/;
2
5
  /**
3
6
  * Configure noExternals to ensure nitro-graphql route handlers are bundled
4
7
  * This is critical for Nuxt integration where node_modules are externalized by default.
5
8
  * Without this, the #nitro-graphql/* virtual imports in handlers would fail at runtime.
6
9
  */
7
10
  function setupNoExternals(nitro) {
8
- const routePatterns = [/nitro-graphql[/\\]dist[/\\]nitro[/\\]routes/, /nitro-graphql[/\\]dist[/\\]core[/\\]schema/];
11
+ const routePatterns = [NITRO_GRAPHQL_ROUTES_RE, NITRO_GRAPHQL_SCHEMA_RE];
9
12
  if (nitro.options.noExternals === true) return;
10
13
  if (!Array.isArray(nitro.options.noExternals)) nitro.options.noExternals = [];
11
14
  nitro.options.noExternals.push(...routePatterns);
@@ -18,7 +21,37 @@ function setupNoExternals(nitro) {
18
21
  * interfering with Nitro's node_modules chunking which uses advancedChunks.
19
22
  */
20
23
  function setupRollupChunking(nitro) {
21
- nitro.hooks.hook("rollup:before", (_, rollupConfig) => {});
24
+ nitro.hooks.hook("rollup:before", (_, rollupConfig) => {
25
+ if (rollupConfig.output.inlineDynamicImports) return;
26
+ const output = rollupConfig.output;
27
+ if (output.advancedChunks || "codeSplitting" in output) return;
28
+ const existingManualChunks = rollupConfig.output?.manualChunks;
29
+ rollupConfig.output.manualChunks = (id, meta) => {
30
+ if (isGraphQLFile(id)) return `graphql/${CHUNK_NAME_SCHEMAS}`;
31
+ if (isResolverFile(id)) return `graphql/${CHUNK_NAME_RESOLVERS}`;
32
+ if (typeof existingManualChunks === "function") return existingManualChunks(id, meta);
33
+ };
34
+ const existingChunkFileNames = rollupConfig.output.chunkFileNames;
35
+ rollupConfig.output.chunkFileNames = (chunkInfo) => {
36
+ const name = chunkInfo.name || "";
37
+ if (name.startsWith("graphql/")) return `chunks/${name}.mjs`;
38
+ if (typeof existingChunkFileNames === "function") return existingChunkFileNames(chunkInfo);
39
+ if (typeof existingChunkFileNames === "string") return existingChunkFileNames;
40
+ return CHUNK_PATH_UNKNOWN;
41
+ };
42
+ });
43
+ }
44
+ /**
45
+ * Check if a file is a GraphQL schema file
46
+ */
47
+ function isGraphQLFile(id) {
48
+ return GRAPHQL_EXTENSIONS.some((ext) => id.endsWith(ext));
49
+ }
50
+ /**
51
+ * Check if a file is a resolver file
52
+ */
53
+ function isResolverFile(id) {
54
+ return RESOLVER_EXTENSIONS.some((ext) => id.endsWith(ext));
22
55
  }
23
56
  /**
24
57
  * Configure external dependencies for Rollup
@@ -58,6 +91,5 @@ function setupRollupExternals(nitro) {
58
91
  }
59
92
  });
60
93
  }
61
-
62
94
  //#endregion
63
- export { setupNoExternals, setupRollupChunking, setupRollupExternals };
95
+ export { setupNoExternals, setupRollupChunking, setupRollupExternals };
@@ -1,6 +1,5 @@
1
1
  import { ENDPOINT_DEBUG, GRAPHQL_HTTP_METHODS } from "../../core/constants.mjs";
2
2
  import { fileURLToPath } from "node:url";
3
-
4
3
  //#region src/nitro/setup/routes.ts
5
4
  /**
6
5
  * Resolve a module specifier to an absolute filesystem path.
@@ -66,6 +65,5 @@ function registerRouteHandlers(nitro) {
66
65
  method: "GET"
67
66
  });
68
67
  }
69
-
70
68
  //#endregion
71
- export { registerRouteHandlers };
69
+ export { registerRouteHandlers };
@@ -1,59 +1,24 @@
1
- import { ExtendSource } from "../types.mjs";
1
+ import { ExtendSource } from "../types/config.mjs";
2
2
  import { Nitro } from "nitro/types";
3
3
 
4
4
  //#region src/nitro/setup/scanner.d.ts
5
5
  interface ScanOptions {
6
- /** Silent mode - suppress logging */
7
6
  silent?: boolean;
8
- /** Is this a rescan (dev mode hot reload) */
9
7
  isRescan?: boolean;
10
8
  }
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
9
  declare function shouldScanLocalFiles(nitro: Nitro): boolean;
22
- /**
23
- * Check if server-side GraphQL is enabled
24
- */
25
10
  declare function isServerEnabled(nitro: Nitro): boolean;
26
- /**
27
- * Get extend sources from config
28
- */
29
11
  declare function getExtendSources(nitro: Nitro): ExtendSource[] | undefined;
30
12
  /**
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
13
+ * Perform complete GraphQL scan workflow.
14
+ * Builds an immutable state snapshot and assigns it to nitro.graphql.state atomically.
46
15
  *
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
16
+ * Flow:
17
+ * 1. Scan local files (or skip if skipLocalScan)
18
+ * 2. Merge extend sources into state
19
+ * 3. Assign frozen state to nitro.graphql.state (single atomic write)
52
20
  */
53
21
  declare function performGraphQLScan(nitro: Nitro, options?: ScanOptions): Promise<void>;
54
- /**
55
- * Log resolver diagnostics for development
56
- */
57
22
  declare function logResolverDiagnostics(nitro: Nitro): void;
58
23
  //#endregion
59
- export { ScanOptions, ScanResult, getExtendSources, initializeEmptyScanResults, isServerEnabled, logResolverDiagnostics, performGraphQLScan, scanDocumentsOnly, scanLocalFiles, shouldScanLocalFiles };
24
+ export { ScanOptions, getExtendSources, isServerEnabled, logResolverDiagnostics, performGraphQLScan, shouldScanLocalFiles };
@@ -1,99 +1,96 @@
1
1
  import { LOG_TAG } from "../../core/constants.mjs";
2
+ import { scanDirectivesCore } from "../../core/scanning/directives.mjs";
3
+ import { scanDocumentsCore } from "../../core/scanning/documents.mjs";
4
+ import { scanResolversCore } from "../../core/scanning/resolvers.mjs";
5
+ import { scanSchemasCore } from "../../core/scanning/schemas.mjs";
2
6
  import { generateDirectiveSchemas } from "../../core/utils/directive-parser.mjs";
3
- import { NitroAdapter } from "../adapter.mjs";
7
+ import { createScanContextFromNitro } from "../adapter.mjs";
8
+ import { createScanState } from "../state.mjs";
4
9
  import { resolveExtendConfig } from "./extend-loader.mjs";
5
10
  import consola from "consola";
6
-
11
+ import { relative } from "pathe";
7
12
  //#region src/nitro/setup/scanner.ts
8
13
  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
14
  function shouldScanLocalFiles(nitro) {
14
15
  return nitro.options.graphql?.skipLocalScan !== true;
15
16
  }
16
- /**
17
- * Check if server-side GraphQL is enabled
18
- */
19
17
  function isServerEnabled(nitro) {
20
18
  return nitro.options.graphql?.server !== false;
21
19
  }
22
- /**
23
- * Get extend sources from config
24
- */
25
20
  function getExtendSources(nitro) {
26
21
  const extend = nitro.options.graphql?.extend;
27
22
  return Array.isArray(extend) ? extend : void 0;
28
23
  }
29
24
  /**
30
- * Scan local GraphQL files (schemas, resolvers, directives, documents)
31
- * This is the low-level scan function - use performGraphQLScan for full workflow
25
+ * Scan local GraphQL files and return an immutable state snapshot.
26
+ * Does NOT mutate nitro caller is responsible for assigning the state.
32
27
  */
33
28
  async function scanLocalFiles(nitro) {
34
- const directivesResult = await NitroAdapter.scanDirectives(nitro);
35
- nitro.scanDirectives = directivesResult.items;
29
+ const ctx = createScanContextFromNitro(nitro);
30
+ const directivesResult = await scanDirectivesCore(ctx);
36
31
  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
- };
32
+ const schemasResult = await scanSchemasCore(ctx);
33
+ const [docsResult, resolversResult] = await Promise.all([scanDocumentsCore(ctx, {
34
+ externalServices: nitro.options.graphql?.externalServices,
35
+ clientDirRelative: relative(nitro.options.rootDir, nitro.graphql.clientDir)
36
+ }), scanResolversCore(ctx)]);
37
+ return createScanState({
38
+ schemas: schemasResult.items,
39
+ resolvers: resolversResult.items,
40
+ directives: directivesResult.items,
41
+ documents: docsResult.items,
42
+ directiveSchemas
43
+ });
50
44
  }
51
45
  /**
52
- * Scan only client documents (for external services or client-only mode)
46
+ * Scan only client documents, preserving existing state for other fields
53
47
  */
54
48
  async function scanDocumentsOnly(nitro) {
55
- const result = await NitroAdapter.scanDocuments(nitro);
56
- nitro.scanDocuments = result.items;
57
- return result.items.length;
49
+ return createScanState({
50
+ schemas: [],
51
+ resolvers: [],
52
+ directives: [],
53
+ documents: (await scanDocumentsCore(createScanContextFromNitro(nitro), {
54
+ externalServices: nitro.options.graphql?.externalServices,
55
+ clientDirRelative: relative(nitro.options.rootDir, nitro.graphql.clientDir)
56
+ })).items,
57
+ directiveSchemas: null
58
+ });
58
59
  }
59
60
  /**
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
61
+ * Perform complete GraphQL scan workflow.
62
+ * Builds an immutable state snapshot and assigns it to nitro.graphql.state atomically.
70
63
  *
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
64
+ * Flow:
65
+ * 1. Scan local files (or skip if skipLocalScan)
66
+ * 2. Merge extend sources into state
67
+ * 3. Assign frozen state to nitro.graphql.state (single atomic write)
76
68
  */
77
69
  async function performGraphQLScan(nitro, options = {}) {
78
70
  const { silent = false, isRescan = false } = options;
79
71
  const serverEnabled = isServerEnabled(nitro);
80
72
  const scanLocal = shouldScanLocalFiles(nitro);
81
73
  const extendSources = getExtendSources(nitro);
82
- if (isRescan && !scanLocal && extendSources?.length) return;
74
+ if (isRescan && extendSources?.length) return;
75
+ let state;
83
76
  if (!scanLocal) {
84
77
  if (!isRescan && !silent) if (extendSources?.length) logger.info(`Using ${extendSources.length} extend source(s), skipping local scanning`);
85
78
  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 });
79
+ state = await scanDocumentsOnly(nitro);
80
+ } else if (serverEnabled) state = await scanLocalFiles(nitro);
81
+ else state = await scanDocumentsOnly(nitro);
82
+ state = await resolveExtendConfig(nitro, state, { silent: silent || isRescan });
83
+ nitro.graphql.state = state;
84
+ nitro.scanSchemas = [...state.schemas];
85
+ nitro.scanResolvers = [...state.resolvers];
86
+ nitro.scanDirectives = [...state.directives];
87
+ nitro.scanDocuments = [...state.documents];
88
+ nitro.graphql.directiveSchemas = state.directiveSchemas;
89
+ nitro.graphql.extendConfigs = [...state.extendConfigs];
90
+ nitro.graphql.extendSchemas = [...state.extendSchemas];
91
91
  }
92
- /**
93
- * Log resolver diagnostics for development
94
- */
95
92
  function logResolverDiagnostics(nitro) {
96
- const resolvers = nitro.scanResolvers || [];
93
+ const resolvers = nitro.graphql.state.resolvers;
97
94
  if (resolvers.length > 0) {
98
95
  const totalExports = resolvers.reduce((sum, r) => sum + r.imports.length, 0);
99
96
  const typeCount = {
@@ -115,6 +112,5 @@ function logResolverDiagnostics(nitro) {
115
112
  if (breakdown.length > 0) logger.success(`${totalExports} resolver export(s): ${breakdown.join(", ")}`);
116
113
  } else logger.warn("No resolvers found. Check /_nitro/graphql/debug for details.");
117
114
  }
118
-
119
115
  //#endregion
120
- export { getExtendSources, initializeEmptyScanResults, isServerEnabled, logResolverDiagnostics, performGraphQLScan, scanDocumentsOnly, scanLocalFiles, shouldScanLocalFiles };
116
+ export { getExtendSources, isServerEnabled, logResolverDiagnostics, performGraphQLScan, shouldScanLocalFiles };
@@ -0,0 +1,10 @@
1
+ import { CoreSecurityConfig } from "../../core/types/config.mjs";
2
+ //#region src/nitro/setup/security.d.ts
3
+ /**
4
+ * Resolves security configuration with environment-aware defaults
5
+ * In production: introspection off, playground off, errors masked, suggestions disabled
6
+ * In development: introspection on, playground on, errors shown, suggestions enabled
7
+ */
8
+ declare function resolveSecurityConfig(config?: CoreSecurityConfig): Required<CoreSecurityConfig>;
9
+ //#endregion
10
+ export { resolveSecurityConfig };