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,141 +1,2 @@
1
- import { DIRECTIVE_EXTENSIONS, GRAPHQL_EXTENSIONS, RESOLVER_EXTENSIONS } from "../constants.mjs";
2
- import { watch } from "chokidar";
3
- import { debounce } from "perfect-debounce";
4
-
5
- //#region src/core/watcher/index.ts
6
- /**
7
- * Check if a file is a GraphQL-related file
8
- */
9
- function getFileType(path) {
10
- if (GRAPHQL_EXTENSIONS.some((ext) => path.endsWith(ext))) return "graphql";
11
- if (RESOLVER_EXTENSIONS.some((ext) => path.endsWith(ext))) return "resolver";
12
- if (DIRECTIVE_EXTENSIONS.some((ext) => path.endsWith(ext))) return "directive";
13
- return null;
14
- }
15
- /**
16
- * Check if a file should be watched
17
- */
18
- function isWatchableFile(path) {
19
- return getFileType(path) !== null;
20
- }
21
- /**
22
- * Classify a file change as server or client
23
- */
24
- function classifyChange(path, serverDir) {
25
- const fileType = getFileType(path);
26
- if (!fileType) return null;
27
- if (fileType === "resolver" || fileType === "directive") return "server";
28
- if (fileType === "graphql") {
29
- const normalizedPath = path.replace(/\\/g, "/");
30
- const normalizedServerDir = serverDir.replace(/\\/g, "/");
31
- if (normalizedPath.includes(normalizedServerDir)) return "server";
32
- if (normalizedPath.includes("/server/graphql/") || normalizedPath.includes("\\server\\graphql\\")) return "server";
33
- return "client";
34
- }
35
- return null;
36
- }
37
- /**
38
- * Create the ignored function for chokidar
39
- * Filters out non-GraphQL files and system directories
40
- */
41
- function createIgnoredFunction() {
42
- return (path) => {
43
- if (path.includes("/node_modules/") || path.includes("/.git/") || path.includes("/.output/") || path.includes("/.nitro/") || path.includes("/.nuxt/") || path.includes("/.graphql/") || path.includes("/dist/")) return true;
44
- if (!(path.split("/").pop() || "").includes(".") || path.endsWith("/")) return false;
45
- return !isWatchableFile(path);
46
- };
47
- }
48
- /**
49
- * Check if a path should be skipped (generated files)
50
- */
51
- function shouldSkipPath(path) {
52
- return path.includes("/sdk.ts") || path.includes("/sdk.js") || path.endsWith("/config.ts");
53
- }
54
- /**
55
- * Create a core file watcher
56
- *
57
- * This is the shared watcher used by both Nitro and CLI.
58
- * Framework-specific actions are passed as callbacks.
59
- *
60
- * @example
61
- * ```typescript
62
- * // In Nitro
63
- * const watcher = createCoreWatcher(
64
- * { watchDirs, serverDir: nitro.graphql.serverDir },
65
- * {
66
- * onServerChange: async () => {
67
- * await performGraphQLScan(nitro, { silent: true, isRescan: true })
68
- * await generateServerTypes(nitro, { silent: true })
69
- * await nitro.hooks.callHook('dev:reload')
70
- * },
71
- * onClientChange: async () => {
72
- * await generateClientTypes(nitro, { silent: true })
73
- * },
74
- * }
75
- * )
76
- *
77
- * // In CLI
78
- * const watcher = createCoreWatcher(
79
- * { watchDirs, serverDir: ctx.config.serverDir },
80
- * {
81
- * onServerChange: async () => {
82
- * await generateAll(ctx, { silent: true })
83
- * await reloadHandler()
84
- * },
85
- * onClientChange: async () => {
86
- * await generateClient(ctx, { silent: true })
87
- * },
88
- * }
89
- * )
90
- * ```
91
- */
92
- function createCoreWatcher(config, callbacks) {
93
- const { watchDirs, serverDir, debounceMs = 150, persistent = true, ignoreInitial = true, usePolling } = config;
94
- const shouldUsePolling = usePolling ?? (process.env.CI === "true" || process.env.VITE_TEST === "true");
95
- const watcher = watch(watchDirs, {
96
- persistent,
97
- ignoreInitial,
98
- ignored: createIgnoredFunction(),
99
- usePolling: shouldUsePolling,
100
- interval: shouldUsePolling ? 100 : void 0,
101
- awaitWriteFinish: shouldUsePolling ? {
102
- stabilityThreshold: 100,
103
- pollInterval: 50
104
- } : false
105
- });
106
- const pending = {
107
- server: false,
108
- client: false
109
- };
110
- async function processChanges() {
111
- const changes = { ...pending };
112
- pending.server = pending.client = false;
113
- try {
114
- if (changes.server) await callbacks.onServerChange();
115
- else if (changes.client) await callbacks.onClientChange();
116
- } catch (error) {
117
- callbacks.onError?.(error);
118
- }
119
- }
120
- const debouncedProcess = debounce(processChanges, debounceMs);
121
- watcher.on("all", (_, path) => {
122
- if (shouldSkipPath(path)) return;
123
- const changeType = classifyChange(path, serverDir);
124
- if (!changeType) return;
125
- if (changeType === "server") pending.server = true;
126
- else pending.client = true;
127
- debouncedProcess();
128
- });
129
- if (callbacks.onReady) watcher.on("ready", callbacks.onReady);
130
- if (callbacks.onError) watcher.on("error", callbacks.onError);
131
- return watcher;
132
- }
133
- /**
134
- * Close a watcher safely
135
- */
136
- async function closeWatcher(watcher) {
137
- await watcher.close();
138
- }
139
-
140
- //#endregion
141
- export { classifyChange, closeWatcher, createCoreWatcher, createIgnoredFunction, getFileType, isWatchableFile, shouldSkipPath };
1
+ import { classifyChange, closeWatcher, createCoreWatcher, createIgnoredFunction, getFileType, isWatchableFile, shouldSkipPath } from "./create-watcher.mjs";
2
+ export { classifyChange, closeWatcher, createCoreWatcher, createIgnoredFunction, getFileType, isWatchableFile, shouldSkipPath };
package/dist/define.d.mts CHANGED
@@ -1,5 +1,7 @@
1
- import { DefineDirectiveConfig, DefineServerConfig, DirectiveDefinition, Flatten, StandardSchemaV1 } from "./nitro/types.mjs";
2
- import { PubSubEngine, TypedPubSub, createPubSub, mapAsyncIterator, withFilter } from "./core/pubsub/index.mjs";
1
+ import { DefineDirectiveConfig, DirectiveDefinition, Flatten } from "./core/types/define.mjs";
2
+ import { StandardSchemaV1 } from "./core/types/standard-schema.mjs";
3
+ import { DefineServerConfig } from "./nitro/types/define.mjs";
4
+ import { PubSubEngine, TypedPubSub, createPubSub, mapAsyncIterator, withFilter } from "./core/pubsub/memory-pubsub.mjs";
3
5
  import { NPMConfig, Resolvers, ResolversTypes } from "#graphql/server";
4
6
 
5
7
  //#region src/define.d.ts
package/dist/define.mjs CHANGED
@@ -1,5 +1,4 @@
1
- import { createPubSub, mapAsyncIterator, withFilter } from "./core/pubsub/index.mjs";
2
-
1
+ import { createPubSub, mapAsyncIterator, withFilter } from "./core/pubsub/memory-pubsub.mjs";
3
2
  //#region src/define.ts
4
3
  /**
5
4
  * Define schema extensions programmatically for GraphQL types.
@@ -309,17 +308,17 @@ function defineDirective(config) {
309
308
  const argsString = args ? `(${args})` : "";
310
309
  const locations = config.locations.join(" | ");
311
310
  const schemaDefinition = `directive @${config.name}${argsString} on ${locations}`;
312
- Object.defineProperty(config, "__schema", {
311
+ const result = {
312
+ ...config,
313
+ locations: [...config.locations]
314
+ };
315
+ Object.defineProperty(result, "__schema", {
313
316
  value: schemaDefinition,
314
317
  enumerable: false,
315
318
  configurable: false,
316
319
  writable: false
317
320
  });
318
- return {
319
- ...config,
320
- locations: [...config.locations]
321
- };
321
+ return result;
322
322
  }
323
-
324
323
  //#endregion
325
- export { createPubSub, defineDirective, defineField, defineGraphQLConfig, defineMutation, defineQuery, defineResolver, defineSchema, defineSubscription, mapAsyncIterator, withFilter };
324
+ export { createPubSub, defineDirective, defineField, defineGraphQLConfig, defineMutation, defineQuery, defineResolver, defineSchema, defineSubscription, mapAsyncIterator, withFilter };
package/dist/index.d.mts CHANGED
@@ -1,6 +1,7 @@
1
- import { ExternalGraphQLService, NitroGraphQLOptions, SecurityConfig } from "./nitro/types.mjs";
1
+ import { CoreSecurityConfig } from "./core/types/config.mjs";
2
+ import { ExternalGraphQLService, NitroGraphQLOptions } from "./nitro/types/config.mjs";
2
3
  import { NitroAdapter } from "./nitro/adapter.mjs";
3
- import { resolveSecurityConfig } from "./nitro/setup/logging.mjs";
4
+ import { resolveSecurityConfig } from "./nitro/setup/security.mjs";
4
5
  import { setupNitroGraphQL } from "./nitro/setup.mjs";
5
6
  import graphqlModule from "./nitro/index.mjs";
6
- export { type ExternalGraphQLService, NitroAdapter, type NitroGraphQLOptions, type SecurityConfig, graphqlModule as default, resolveSecurityConfig, setupNitroGraphQL };
7
+ export { type ExternalGraphQLService, NitroAdapter, type NitroGraphQLOptions, type CoreSecurityConfig as SecurityConfig, graphqlModule as default, resolveSecurityConfig, setupNitroGraphQL };
package/dist/index.mjs CHANGED
@@ -1,6 +1,5 @@
1
1
  import { NitroAdapter } from "./nitro/adapter.mjs";
2
- import { resolveSecurityConfig } from "./nitro/setup/logging.mjs";
2
+ import { resolveSecurityConfig } from "./nitro/setup/security.mjs";
3
3
  import { setupNitroGraphQL } from "./nitro/setup.mjs";
4
- import nitro_default from "./nitro/index.mjs";
5
-
6
- export { NitroAdapter, nitro_default as default, resolveSecurityConfig, setupNitroGraphQL };
4
+ import graphqlModule from "./nitro/index.mjs";
5
+ export { NitroAdapter, graphqlModule as default, resolveSecurityConfig, setupNitroGraphQL };
@@ -1,7 +1,6 @@
1
- import { CoreConfig, CoreContext, CoreLogger } from "../core/types/config.mjs";
1
+ import { CoreConfig, CoreLogger } from "../core/types/config.mjs";
2
2
  import { ScanContext } from "../core/types/scanning.mjs";
3
- import "../core/types/index.mjs";
4
- import { FrameworkAdapter, ScanAdapter } from "../core/types/adapter.mjs";
3
+ import { FrameworkAdapter } from "../core/types/adapter.mjs";
5
4
  import { Nitro } from "nitro/types";
6
5
 
7
6
  //#region src/nitro/adapter.d.ts
@@ -10,7 +9,7 @@ import { Nitro } from "nitro/types";
10
9
  */
11
10
  declare function createLoggerFromNitro(nitro: Nitro): CoreLogger;
12
11
  /**
13
- * Create a ScanContext from Nitro instance
12
+ * Create a ScanContext directly from Nitro instance
14
13
  */
15
14
  declare function createScanContextFromNitro(nitro: Nitro): ScanContext;
16
15
  /**
@@ -18,12 +17,8 @@ declare function createScanContextFromNitro(nitro: Nitro): ScanContext;
18
17
  */
19
18
  declare function createCoreConfigFromNitro(nitro: Nitro): CoreConfig;
20
19
  /**
21
- * Create a CoreContext from Nitro instance
20
+ * Nitro framework adapter
22
21
  */
23
- declare function createCoreContextFromNitro(nitro: Nitro): CoreContext;
24
- /**
25
- * Nitro framework adapter implementation
26
- */
27
- declare const NitroAdapter: FrameworkAdapter<Nitro> & ScanAdapter<Nitro>;
22
+ declare const NitroAdapter: FrameworkAdapter<Nitro>;
28
23
  //#endregion
29
- export { NitroAdapter, NitroAdapter as default, createCoreConfigFromNitro, createCoreContextFromNitro, createLoggerFromNitro, createScanContextFromNitro };
24
+ export { NitroAdapter, NitroAdapter as default, createCoreConfigFromNitro, createLoggerFromNitro, createScanContextFromNitro };
@@ -1,9 +1,4 @@
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 { scanGraphqlCore, scanSchemasCore } from "../core/scanning/schemas.mjs";
5
- import { join, relative } from "pathe";
6
-
1
+ import { join } from "pathe";
7
2
  //#region src/nitro/adapter.ts
8
3
  /**
9
4
  * Create a CoreLogger from Nitro's logger
@@ -18,7 +13,7 @@ function createLoggerFromNitro(nitro) {
18
13
  };
19
14
  }
20
15
  /**
21
- * Create a ScanContext from Nitro instance
16
+ * Create a ScanContext directly from Nitro instance
22
17
  */
23
18
  function createScanContextFromNitro(nitro) {
24
19
  return {
@@ -35,59 +30,31 @@ function createScanContextFromNitro(nitro) {
35
30
  */
36
31
  function createCoreConfigFromNitro(nitro) {
37
32
  const graphqlOptions = nitro.options.graphql || {};
38
- const isNuxt = nitro.options.framework?.name === "nuxt";
39
- const typesDir = join(nitro.graphql.buildDir, "types");
40
33
  return {
41
34
  rootDir: nitro.options.rootDir,
42
35
  buildDir: nitro.graphql.buildDir,
43
36
  serverDir: nitro.graphql.serverDir,
44
37
  clientDir: nitro.graphql.clientDir,
45
- typesDir,
38
+ typesDir: join(nitro.graphql.buildDir, "types"),
46
39
  framework: graphqlOptions.framework || "graphql-yoga",
47
- isNuxt,
40
+ isNuxt: nitro.options.framework?.name === "nuxt",
48
41
  isDev: nitro.options.dev,
49
- graphqlOptions: {
50
- framework: graphqlOptions.framework,
51
- endpoint: typeof graphqlOptions.endpoint === "object" ? graphqlOptions.endpoint?.graphql : graphqlOptions.endpoint,
52
- federation: graphqlOptions.federation,
53
- security: graphqlOptions.security
54
- },
55
42
  logger: createLoggerFromNitro(nitro),
56
- ignorePatterns: nitro.options.ignore
57
- };
58
- }
59
- /**
60
- * Create a CoreContext from Nitro instance
61
- */
62
- function createCoreContextFromNitro(nitro) {
63
- return {
64
- config: createCoreConfigFromNitro(nitro),
65
- graphqlBuildDir: nitro.graphql.buildDir,
66
- watchDirs: nitro.graphql.watchDirs,
67
- dir: nitro.graphql.dir
43
+ ignorePatterns: nitro.options.ignore,
44
+ security: graphqlOptions.security,
45
+ federation: graphqlOptions.federation,
46
+ codegen: graphqlOptions.codegen,
47
+ externalServices: graphqlOptions.externalServices
68
48
  };
69
49
  }
70
50
  /**
71
- * Nitro framework adapter implementation
51
+ * Nitro framework adapter
72
52
  */
73
53
  const NitroAdapter = {
74
54
  name: "nitro",
75
55
  createCoreConfig: createCoreConfigFromNitro,
76
- createCoreContext: createCoreContextFromNitro,
77
56
  createScanContext: createScanContextFromNitro,
78
- getLogger: createLoggerFromNitro,
79
- scanSchemas: (nitro) => scanSchemasCore(createScanContextFromNitro(nitro)),
80
- scanGraphql: (nitro) => scanGraphqlCore(createScanContextFromNitro(nitro)),
81
- scanResolvers: (nitro) => scanResolversCore(createScanContextFromNitro(nitro)),
82
- scanDirectives: (nitro) => scanDirectivesCore(createScanContextFromNitro(nitro)),
83
- scanDocuments(nitro) {
84
- return scanDocumentsCore(createScanContextFromNitro(nitro), {
85
- externalServices: nitro.options.graphql?.externalServices,
86
- clientDirRelative: relative(nitro.options.rootDir, nitro.graphql.clientDir)
87
- });
88
- }
57
+ getLogger: createLoggerFromNitro
89
58
  };
90
- var adapter_default = NitroAdapter;
91
-
92
59
  //#endregion
93
- export { NitroAdapter, createCoreConfigFromNitro, createCoreContextFromNitro, createLoggerFromNitro, createScanContextFromNitro, adapter_default as default };
60
+ export { NitroAdapter, NitroAdapter as default, createCoreConfigFromNitro, createLoggerFromNitro, createScanContextFromNitro };
@@ -1,6 +1,5 @@
1
1
  import { HeaderMap } from "@apollo/server";
2
2
  import { eventHandler, getRequestURL, readBody } from "nitro/h3";
3
-
4
3
  //#region src/nitro/apollo.ts
5
4
  function startServerAndCreateH3Handler(server, options) {
6
5
  const defaultContext = () => Promise.resolve({});
@@ -54,6 +53,5 @@ async function normalizeBody(event) {
54
53
  const method = event.req.method;
55
54
  if (method && PayloadMethods.includes(method)) return await readBody(event);
56
55
  }
57
-
58
56
  //#endregion
59
- export { startServerAndCreateH3Handler };
57
+ export { startServerAndCreateH3Handler };
@@ -0,0 +1,12 @@
1
+ import { Nitro } from "nitro/types";
2
+
3
+ //#region src/nitro/codegen/client-types.d.ts
4
+ /**
5
+ * Generate client-side operation types
6
+ */
7
+ declare function generateClientTypes(nitro: Nitro, options?: {
8
+ silent?: boolean;
9
+ isInitial?: boolean;
10
+ }, schemaString?: string): Promise<void>;
11
+ //#endregion
12
+ export { generateClientTypes };
@@ -0,0 +1,73 @@
1
+ import { LOG_TAG } from "../../core/constants.mjs";
2
+ import { generateClientTypesCore } from "../../core/codegen/client.mjs";
3
+ import { loadGraphQLDocuments } from "../../core/codegen/document-loader.mjs";
4
+ import { writeFile } from "../../core/utils/file-io.mjs";
5
+ import { generateSubscriptionBuilder } from "../../core/codegen/vue-subscription-builder.mjs";
6
+ import { getDefaultPaths, getSdkConfig, getTypesConfig, resolveFilePath } from "../paths.mjs";
7
+ import { subscribeClientTemplate } from "../../core/utils/subscribe-templates.mjs";
8
+ import { generateExternalTypes } from "./external-types.mjs";
9
+ import consola from "consola";
10
+ import { join } from "pathe";
11
+ import { existsSync, readFileSync } from "node:fs";
12
+ //#region src/nitro/codegen/client-types.ts
13
+ const logger = consola.withTag(LOG_TAG);
14
+ /**
15
+ * Generate client-side operation types
16
+ */
17
+ async function generateClientTypes(nitro, options = {}, schemaString) {
18
+ try {
19
+ if (nitro.graphql.state.schemas.length) await generateMainClientTypes(nitro, options, schemaString);
20
+ if (nitro.options.graphql?.externalServices?.length) await generateExternalTypes(nitro, options);
21
+ } catch (error) {
22
+ logger.error("Client type generation failed:", error);
23
+ }
24
+ }
25
+ async function generateMainClientTypes(nitro, options = {}, schemaString) {
26
+ if (!schemaString) {
27
+ const schemaPath = join(nitro.graphql.buildDir, "schema.graphql");
28
+ if (!existsSync(schemaPath)) {
29
+ if (!options.silent) consola.info("Schema not ready for client types");
30
+ return;
31
+ }
32
+ schemaString = readFileSync(schemaPath, "utf-8");
33
+ }
34
+ const docs = await loadGraphQLDocuments([...nitro.graphql.state.documents]);
35
+ const serverScalars = nitro.options.graphql?.codegen?.server?.scalars;
36
+ const clientConfig = nitro.options.graphql?.codegen?.client || {};
37
+ const resolvedClientConfig = {
38
+ ...clientConfig,
39
+ scalars: clientConfig.scalars ?? serverScalars
40
+ };
41
+ const types = await generateClientTypesCore({
42
+ schemaString,
43
+ documents: docs,
44
+ config: resolvedClientConfig,
45
+ sdkConfig: nitro.options.graphql?.codegen?.clientSDK,
46
+ options
47
+ });
48
+ if (types === false) return;
49
+ const placeholders = getDefaultPaths(nitro);
50
+ const typesConfig = getTypesConfig(nitro);
51
+ const sdkFileConfig = getSdkConfig(nitro);
52
+ const subscriptionsEnabled = nitro.options.graphql?.subscriptions?.enabled ?? false;
53
+ const clientPath = resolveFilePath(typesConfig.client, typesConfig.enabled, true, "{typesDir}/nitro-graphql-client.d.ts", placeholders);
54
+ if (clientPath) {
55
+ writeFile(clientPath, types.types);
56
+ if (!options.silent) logger.success(`Client types: ${clientPath}`);
57
+ }
58
+ const subscriptionCode = generateSubscriptionBuilder(docs, subscriptionsEnabled);
59
+ const sdkPath = resolveFilePath(sdkFileConfig.main, sdkFileConfig.enabled, true, "{clientDir}/default/sdk.ts", placeholders);
60
+ if (sdkPath) {
61
+ writeFile(sdkPath, subscriptionCode ? types.sdk + subscriptionCode : types.sdk);
62
+ if (!options.silent) logger.success(`SDK: ${sdkPath}`);
63
+ }
64
+ if (subscriptionsEnabled) {
65
+ const subscribePath = resolveFilePath(true, true, true, "{clientDir}/default/subscribe.ts", placeholders);
66
+ if (subscribePath && !existsSync(subscribePath)) {
67
+ writeFile(subscribePath, subscribeClientTemplate);
68
+ if (!options.silent) logger.success(`Subscribe config: ${subscribePath}`);
69
+ }
70
+ }
71
+ }
72
+ //#endregion
73
+ export { generateClientTypes };
@@ -0,0 +1,8 @@
1
+ import { Nitro } from "nitro/types";
2
+
3
+ //#region src/nitro/codegen/external-types.d.ts
4
+ declare function generateExternalTypes(nitro: Nitro, options?: {
5
+ silent?: boolean;
6
+ }): Promise<void>;
7
+ //#endregion
8
+ export { generateExternalTypes };
@@ -0,0 +1,47 @@
1
+ import { generateExternalClientTypesCore } from "../../core/codegen/client.mjs";
2
+ import { loadGraphQLDocuments } from "../../core/codegen/document-loader.mjs";
3
+ import { writeFile } from "../../core/utils/file-io.mjs";
4
+ import { downloadAndSaveSchema, loadExternalSchema } from "../../core/codegen/schema-loader.mjs";
5
+ import { getDefaultPaths, getSdkConfig, getTypesConfig, resolveFilePath } from "../paths.mjs";
6
+ import consola from "consola";
7
+ //#region src/nitro/codegen/external-types.ts
8
+ async function generateExternalServiceTypes(nitro, service, options = {}) {
9
+ if (!options.silent) consola.info(`[${service.name}] Processing external service`);
10
+ await downloadAndSaveSchema(service, nitro.options.buildDir);
11
+ const schema = await loadExternalSchema(service, nitro.options.buildDir);
12
+ if (!schema) {
13
+ consola.warn(`[${service.name}] Failed to load schema`);
14
+ return;
15
+ }
16
+ const docs = service.documents?.length ? await loadGraphQLDocuments(service.documents).catch(() => []) : [];
17
+ if (service.documents?.length && !docs.length) {
18
+ consola.warn(`[${service.name}] No documents found`);
19
+ return;
20
+ }
21
+ const types = await generateExternalClientTypesCore(service, schema, docs);
22
+ if (types === false) return;
23
+ const placeholders = {
24
+ ...getDefaultPaths(nitro),
25
+ serviceName: service.name
26
+ };
27
+ const typesConfig = getTypesConfig(nitro);
28
+ const sdkFileConfig = getSdkConfig(nitro);
29
+ const typesPath = resolveFilePath(service.paths?.types ?? typesConfig.external, typesConfig.enabled, true, "{typesDir}/nitro-graphql-client-{serviceName}.d.ts", placeholders);
30
+ if (typesPath) {
31
+ writeFile(typesPath, types.types);
32
+ if (!options.silent) consola.success(`[${service.name}] Types: ${typesPath}`);
33
+ }
34
+ const sdkPath = resolveFilePath(service.paths?.sdk ?? sdkFileConfig.external, sdkFileConfig.enabled, true, "{clientDir}/{serviceName}/sdk.ts", placeholders);
35
+ if (sdkPath) {
36
+ writeFile(sdkPath, types.sdk);
37
+ if (!options.silent) consola.success(`[${service.name}] SDK: ${sdkPath}`);
38
+ }
39
+ }
40
+ async function generateExternalTypes(nitro, options = {}) {
41
+ const services = nitro.options.graphql?.externalServices || [];
42
+ await Promise.all(services.map((service) => generateExternalServiceTypes(nitro, service, options).catch((error) => {
43
+ consola.error(`[${service.name}] External service failed:`, error);
44
+ })));
45
+ }
46
+ //#endregion
47
+ export { generateExternalTypes };
@@ -0,0 +1,4 @@
1
+ import { generateClientTypes } from "./client-types.mjs";
2
+ import { generateExternalTypes } from "./external-types.mjs";
3
+ import { generateServerTypes } from "./server-types.mjs";
4
+ export { generateClientTypes, generateExternalTypes, generateServerTypes };
@@ -0,0 +1,4 @@
1
+ import { generateExternalTypes } from "./external-types.mjs";
2
+ import { generateClientTypes } from "./client-types.mjs";
3
+ import { generateServerTypes } from "./server-types.mjs";
4
+ export { generateClientTypes, generateExternalTypes, generateServerTypes };
@@ -0,0 +1,12 @@
1
+ import { Nitro } from "nitro/types";
2
+
3
+ //#region src/nitro/codegen/server-types.d.ts
4
+ /**
5
+ * Generate server-side resolver types
6
+ * Returns the sorted schema string for reuse by client type generation
7
+ */
8
+ declare function generateServerTypes(nitro: Nitro, options?: {
9
+ silent?: boolean;
10
+ }): Promise<string | undefined>;
11
+ //#endregion
12
+ export { generateServerTypes };
@@ -0,0 +1,81 @@
1
+ import { LOG_TAG } from "../../core/constants.mjs";
2
+ import { writeFile } from "../../core/utils/file-io.mjs";
3
+ import { generateServerTypesCore } from "../../core/codegen/server.mjs";
4
+ import { validateNoDuplicateTypes } from "../../core/codegen/validation.mjs";
5
+ import { loadFederationSupport } from "../../core/schema/federation.mjs";
6
+ import { getDefaultPaths, getTypesConfig, resolveFilePath, shouldGenerateTypes } from "../paths.mjs";
7
+ import consola from "consola";
8
+ import { resolve } from "pathe";
9
+ import { printSchemaWithDirectives } from "@graphql-tools/utils";
10
+ import { parse, print } from "graphql";
11
+ import { mergeTypeDefs } from "@graphql-tools/merge";
12
+ import { makeExecutableSchema } from "@graphql-tools/schema";
13
+ import { loadFilesSync } from "@graphql-tools/load-files";
14
+ //#region src/nitro/codegen/server-types.ts
15
+ const logger = consola.withTag(LOG_TAG);
16
+ /**
17
+ * Build schema with optional federation support
18
+ * Uses @graphql-tools to ensure same graphql instance is used throughout
19
+ */
20
+ async function buildSchemaFromString(source, federation) {
21
+ if (federation) {
22
+ const buildSubgraph = await loadFederationSupport();
23
+ if (!buildSubgraph) throw new Error("Federation enabled but @apollo/subgraph not installed");
24
+ return buildSubgraph([{ typeDefs: parse(source) }]);
25
+ }
26
+ return makeExecutableSchema({ typeDefs: source });
27
+ }
28
+ /**
29
+ * Generate server-side resolver types
30
+ * Returns the sorted schema string for reuse by client type generation
31
+ */
32
+ async function generateServerTypes(nitro, options = {}) {
33
+ if (!shouldGenerateTypes(nitro)) return;
34
+ const schemas = nitro.graphql.state.schemas;
35
+ if (!schemas.length) {
36
+ if (!options.silent) consola.info("No GraphQL schemas found");
37
+ return;
38
+ }
39
+ try {
40
+ const allStrings = loadFilesSync(schemas).map((s) => typeof s === "string" ? s : s.loc?.source?.body || "");
41
+ const validSchemas = [];
42
+ const strings = [];
43
+ schemas.forEach((schema, i) => {
44
+ if (allStrings[i]) {
45
+ validSchemas.push(schema);
46
+ strings.push(allStrings[i]);
47
+ }
48
+ });
49
+ const directiveSchemas = nitro.graphql.state.directiveSchemas;
50
+ if (directiveSchemas) {
51
+ validSchemas.push("<inline-directives>");
52
+ strings.push(directiveSchemas);
53
+ }
54
+ if (!validateNoDuplicateTypes(validSchemas, strings)) return;
55
+ const mergedSchemaString = print(mergeTypeDefs([strings.join("\n\n")], {
56
+ throwOnConflict: true,
57
+ sort: true
58
+ }));
59
+ const federation = nitro.options.graphql?.federation?.enabled === true;
60
+ const sortedSchemaString = printSchemaWithDirectives(await buildSchemaFromString(mergedSchemaString, federation));
61
+ const result = await generateServerTypesCore({
62
+ framework: nitro.options.graphql?.framework || "graphql-yoga",
63
+ schemaString: sortedSchemaString,
64
+ config: nitro.options.graphql?.codegen?.server,
65
+ federationEnabled: federation
66
+ });
67
+ writeFile(resolve(nitro.graphql.buildDir, "schema.graphql"), sortedSchemaString);
68
+ const placeholders = getDefaultPaths(nitro);
69
+ const typesConfig = getTypesConfig(nitro);
70
+ const typesPath = resolveFilePath(typesConfig.server, typesConfig.enabled, true, "{typesDir}/nitro-graphql-server.d.ts", placeholders);
71
+ if (typesPath) {
72
+ writeFile(typesPath, result.types);
73
+ if (!options.silent) logger.success(`Server types: ${typesPath}`);
74
+ }
75
+ return sortedSchemaString;
76
+ } catch (error) {
77
+ logger.error("Server type generation failed:", error);
78
+ }
79
+ }
80
+ //#endregion
81
+ export { generateServerTypes };
@@ -0,0 +1,28 @@
1
+ import { NitroGraphQLOptions } from "./types/config.mjs";
2
+ //#region src/nitro/defaults.d.ts
3
+ /**
4
+ * Default type generation configuration
5
+ */
6
+ declare const DEFAULT_TYPES_CONFIG: {
7
+ readonly server: ".graphql/nitro-graphql-server.d.ts";
8
+ readonly client: ".graphql/nitro-graphql-client.d.ts";
9
+ readonly enabled: true;
10
+ };
11
+ /**
12
+ * Default runtime GraphQL configuration
13
+ */
14
+ declare const DEFAULT_RUNTIME_CONFIG: NitroGraphQLOptions;
15
+ /**
16
+ * Default SDK configuration
17
+ */
18
+ declare const DEFAULT_SDK_CONFIG: {
19
+ readonly enabled: true;
20
+ readonly main: true;
21
+ readonly external: true;
22
+ };
23
+ /**
24
+ * Default TypeScript strict mode setting
25
+ */
26
+ declare const DEFAULT_TYPESCRIPT_STRICT: true;
27
+ //#endregion
28
+ export { DEFAULT_RUNTIME_CONFIG, DEFAULT_SDK_CONFIG, DEFAULT_TYPESCRIPT_STRICT, DEFAULT_TYPES_CONFIG };
@@ -0,0 +1,34 @@
1
+ import { DEFAULT_CLIENT_TYPES_PATH, DEFAULT_SERVER_TYPES_PATH, ENDPOINT_GRAPHQL, ENDPOINT_HEALTH } from "../core/constants.mjs";
2
+ //#region src/nitro/defaults.ts
3
+ /**
4
+ * Default type generation configuration
5
+ */
6
+ const DEFAULT_TYPES_CONFIG = {
7
+ server: DEFAULT_SERVER_TYPES_PATH,
8
+ client: DEFAULT_CLIENT_TYPES_PATH,
9
+ enabled: true
10
+ };
11
+ /**
12
+ * Default runtime GraphQL configuration
13
+ */
14
+ const DEFAULT_RUNTIME_CONFIG = {
15
+ endpoint: {
16
+ graphql: ENDPOINT_GRAPHQL,
17
+ healthCheck: ENDPOINT_HEALTH
18
+ },
19
+ playground: true
20
+ };
21
+ /**
22
+ * Default SDK configuration
23
+ */
24
+ const DEFAULT_SDK_CONFIG = {
25
+ enabled: true,
26
+ main: true,
27
+ external: true
28
+ };
29
+ /**
30
+ * Default TypeScript strict mode setting
31
+ */
32
+ const DEFAULT_TYPESCRIPT_STRICT = true;
33
+ //#endregion
34
+ export { DEFAULT_RUNTIME_CONFIG, DEFAULT_SDK_CONFIG, DEFAULT_TYPESCRIPT_STRICT, DEFAULT_TYPES_CONFIG };