nitro-graphql 2.0.0-beta.36 → 2.0.0-beta.38

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 (204) hide show
  1. package/dist/cli/commands/generate.d.mts +26 -0
  2. package/dist/cli/commands/generate.mjs +196 -0
  3. package/dist/cli/commands/index.d.mts +4 -0
  4. package/dist/cli/commands/index.mjs +5 -0
  5. package/dist/cli/commands/init.d.mts +12 -0
  6. package/dist/cli/commands/init.mjs +100 -0
  7. package/dist/cli/commands/validate.d.mts +10 -0
  8. package/dist/cli/commands/validate.mjs +69 -0
  9. package/dist/cli/config.d.mts +75 -0
  10. package/dist/cli/config.mjs +20 -0
  11. package/dist/cli/index.d.mts +24 -0
  12. package/dist/cli/index.mjs +219 -0
  13. package/dist/core/codegen/client.d.mts +23 -0
  14. package/dist/core/codegen/client.mjs +150 -0
  15. package/dist/core/codegen/document-loader.d.mts +10 -0
  16. package/dist/core/codegen/document-loader.mjs +18 -0
  17. package/dist/core/codegen/index.d.mts +8 -0
  18. package/dist/core/codegen/index.mjs +9 -0
  19. package/dist/{utils/codegen-plugin.d.mts → core/codegen/plugin.d.mts} +2 -2
  20. package/dist/{utils/codegen-plugin.mjs → core/codegen/plugin.mjs} +1 -1
  21. package/dist/core/codegen/runtime.d.mts +20 -0
  22. package/dist/core/codegen/runtime.mjs +60 -0
  23. package/dist/core/codegen/schema-loader.d.mts +28 -0
  24. package/dist/core/codegen/schema-loader.mjs +128 -0
  25. package/dist/core/codegen/server.d.mts +28 -0
  26. package/dist/core/codegen/server.mjs +143 -0
  27. package/dist/{codegen → core/codegen}/validation.d.mts +1 -1
  28. package/dist/{codegen → core/codegen}/validation.mjs +1 -1
  29. package/dist/core/config.d.mts +50 -0
  30. package/dist/core/config.mjs +82 -0
  31. package/dist/core/constants.d.mts +188 -0
  32. package/dist/core/constants.mjs +210 -0
  33. package/dist/core/index.d.mts +32 -0
  34. package/dist/core/index.mjs +26 -0
  35. package/dist/core/scanning/ast-scanner.d.mts +23 -0
  36. package/dist/core/scanning/ast-scanner.mjs +103 -0
  37. package/dist/core/scanning/common.d.mts +37 -0
  38. package/dist/core/scanning/common.mjs +60 -0
  39. package/dist/core/scanning/directives.d.mts +10 -0
  40. package/dist/core/scanning/directives.mjs +29 -0
  41. package/dist/core/scanning/documents.d.mts +21 -0
  42. package/dist/core/scanning/documents.mjs +43 -0
  43. package/dist/core/scanning/index.d.mts +7 -0
  44. package/dist/core/scanning/index.mjs +8 -0
  45. package/dist/core/scanning/resolvers.d.mts +10 -0
  46. package/dist/core/scanning/resolvers.mjs +58 -0
  47. package/dist/core/scanning/schemas.d.mts +14 -0
  48. package/dist/core/scanning/schemas.mjs +64 -0
  49. package/dist/{utils/schema-builder.d.mts → core/schema/builder.d.mts} +7 -2
  50. package/dist/{utils/schema-builder.mjs → core/schema/builder.mjs} +22 -3
  51. package/dist/{utils → core/schema}/federation.d.mts +10 -5
  52. package/dist/{utils → core/schema}/federation.mjs +1 -1
  53. package/dist/core/schema/index.d.mts +3 -0
  54. package/dist/core/schema/index.mjs +4 -0
  55. package/dist/core/types/adapter.d.mts +58 -0
  56. package/dist/core/types/codegen.d.mts +133 -0
  57. package/dist/core/types/config.d.mts +212 -0
  58. package/dist/{types → core/types}/define.d.mts +3 -7
  59. package/dist/core/types/index.d.mts +5 -0
  60. package/dist/core/types/scanning.d.mts +69 -0
  61. package/dist/core/types/scanning.mjs +1 -0
  62. package/dist/{utils → core/utils}/directive-parser.d.mts +21 -5
  63. package/dist/{utils → core/utils}/directive-parser.mjs +25 -36
  64. package/dist/{utils → core/utils}/errors.d.mts +8 -4
  65. package/dist/{utils → core/utils}/errors.mjs +8 -4
  66. package/dist/core/utils/file-io.d.mts +24 -0
  67. package/dist/core/utils/file-io.mjs +47 -0
  68. package/dist/{utils → core/utils}/imports.d.mts +1 -1
  69. package/dist/{utils → core/utils}/imports.mjs +1 -1
  70. package/dist/core/utils/index.d.mts +7 -0
  71. package/dist/core/utils/index.mjs +8 -0
  72. package/dist/core/utils/logger.d.mts +19 -0
  73. package/dist/core/utils/logger.mjs +38 -0
  74. package/dist/{utils → core/utils}/ofetch-templates.d.mts +1 -1
  75. package/dist/{utils → core/utils}/ofetch-templates.mjs +1 -1
  76. package/dist/core/validation/external-services.d.mts +11 -0
  77. package/dist/{utils/validation.mjs → core/validation/external-services.mjs} +3 -3
  78. package/dist/core/validation/index.d.mts +2 -0
  79. package/dist/core/validation/index.mjs +3 -0
  80. package/dist/define.d.mts +1 -3
  81. package/dist/index.d.mts +6 -43
  82. package/dist/index.mjs +5 -62
  83. package/dist/nitro/adapter.d.mts +30 -0
  84. package/dist/nitro/adapter.mjs +97 -0
  85. package/dist/{utils → nitro}/apollo.d.mts +1 -1
  86. package/dist/{utils → nitro}/apollo.mjs +1 -1
  87. package/dist/nitro/codegen.d.mts +19 -0
  88. package/dist/nitro/codegen.mjs +141 -0
  89. package/dist/nitro/config.d.mts +52 -0
  90. package/dist/nitro/config.mjs +58 -0
  91. package/dist/nitro/index.d.mts +46 -0
  92. package/dist/nitro/index.mjs +65 -0
  93. package/dist/{utils/path-resolver.d.mts → nitro/paths.d.mts} +3 -19
  94. package/dist/{utils/path-resolver.mjs → nitro/paths.mjs} +2 -36
  95. package/dist/{rollup.d.mts → nitro/rollup.d.mts} +1 -1
  96. package/dist/{rollup.mjs → nitro/rollup.mjs} +11 -23
  97. package/dist/{routes → nitro/routes}/apollo-server.d.mts +1 -1
  98. package/dist/nitro/routes/apollo-server.mjs +71 -0
  99. package/dist/{routes → nitro/routes}/debug-template.d.mts +1 -1
  100. package/dist/{routes → nitro/routes}/debug-template.mjs +1 -1
  101. package/dist/{routes → nitro/routes}/debug.d.mts +10 -16
  102. package/dist/{routes → nitro/routes}/debug.mjs +2 -2
  103. package/dist/nitro/routes/graphql-yoga.d.mts +6 -0
  104. package/dist/{routes → nitro/routes}/graphql-yoga.mjs +21 -10
  105. package/dist/nitro/routes/health.d.mts +10 -0
  106. package/dist/{routes → nitro/routes}/health.mjs +1 -1
  107. package/dist/nitro/setup/file-watcher.d.mts +16 -0
  108. package/dist/{setup → nitro/setup}/file-watcher.mjs +14 -18
  109. package/dist/nitro/setup/logging.d.mts +17 -0
  110. package/dist/nitro/setup/logging.mjs +66 -0
  111. package/dist/nitro/setup/rollup-integration.d.mts +16 -0
  112. package/dist/{setup → nitro/setup}/rollup-integration.mjs +2 -2
  113. package/dist/nitro/setup/routes.d.mts +10 -0
  114. package/dist/nitro/setup/routes.mjs +35 -0
  115. package/dist/nitro/setup/ts-config.d.mts +11 -0
  116. package/dist/{setup → nitro/setup}/ts-config.mjs +3 -3
  117. package/dist/{setup.d.mts → nitro/setup.d.mts} +3 -2
  118. package/dist/{setup.mjs → nitro/setup.mjs} +73 -62
  119. package/dist/nitro/types.d.mts +378 -0
  120. package/dist/nitro/types.mjs +1 -0
  121. package/dist/nitro/virtual/generators.d.mts +31 -0
  122. package/dist/nitro/virtual/generators.mjs +193 -0
  123. package/dist/nitro/virtual/stubs.d.mts +20 -0
  124. package/dist/nitro/virtual/stubs.mjs +31 -0
  125. package/dist/{ecosystem/nuxt.d.mts → nuxt.d.mts} +1 -1
  126. package/dist/{ecosystem/nuxt.mjs → nuxt.mjs} +2 -2
  127. package/dist/{graphql/server.d.mts → stubs/index.d.mts} +5 -1
  128. package/dist/stubs/index.mjs +1 -0
  129. package/package.json +45 -43
  130. package/dist/codegen/client-types.d.mts +0 -13
  131. package/dist/codegen/client-types.mjs +0 -131
  132. package/dist/codegen/external-types.d.mts +0 -12
  133. package/dist/codegen/external-types.mjs +0 -88
  134. package/dist/codegen/index.d.mts +0 -18
  135. package/dist/codegen/index.mjs +0 -24
  136. package/dist/codegen/server-types.d.mts +0 -13
  137. package/dist/codegen/server-types.mjs +0 -64
  138. package/dist/config/defaults.mjs +0 -36
  139. package/dist/constants/scalars.mjs +0 -27
  140. package/dist/constants.mjs +0 -106
  141. package/dist/graphql/index.d.mts +0 -5
  142. package/dist/routes/apollo-server.mjs +0 -45
  143. package/dist/routes/graphql-yoga.d.mts +0 -6
  144. package/dist/routes/health.d.mts +0 -10
  145. package/dist/setup/graphql-scanner.mjs +0 -25
  146. package/dist/setup/scaffold-generator.mjs +0 -109
  147. package/dist/types/index.d.mts +0 -246
  148. package/dist/types/standard-schema.d.mts +0 -59
  149. package/dist/utils/client-codegen.d.mts +0 -41
  150. package/dist/utils/client-codegen.mjs +0 -267
  151. package/dist/utils/file-generator.d.mts +0 -37
  152. package/dist/utils/file-generator.mjs +0 -72
  153. package/dist/utils/file-writer.d.mts +0 -35
  154. package/dist/utils/file-writer.mjs +0 -32
  155. package/dist/utils/index.d.mts +0 -13
  156. package/dist/utils/index.mjs +0 -13
  157. package/dist/utils/layers.d.mts +0 -22
  158. package/dist/utils/layers.mjs +0 -28
  159. package/dist/utils/scanning/common.d.mts +0 -23
  160. package/dist/utils/scanning/common.mjs +0 -39
  161. package/dist/utils/scanning/directives.d.mts +0 -11
  162. package/dist/utils/scanning/directives.mjs +0 -43
  163. package/dist/utils/scanning/documents.d.mts +0 -15
  164. package/dist/utils/scanning/documents.mjs +0 -46
  165. package/dist/utils/scanning/index.d.mts +0 -6
  166. package/dist/utils/scanning/index.mjs +0 -7
  167. package/dist/utils/scanning/resolvers.d.mts +0 -11
  168. package/dist/utils/scanning/resolvers.mjs +0 -100
  169. package/dist/utils/scanning/schemas.d.mts +0 -15
  170. package/dist/utils/scanning/schemas.mjs +0 -29
  171. package/dist/utils/server-codegen.d.mts +0 -7
  172. package/dist/utils/server-codegen.mjs +0 -113
  173. package/dist/utils/type-generation.d.mts +0 -6
  174. package/dist/utils/type-generation.mjs +0 -7
  175. package/dist/utils/validation.d.mts +0 -11
  176. package/dist/virtual/debug-info.d.mts +0 -9
  177. package/dist/virtual/debug-info.mjs +0 -26
  178. package/dist/virtual/generators/config.d.mts +0 -22
  179. package/dist/virtual/generators/config.mjs +0 -36
  180. package/dist/virtual/generators/debug.d.mts +0 -14
  181. package/dist/virtual/generators/debug.mjs +0 -53
  182. package/dist/virtual/generators/directives.d.mts +0 -14
  183. package/dist/virtual/generators/directives.mjs +0 -52
  184. package/dist/virtual/generators/index.d.mts +0 -6
  185. package/dist/virtual/generators/index.mjs +0 -7
  186. package/dist/virtual/generators/resolvers.d.mts +0 -14
  187. package/dist/virtual/generators/resolvers.mjs +0 -55
  188. package/dist/virtual/generators/schemas.d.mts +0 -14
  189. package/dist/virtual/generators/schemas.mjs +0 -43
  190. package/dist/virtual/graphql-config.d.mts +0 -9
  191. package/dist/virtual/graphql-config.mjs +0 -10
  192. package/dist/virtual/module-config.d.mts +0 -9
  193. package/dist/virtual/module-config.mjs +0 -10
  194. package/dist/virtual/server-directives.d.mts +0 -11
  195. package/dist/virtual/server-directives.mjs +0 -10
  196. package/dist/virtual/server-resolvers.d.mts +0 -11
  197. package/dist/virtual/server-resolvers.mjs +0 -10
  198. package/dist/virtual/server-schemas.d.mts +0 -11
  199. package/dist/virtual/server-schemas.mjs +0 -10
  200. /package/dist/{graphql/index.mjs → core/types/adapter.mjs} +0 -0
  201. /package/dist/{graphql/server.mjs → core/types/codegen.mjs} +0 -0
  202. /package/dist/{types/define.mjs → core/types/config.mjs} +0 -0
  203. /package/dist/{types/index.mjs → core/types/define.mjs} +0 -0
  204. /package/dist/{types/standard-schema.mjs → core/types/index.mjs} +0 -0
@@ -1,51 +1,68 @@
1
- import { ENDPOINT_DEBUG, FRAMEWORK_NITRO, FRAMEWORK_NUXT, GRAPHQL_HTTP_METHODS, LOG_TAG } from "./constants.mjs";
2
- import { getDefaultPaths } from "./utils/path-resolver.mjs";
3
- import { generateServerTypes } from "./codegen/server-types.mjs";
4
- import { generateClientTypes } from "./codegen/index.mjs";
5
- import { DEFAULT_RUNTIME_CONFIG, DEFAULT_TYPESCRIPT_STRICT, DEFAULT_TYPES_CONFIG } from "./config/defaults.mjs";
6
- import { validateExternalServices } from "./utils/validation.mjs";
1
+ import { FRAMEWORK_NITRO, FRAMEWORK_NUXT, LOG_TAG } from "../core/constants.mjs";
2
+ import { generateDirectiveSchemas } from "../core/utils/directive-parser.mjs";
3
+ import { validateExternalServices } from "../core/validation/external-services.mjs";
4
+ import { NitroAdapter } from "./adapter.mjs";
5
+ import { getDefaultPaths } from "./paths.mjs";
6
+ import { generateClientTypes, generateServerTypes } from "./codegen.mjs";
7
+ import { DEFAULT_RUNTIME_CONFIG, DEFAULT_TYPESCRIPT_STRICT, DEFAULT_TYPES_CONFIG } from "./config.mjs";
7
8
  import { rollupConfig } from "./rollup.mjs";
8
9
  import { getWatchDirectories, setupFileWatcher } from "./setup/file-watcher.mjs";
9
- import { scanAllGraphQLFiles } from "./setup/graphql-scanner.mjs";
10
+ import { logStartupInfo, resolveSecurityConfig } from "./setup/logging.mjs";
10
11
  import { setupRollupChunking, setupRollupExternals } from "./setup/rollup-integration.mjs";
11
- import { generateScaffoldFiles } from "./setup/scaffold-generator.mjs";
12
+ import { registerRouteHandlers } from "./setup/routes.mjs";
12
13
  import { setupTypeScriptPaths } from "./setup/ts-config.mjs";
13
14
  import defu from "defu";
14
- import { fileURLToPath } from "node:url";
15
15
  import consola from "consola";
16
- import { join, relative, resolve } from "pathe";
16
+ import { relative, resolve } from "pathe";
17
17
 
18
- //#region src/setup.ts
18
+ //#region src/nitro/setup.ts
19
19
  const logger = consola.withTag(LOG_TAG);
20
20
  /**
21
+ * Scan all GraphQL files and update Nitro state
22
+ */
23
+ async function scanAllGraphQLFiles(nitro) {
24
+ const directivesResult = await NitroAdapter.scanDirectives(nitro);
25
+ nitro.scanDirectives = directivesResult.items;
26
+ if (!nitro.scanSchemas) nitro.scanSchemas = [];
27
+ const directivesPath = await generateDirectiveSchemas(nitro, directivesResult.items);
28
+ const schemas = (await NitroAdapter.scanSchemas(nitro)).items;
29
+ if (directivesPath && !schemas.includes(directivesPath)) schemas.push(directivesPath);
30
+ nitro.scanSchemas = schemas;
31
+ nitro.scanDocuments = (await NitroAdapter.scanDocuments(nitro)).items;
32
+ nitro.scanResolvers = (await NitroAdapter.scanResolvers(nitro)).items;
33
+ }
34
+ /**
21
35
  * Main setup function for nitro-graphql
22
36
  * Coordinates all initialization steps for the module
23
37
  */
24
38
  async function setupNitroGraphQL(nitro) {
25
- initializeConfiguration(nitro);
39
+ const serverEnabled = nitro.options.graphql?.server !== false;
40
+ initializeConfiguration(nitro, serverEnabled);
26
41
  validateConfiguration(nitro);
27
42
  setupBuildDirectories(nitro);
28
- setupRollupExternals(nitro);
29
- setupRollupChunking(nitro);
43
+ if (serverEnabled) {
44
+ setupRollupExternals(nitro);
45
+ setupRollupChunking(nitro);
46
+ }
30
47
  initializeRuntimeConfig(nitro);
31
- setupFileWatching(nitro);
32
- await scanGraphQLFiles(nitro);
33
- setupDevHooks(nitro);
34
- await rollupConfig(nitro);
35
- await generateTypes(nitro);
36
- setupCloseHooks(nitro);
37
- registerRouteHandlers(nitro);
48
+ setupFileWatching(nitro, serverEnabled);
49
+ await scanGraphQLFiles(nitro, serverEnabled);
50
+ if (serverEnabled) setupDevHooks(nitro);
51
+ if (serverEnabled) await rollupConfig(nitro);
52
+ await generateTypes(nitro, serverEnabled);
53
+ setupCloseHooks(nitro, serverEnabled);
54
+ if (serverEnabled) registerRouteHandlers(nitro);
38
55
  setupTypeScriptConfiguration(nitro);
39
56
  setupNuxtIntegration(nitro);
40
- generateScaffoldFiles(nitro);
57
+ logStartupInfo(nitro, serverEnabled);
41
58
  }
42
59
  /**
43
60
  * Initialize default configuration values
44
61
  */
45
- function initializeConfiguration(nitro) {
62
+ function initializeConfiguration(nitro, serverEnabled) {
46
63
  nitro.options.graphql ||= {};
47
64
  nitro.options.graphql.types = defu(nitro.options.graphql.types, DEFAULT_TYPES_CONFIG);
48
- if (!nitro.options.graphql?.framework) logger.warn("No GraphQL framework specified. Please set graphql.framework to \"graphql-yoga\" or \"apollo-server\".");
65
+ if (serverEnabled && !nitro.options.graphql?.framework) logger.warn("No GraphQL framework specified. Please set graphql.framework to \"graphql-yoga\" or \"apollo-server\".");
49
66
  const defaultPaths = getDefaultPaths(nitro);
50
67
  nitro.graphql ||= {
51
68
  buildDir: "",
@@ -58,6 +75,10 @@ function initializeConfiguration(nitro) {
58
75
  server: "server"
59
76
  }
60
77
  };
78
+ nitro.scanSchemas ||= [];
79
+ nitro.scanResolvers ||= [];
80
+ nitro.scanDirectives ||= [];
81
+ nitro.scanDocuments ||= [];
61
82
  }
62
83
  /**
63
84
  * Validate external services configuration
@@ -96,13 +117,17 @@ function setupBuildDirectories(nitro) {
96
117
  * Initialize runtime configuration
97
118
  */
98
119
  function initializeRuntimeConfig(nitro) {
99
- nitro.options.runtimeConfig.graphql = defu(nitro.options.runtimeConfig.graphql || {}, DEFAULT_RUNTIME_CONFIG);
120
+ const securityConfig = resolveSecurityConfig(nitro.options.graphql?.security);
121
+ nitro.options.runtimeConfig.graphql = defu(nitro.options.runtimeConfig.graphql || {}, {
122
+ ...DEFAULT_RUNTIME_CONFIG,
123
+ security: securityConfig
124
+ });
100
125
  }
101
126
  /**
102
127
  * Setup file watching for development mode
103
128
  */
104
- function setupFileWatching(nitro) {
105
- const watchDirs = getWatchDirectories(nitro);
129
+ function setupFileWatching(nitro, serverEnabled) {
130
+ const watchDirs = serverEnabled ? getWatchDirectories(nitro) : [nitro.graphql.clientDir].filter(Boolean);
106
131
  nitro.graphql.watchDirs = watchDirs;
107
132
  const watcher = setupFileWatcher(nitro, watchDirs);
108
133
  nitro.hooks.hook("close", () => {
@@ -112,8 +137,19 @@ function setupFileWatching(nitro) {
112
137
  /**
113
138
  * Scan all GraphQL files (schemas, resolvers, directives, documents)
114
139
  */
115
- async function scanGraphQLFiles(nitro) {
116
- await scanAllGraphQLFiles(nitro);
140
+ async function scanGraphQLFiles(nitro, serverEnabled) {
141
+ const skipLocalScan = nitro.options.graphql?.skipLocalScan === true;
142
+ const extendSources = nitro.options.graphql?.extend;
143
+ if (skipLocalScan && extendSources?.length) {
144
+ logger.info(`Using ${extendSources.length} extend source(s), skipping local scanning`);
145
+ nitro.scanSchemas = [];
146
+ nitro.scanResolvers = [];
147
+ nitro.scanDirectives = [];
148
+ nitro.scanDocuments = (await NitroAdapter.scanDocuments(nitro)).items;
149
+ return;
150
+ }
151
+ if (serverEnabled) await scanAllGraphQLFiles(nitro);
152
+ else nitro.scanDocuments = (await NitroAdapter.scanDocuments(nitro)).items;
117
153
  }
118
154
  /**
119
155
  * Setup dev mode hooks for rescanning files
@@ -157,47 +193,22 @@ function logResolverDiagnostics(nitro) {
157
193
  /**
158
194
  * Generate server and client types
159
195
  */
160
- async function generateTypes(nitro) {
161
- await generateServerTypes(nitro);
162
- await generateClientTypes(nitro, { isInitial: true });
196
+ async function generateTypes(nitro, serverEnabled) {
197
+ if (serverEnabled) {
198
+ await generateServerTypes(nitro);
199
+ await generateClientTypes(nitro, { isInitial: true });
200
+ } else await generateClientTypes(nitro, { isInitial: true });
163
201
  }
164
202
  /**
165
203
  * Setup close hooks for final type generation
166
204
  */
167
- function setupCloseHooks(nitro) {
205
+ function setupCloseHooks(nitro, serverEnabled) {
168
206
  nitro.hooks.hook("close", async () => {
169
- await generateServerTypes(nitro, { silent: true });
207
+ if (serverEnabled) await generateServerTypes(nitro, { silent: true });
170
208
  await generateClientTypes(nitro, { silent: true });
171
209
  });
172
210
  }
173
211
  /**
174
- * Register GraphQL route handlers
175
- */
176
- function registerRouteHandlers(nitro) {
177
- const runtime = fileURLToPath(new URL("routes", import.meta.url));
178
- const framework = nitro.options.graphql?.framework;
179
- if (framework === "graphql-yoga") for (const method of GRAPHQL_HTTP_METHODS) nitro.options.handlers.push({
180
- route: nitro.options.runtimeConfig.graphql?.endpoint?.graphql || "/api/graphql",
181
- handler: join(runtime, "graphql-yoga"),
182
- method
183
- });
184
- if (framework === "apollo-server") for (const method of GRAPHQL_HTTP_METHODS) nitro.options.handlers.push({
185
- route: nitro.options.runtimeConfig.graphql?.endpoint?.graphql || "/api/graphql",
186
- handler: join(runtime, "apollo-server"),
187
- method
188
- });
189
- nitro.options.handlers.push({
190
- route: nitro.options.runtimeConfig.graphql?.endpoint?.healthCheck || "/api/graphql/health",
191
- handler: join(runtime, "health"),
192
- method: "GET"
193
- });
194
- if (nitro.options.dev) nitro.options.handlers.push({
195
- route: ENDPOINT_DEBUG,
196
- handler: join(runtime, "debug"),
197
- method: "GET"
198
- });
199
- }
200
- /**
201
212
  * Setup TypeScript configuration and path aliases
202
213
  */
203
214
  function setupTypeScriptConfiguration(nitro) {
@@ -217,4 +228,4 @@ function setupNuxtIntegration(nitro) {
217
228
  }
218
229
 
219
230
  //#endregion
220
- export { setupNitroGraphQL };
231
+ export { resolveSecurityConfig, setupNitroGraphQL };
@@ -0,0 +1,378 @@
1
+ import { TypeScriptPluginConfig } from "@graphql-codegen/typescript";
2
+ import { plugin as plugin$1 } from "@graphql-codegen/typescript-generic-sdk";
3
+ import { TypeScriptDocumentsPluginConfig } from "@graphql-codegen/typescript-operations";
4
+ import { IResolvers } from "@graphql-tools/utils";
5
+ import { GraphQLSchema } from "graphql";
6
+ import { TypeScriptResolversPluginConfig } from "@graphql-codegen/typescript-resolvers";
7
+ import { ESMCodeGenOptions } from "knitwork";
8
+ import { ApolloServerOptions } from "@apollo/server";
9
+ import { H3Event } from "nitro/h3";
10
+ import { YogaServerOptions } from "graphql-yoga";
11
+ import { NPMConfig } from "#graphql/server";
12
+
13
+ //#region src/nitro/types.d.ts
14
+
15
+ /** The Standard Schema interface. */
16
+ interface StandardSchemaV1<Input = unknown, Output = Input> {
17
+ /** The Standard Schema properties. */
18
+ readonly '~standard': StandardSchemaV1.Props<Input, Output>;
19
+ }
20
+ declare namespace StandardSchemaV1 {
21
+ /** The Standard Schema properties interface. */
22
+ export interface Props<Input = unknown, Output = Input> {
23
+ /** The version number of the standard. */
24
+ readonly version: 1;
25
+ /** The vendor name of the schema library. */
26
+ readonly vendor: string;
27
+ /** Validates unknown input values. */
28
+ readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
29
+ /** Inferred types associated with the schema. */
30
+ readonly types?: Types<Input, Output> | undefined;
31
+ }
32
+ /** The result interface of the validate function. */
33
+ export type Result<Output> = SuccessResult<Output> | FailureResult;
34
+ /** The result interface if validation succeeds. */
35
+ export interface SuccessResult<Output> {
36
+ /** The typed output value. */
37
+ readonly value: Output;
38
+ /** The non-existent issues. */
39
+ readonly issues?: undefined;
40
+ }
41
+ /** The result interface if validation fails. */
42
+ export interface FailureResult {
43
+ /** The issues of failed validation. */
44
+ readonly issues: ReadonlyArray<Issue>;
45
+ }
46
+ /** The issue interface of the failure output. */
47
+ export interface Issue {
48
+ /** The error message of the issue. */
49
+ readonly message: string;
50
+ /** The path of the issue, if any. */
51
+ readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
52
+ }
53
+ /** The path segment interface of the issue. */
54
+ export interface PathSegment {
55
+ /** The key representing a path segment. */
56
+ readonly key: PropertyKey;
57
+ }
58
+ /** The Standard Schema types interface. */
59
+ export interface Types<Input = unknown, Output = Input> {
60
+ /** The input type of the schema. */
61
+ readonly input: Input;
62
+ /** The output type of the schema. */
63
+ readonly output: Output;
64
+ }
65
+ /** Infers the input type of a Standard Schema. */
66
+ export type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['input'];
67
+ /** Infers the output type of a Standard Schema. */
68
+ export type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['output'];
69
+ export {};
70
+ }
71
+ type Flatten<T> = T extends infer U ? { [K in keyof U]: U[K] } : never;
72
+ type DefineServerConfig<T extends NPMConfig = NPMConfig> = T['framework'] extends 'graphql-yoga' ? Partial<YogaServerOptions<H3Event, Partial<H3Event>>> : T['framework'] extends 'apollo-server' ? Partial<ApolloServerOptions<H3Event>> : Partial<YogaServerOptions<H3Event, Partial<H3Event>>> | Partial<ApolloServerOptions<H3Event>>;
73
+ type DirectiveLocationName = 'QUERY' | 'MUTATION' | 'SUBSCRIPTION' | 'FIELD' | 'FRAGMENT_DEFINITION' | 'FRAGMENT_SPREAD' | 'INLINE_FRAGMENT' | 'VARIABLE_DEFINITION' | 'SCHEMA' | 'SCALAR' | 'OBJECT' | 'FIELD_DEFINITION' | 'ARGUMENT_DEFINITION' | 'INTERFACE' | 'UNION' | 'ENUM' | 'ENUM_VALUE' | 'INPUT_OBJECT' | 'INPUT_FIELD_DEFINITION';
74
+ type GraphQLScalarType = 'String' | 'Int' | 'Float' | 'Boolean' | 'ID' | 'JSON' | 'DateTime';
75
+ type GraphQLBaseType = GraphQLScalarType | (string & {});
76
+ type GraphQLArgumentType = 'String' | 'Int' | 'Float' | 'Boolean' | 'ID' | 'JSON' | 'DateTime' | 'String!' | 'Int!' | 'Float!' | 'Boolean!' | 'ID!' | 'JSON!' | 'DateTime!' | '[String]' | '[String!]' | '[String]!' | '[String!]!' | '[Int]' | '[Int!]' | '[Int]!' | '[Int!]!' | '[Float]' | '[Float!]' | '[Float]!' | '[Float!]!' | '[Boolean]' | '[Boolean!]' | '[Boolean]!' | '[Boolean!]!' | '[ID]' | '[ID!]' | '[ID]!' | '[ID!]!' | '[JSON]' | '[JSON!]' | '[JSON]!' | '[JSON!]!' | '[DateTime]' | '[DateTime!]' | '[DateTime]!' | '[DateTime!]!' | (string & {});
77
+ interface DirectiveArgument<T extends GraphQLArgumentType = GraphQLArgumentType> {
78
+ /**
79
+ * GraphQL type for the argument
80
+ * @example 'String', 'Int!', '[String!]!', 'DateTime', 'JSON'
81
+ */
82
+ type: T;
83
+ defaultValue?: any;
84
+ description?: string;
85
+ }
86
+ interface DirectiveArg {
87
+ type: GraphQLArgumentType;
88
+ defaultValue?: any;
89
+ description?: string;
90
+ }
91
+ interface DirectiveDefinition {
92
+ name: string;
93
+ locations: DirectiveLocationName[];
94
+ args?: Record<string, DirectiveArg>;
95
+ description?: string;
96
+ isRepeatable?: boolean;
97
+ transformer?: (schema: GraphQLSchema) => GraphQLSchema;
98
+ }
99
+ interface DefineDirectiveConfig {
100
+ name: string;
101
+ locations: ReadonlyArray<DirectiveLocationName>;
102
+ args?: Record<string, {
103
+ type: GraphQLArgumentType;
104
+ defaultValue?: any;
105
+ description?: string;
106
+ }>;
107
+ description?: string;
108
+ isRepeatable?: boolean;
109
+ transformer?: (schema: GraphQLSchema) => GraphQLSchema;
110
+ }
111
+ type CodegenServerConfig = TypeScriptPluginConfig & TypeScriptResolversPluginConfig;
112
+ type DocumentModeConfig = Pick<Parameters<typeof plugin$1>[2], 'documentMode'>;
113
+ type DocumentModeEnum = NonNullable<DocumentModeConfig['documentMode']>;
114
+ type DocumentModeType = `${DocumentModeEnum}`;
115
+ type GenericSdkConfig = Omit<Parameters<typeof plugin$1>[2], 'documentMode'> & {
116
+ documentMode?: DocumentModeType;
117
+ };
118
+ type CodegenClientConfig = TypeScriptPluginConfig & TypeScriptDocumentsPluginConfig & {
119
+ endpoint?: string;
120
+ /**
121
+ * Generate TypedDocumentNode exports for urql/Apollo Client compatibility.
122
+ * When enabled, generates typed document constants that can be used with
123
+ * any GraphQL client that supports TypedDocumentNode.
124
+ * @default false
125
+ */
126
+ typedDocumentNode?: boolean;
127
+ };
128
+ interface IESMImport {
129
+ name: string;
130
+ as?: string;
131
+ type: 'resolver' | 'query' | 'mutation' | 'type' | 'subscription' | 'directive';
132
+ }
133
+ interface GenImport {
134
+ specifier: string;
135
+ imports: IESMImport[];
136
+ options?: ESMCodeGenOptions;
137
+ }
138
+ declare module 'nitro/types' {
139
+ interface Nitro {
140
+ scanSchemas: string[];
141
+ scanDocuments: string[];
142
+ scanResolvers: GenImport[];
143
+ scanDirectives: GenImport[];
144
+ graphql: {
145
+ buildDir: string;
146
+ watchDirs: string[];
147
+ clientDir: string;
148
+ serverDir: string;
149
+ dir: {
150
+ build: string;
151
+ client: string;
152
+ server: string;
153
+ };
154
+ };
155
+ }
156
+ }
157
+ declare module 'nitro/types' {
158
+ interface NitroOptions {
159
+ graphql?: NitroGraphQLOptions;
160
+ }
161
+ interface NitroRuntimeConfig {
162
+ graphql?: NitroGraphQLOptions;
163
+ }
164
+ interface NitroConfig {
165
+ graphql?: NitroGraphQLOptions;
166
+ }
167
+ }
168
+ /**
169
+ * Service-specific path overrides for external GraphQL services
170
+ * These paths override global config for this specific service
171
+ */
172
+ interface ExternalServicePaths {
173
+ /** SDK file path (overrides global sdk.external config) */
174
+ sdk?: FileGenerationConfig;
175
+ /** Type definitions file path (overrides global types.external config) */
176
+ types?: FileGenerationConfig;
177
+ }
178
+ interface ExternalGraphQLService {
179
+ /** Unique name for this service (used for file naming and type generation) */
180
+ name: string;
181
+ /** GraphQL endpoint for this service (also used as schema source if `schema` is not specified) */
182
+ endpoint: string;
183
+ /**
184
+ * Schema source - can be URL(s) for remote schemas or file path(s) for local schemas
185
+ * @default Uses `endpoint` for introspection if not specified
186
+ */
187
+ schema?: string | string[];
188
+ /** Optional headers for schema introspection and client requests */
189
+ headers?: Record<string, string> | (() => Record<string, string>);
190
+ /** Optional: specific document patterns for this service */
191
+ documents?: string[];
192
+ /**
193
+ * Optional: Download and cache schema locally for offline usage
194
+ * - true or 'once': Download if file doesn't exist, then use cached version (offline-friendly)
195
+ * - 'always': Check for updates on every build (current behavior)
196
+ * - 'manual': Never download automatically, user manages schema files manually
197
+ * - false: Disable schema downloading
198
+ */
199
+ downloadSchema?: boolean | 'once' | 'always' | 'manual';
200
+ /** Optional: Custom path to save downloaded schema (default: .nitro/graphql/schemas/[serviceName].graphql) */
201
+ downloadPath?: string;
202
+ /** Optional: service-specific codegen configuration */
203
+ codegen?: {
204
+ client?: CodegenClientConfig;
205
+ clientSDK?: GenericSdkConfig;
206
+ };
207
+ /**
208
+ * Optional: Service-specific path overrides
209
+ * These paths take precedence over global config (sdk, types, clientUtils)
210
+ * Supports placeholders: {serviceName}, {buildDir}, {rootDir}, {framework}, {typesDir}, {clientGraphql}
211
+ */
212
+ paths?: ExternalServicePaths;
213
+ }
214
+ interface FederationConfig {
215
+ /** Enable Apollo Federation subgraph support */
216
+ enabled: boolean;
217
+ /** Service name for federation (used in subgraph config) */
218
+ serviceName?: string;
219
+ /** Service version for federation */
220
+ serviceVersion?: string;
221
+ /** Service URL for federation gateway */
222
+ serviceUrl?: string;
223
+ }
224
+ /**
225
+ * File generation control:
226
+ * - false: Do not generate this file
227
+ * - true: Generate at default location
228
+ * - string: Generate at custom path (supports placeholders: {serviceName}, {buildDir}, {rootDir}, {framework})
229
+ */
230
+ type FileGenerationConfig = boolean | string;
231
+ /**
232
+ * SDK files configuration
233
+ * Control auto-generation of GraphQL SDK files
234
+ */
235
+ interface SdkConfig {
236
+ /** Enable/disable all SDK files */
237
+ enabled?: boolean;
238
+ /** app/graphql/default/sdk.ts - Main service SDK */
239
+ main?: FileGenerationConfig;
240
+ /** app/graphql/{serviceName}/sdk.ts - External service SDKs */
241
+ external?: FileGenerationConfig;
242
+ }
243
+ /**
244
+ * Type files configuration
245
+ * Control auto-generation of TypeScript type definition files
246
+ */
247
+ interface TypesConfig {
248
+ /** Enable/disable all type files */
249
+ enabled?: boolean;
250
+ /** .nitro/types/nitro-graphql-server.d.ts - Server-side types */
251
+ server?: FileGenerationConfig;
252
+ /** .nitro/types/nitro-graphql-client.d.ts - Client-side types */
253
+ client?: FileGenerationConfig;
254
+ /** .nitro/types/nitro-graphql-client-{serviceName}.d.ts - External service types */
255
+ external?: FileGenerationConfig;
256
+ }
257
+ /**
258
+ * Global path overrides
259
+ * Set base directories for file generation
260
+ */
261
+ interface PathsConfig {
262
+ /** Server GraphQL directory (default: 'server/graphql') */
263
+ serverGraphql?: string;
264
+ /** Client GraphQL directory (default: 'app/graphql' for Nuxt, 'graphql' for Nitro) */
265
+ clientGraphql?: string;
266
+ /** Build directory (default: '.nitro' or '.nuxt') */
267
+ buildDir?: string;
268
+ /** Types directory (default: '{buildDir}/types') */
269
+ typesDir?: string;
270
+ }
271
+ /**
272
+ * Security configuration for production environments
273
+ * All options auto-detect based on NODE_ENV when not explicitly set
274
+ */
275
+ interface SecurityConfig {
276
+ /**
277
+ * Enable GraphQL introspection queries
278
+ * @default true in development, false in production
279
+ */
280
+ introspection?: boolean;
281
+ /**
282
+ * Enable GraphQL playground/sandbox UI
283
+ * @default true in development, false in production
284
+ */
285
+ playground?: boolean;
286
+ /**
287
+ * Mask internal error details in responses
288
+ * When enabled, internal errors show "Internal server error" instead of actual message
289
+ * @default false in development, true in production
290
+ */
291
+ maskErrors?: boolean;
292
+ /**
293
+ * Disable "Did you mean X?" field suggestions in error messages
294
+ * Prevents attackers from discovering field names via brute force
295
+ * @default false in development, true in production
296
+ */
297
+ disableSuggestions?: boolean;
298
+ }
299
+ interface NitroGraphQLOptions {
300
+ framework?: 'graphql-yoga' | 'apollo-server';
301
+ /**
302
+ * Enable/disable GraphQL server functionality
303
+ * When set to false, only external services client types will be generated
304
+ * Server routes, resolvers, schemas, and directives will not be processed
305
+ * @default true
306
+ */
307
+ server?: boolean;
308
+ endpoint?: {
309
+ graphql?: string;
310
+ healthCheck?: string;
311
+ };
312
+ playground?: boolean;
313
+ typedefs?: string[];
314
+ resolvers?: Array<IResolvers<any, any>>;
315
+ loader?: {
316
+ include?: RegExp;
317
+ exclude?: RegExp;
318
+ validate?: boolean;
319
+ };
320
+ codegen?: {
321
+ server?: CodegenServerConfig;
322
+ client?: CodegenClientConfig;
323
+ clientSDK?: GenericSdkConfig;
324
+ };
325
+ /** External GraphQL services to generate types and SDKs for */
326
+ externalServices?: ExternalGraphQLService[];
327
+ /** Apollo Federation configuration */
328
+ federation?: FederationConfig;
329
+ /** Server GraphQL directory path */
330
+ serverDir?: string;
331
+ /** Layer directories (populated by Nuxt module) */
332
+ layerDirectories?: string[];
333
+ layerServerDirs?: string[];
334
+ layerAppDirs?: string[];
335
+ /**
336
+ * SDK files configuration
337
+ * Set to false to disable all SDK generation
338
+ */
339
+ sdk?: false | SdkConfig;
340
+ /**
341
+ * Type files configuration
342
+ * Set to false to disable all type generation
343
+ */
344
+ types?: false | TypesConfig;
345
+ /**
346
+ * Global path overrides
347
+ * Customize base directories for file generation
348
+ */
349
+ paths?: PathsConfig;
350
+ /**
351
+ * Security configuration for production environments
352
+ * Auto-detects NODE_ENV and applies secure defaults in production
353
+ */
354
+ security?: SecurityConfig;
355
+ /**
356
+ * Extend GraphQL server with external packages
357
+ * Auto-appends /resolvers and /schema to each package path
358
+ * @example extend: ['@myorg/graphql', './generated']
359
+ */
360
+ extend?: ExtendSource[];
361
+ /**
362
+ * Skip local file scanning, use only extend sources
363
+ * When true, only files from `extend` are used (local server/graphql ignored)
364
+ * @default false
365
+ */
366
+ skipLocalScan?: boolean;
367
+ }
368
+ /**
369
+ * Extend source - package path or detailed config
370
+ * - string: auto-appends /resolvers and /schema
371
+ * - object: explicit paths for resolvers and/or schemas
372
+ */
373
+ type ExtendSource = string | {
374
+ resolvers?: string | string[];
375
+ schemas?: string | string[];
376
+ };
377
+ //#endregion
378
+ export { CodegenClientConfig, CodegenServerConfig, DefineDirectiveConfig, DefineServerConfig, DirectiveArgument, DirectiveDefinition, ExtendSource, ExternalGraphQLService, ExternalServicePaths, FederationConfig, FileGenerationConfig, Flatten, GenImport, GenericSdkConfig, GraphQLArgumentType, GraphQLBaseType, GraphQLScalarType, NitroGraphQLOptions, PathsConfig, SdkConfig, SecurityConfig, StandardSchemaV1, TypesConfig };
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,31 @@
1
+ import { Nitro } from "nitro/types";
2
+
3
+ //#region src/nitro/virtual/generators.d.ts
4
+
5
+ declare const serverSchemas: {
6
+ id: string;
7
+ getCode: (nitro: Nitro) => string;
8
+ };
9
+ declare const serverResolvers: {
10
+ id: string;
11
+ getCode: (nitro: Nitro) => string;
12
+ };
13
+ declare const serverDirectives: {
14
+ id: string;
15
+ getCode: (nitro: Nitro) => string;
16
+ };
17
+ declare const graphqlConfig: {
18
+ id: string;
19
+ getCode: (nitro: Nitro) => string;
20
+ };
21
+ declare const moduleConfig: {
22
+ id: string;
23
+ getCode: (nitro: Nitro) => string;
24
+ };
25
+ declare const debugInfo: {
26
+ id: string;
27
+ getCode: (nitro: Nitro) => string;
28
+ };
29
+ declare function registerAllVirtualModules(nitro: Nitro): void;
30
+ //#endregion
31
+ export { debugInfo, graphqlConfig, moduleConfig, registerAllVirtualModules, serverDirectives, serverResolvers, serverSchemas };