nitro-graphql 2.0.0-beta.4 → 2.0.0-beta.41

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 (168) hide show
  1. package/README.md +438 -27
  2. package/dist/cli/commands/generate.d.mts +26 -0
  3. package/dist/cli/commands/generate.mjs +196 -0
  4. package/dist/cli/commands/index.d.mts +4 -0
  5. package/dist/cli/commands/index.mjs +5 -0
  6. package/dist/cli/commands/init.d.mts +46 -0
  7. package/dist/cli/commands/init.mjs +195 -0
  8. package/dist/cli/commands/validate.d.mts +10 -0
  9. package/dist/cli/commands/validate.mjs +69 -0
  10. package/dist/cli/completions.d.mts +7 -0
  11. package/dist/cli/completions.mjs +34 -0
  12. package/dist/cli/config.d.mts +75 -0
  13. package/dist/cli/config.mjs +20 -0
  14. package/dist/cli/index.d.mts +24 -0
  15. package/dist/cli/index.mjs +253 -0
  16. package/dist/config.d.mts +2 -0
  17. package/dist/config.mjs +3 -0
  18. package/dist/core/codegen/client.d.mts +23 -0
  19. package/dist/core/codegen/client.mjs +150 -0
  20. package/dist/core/codegen/document-loader.d.mts +10 -0
  21. package/dist/core/codegen/document-loader.mjs +18 -0
  22. package/dist/core/codegen/index.d.mts +8 -0
  23. package/dist/core/codegen/index.mjs +9 -0
  24. package/dist/core/codegen/plugin.d.mts +20 -0
  25. package/dist/core/codegen/plugin.mjs +30 -0
  26. package/dist/core/codegen/runtime.d.mts +20 -0
  27. package/dist/core/codegen/runtime.mjs +60 -0
  28. package/dist/core/codegen/schema-loader.d.mts +28 -0
  29. package/dist/core/codegen/schema-loader.mjs +128 -0
  30. package/dist/core/codegen/server.d.mts +28 -0
  31. package/dist/core/codegen/server.mjs +143 -0
  32. package/dist/core/codegen/validation.d.mts +13 -0
  33. package/dist/core/codegen/validation.mjs +96 -0
  34. package/dist/core/config.d.mts +50 -0
  35. package/dist/core/config.mjs +82 -0
  36. package/dist/core/constants.d.mts +188 -0
  37. package/dist/core/constants.mjs +210 -0
  38. package/dist/core/index.d.mts +33 -0
  39. package/dist/core/index.mjs +27 -0
  40. package/dist/core/manifest.d.mts +46 -0
  41. package/dist/core/manifest.mjs +76 -0
  42. package/dist/core/scanning/ast-scanner.d.mts +28 -0
  43. package/dist/core/scanning/ast-scanner.mjs +122 -0
  44. package/dist/core/scanning/common.d.mts +37 -0
  45. package/dist/core/scanning/common.mjs +60 -0
  46. package/dist/core/scanning/directives.d.mts +10 -0
  47. package/dist/core/scanning/directives.mjs +29 -0
  48. package/dist/core/scanning/documents.d.mts +21 -0
  49. package/dist/core/scanning/documents.mjs +43 -0
  50. package/dist/core/scanning/index.d.mts +7 -0
  51. package/dist/core/scanning/index.mjs +8 -0
  52. package/dist/core/scanning/resolvers.d.mts +15 -0
  53. package/dist/core/scanning/resolvers.mjs +59 -0
  54. package/dist/core/scanning/schemas.d.mts +14 -0
  55. package/dist/core/scanning/schemas.mjs +64 -0
  56. package/dist/core/schema/builder.d.mts +53 -0
  57. package/dist/core/schema/builder.mjs +70 -0
  58. package/dist/core/schema/federation.d.mts +34 -0
  59. package/dist/core/schema/federation.mjs +40 -0
  60. package/dist/core/schema/index.d.mts +3 -0
  61. package/dist/core/schema/index.mjs +4 -0
  62. package/dist/core/types/adapter.d.mts +58 -0
  63. package/dist/core/types/codegen.d.mts +133 -0
  64. package/dist/core/types/config.d.mts +210 -0
  65. package/dist/core/types/config.mjs +1 -0
  66. package/dist/{utils/define.d.ts → core/types/define.d.mts} +3 -30
  67. package/dist/core/types/define.mjs +1 -0
  68. package/dist/core/types/index.d.mts +5 -0
  69. package/dist/core/types/index.mjs +1 -0
  70. package/dist/core/types/scanning.d.mts +69 -0
  71. package/dist/core/types/scanning.mjs +1 -0
  72. package/dist/{utils/directive-parser.d.ts → core/utils/directive-parser.d.mts} +21 -4
  73. package/dist/{utils/directive-parser.js → core/utils/directive-parser.mjs} +25 -34
  74. package/dist/core/utils/errors.d.mts +77 -0
  75. package/dist/core/utils/errors.mjs +93 -0
  76. package/dist/core/utils/file-io.d.mts +24 -0
  77. package/dist/core/utils/file-io.mjs +47 -0
  78. package/dist/core/utils/imports.d.mts +15 -0
  79. package/dist/core/utils/imports.mjs +25 -0
  80. package/dist/core/utils/index.d.mts +7 -0
  81. package/dist/core/utils/index.mjs +8 -0
  82. package/dist/core/utils/logger.d.mts +19 -0
  83. package/dist/core/utils/logger.mjs +38 -0
  84. package/dist/core/utils/ofetch-templates.d.mts +30 -0
  85. package/dist/core/utils/ofetch-templates.mjs +135 -0
  86. package/dist/core/validation/external-services.d.mts +11 -0
  87. package/dist/core/validation/external-services.mjs +34 -0
  88. package/dist/core/validation/index.d.mts +2 -0
  89. package/dist/core/validation/index.mjs +3 -0
  90. package/dist/define.d.mts +294 -0
  91. package/dist/define.mjs +323 -0
  92. package/dist/index.d.mts +6 -0
  93. package/dist/index.mjs +6 -0
  94. package/dist/nitro/adapter.d.mts +30 -0
  95. package/dist/nitro/adapter.mjs +97 -0
  96. package/dist/{utils/apollo.d.ts → nitro/apollo.d.mts} +3 -3
  97. package/dist/nitro/apollo.mjs +59 -0
  98. package/dist/nitro/codegen.d.mts +19 -0
  99. package/dist/nitro/codegen.mjs +141 -0
  100. package/dist/nitro/config.d.mts +51 -0
  101. package/dist/nitro/config.mjs +57 -0
  102. package/dist/nitro/index.d.mts +46 -0
  103. package/dist/nitro/index.mjs +65 -0
  104. package/dist/nitro/paths.d.mts +54 -0
  105. package/dist/nitro/paths.mjs +92 -0
  106. package/dist/nitro/rollup.d.mts +6 -0
  107. package/dist/nitro/rollup.mjs +95 -0
  108. package/dist/nitro/routes/apollo-server.d.mts +6 -0
  109. package/dist/nitro/routes/apollo-server.mjs +71 -0
  110. package/dist/nitro/routes/debug-template.d.mts +15 -0
  111. package/dist/nitro/routes/debug-template.mjs +385 -0
  112. package/dist/nitro/routes/debug.d.mts +55 -0
  113. package/dist/nitro/routes/debug.mjs +102 -0
  114. package/dist/nitro/routes/graphql-yoga.d.mts +6 -0
  115. package/dist/nitro/routes/graphql-yoga.mjs +62 -0
  116. package/dist/nitro/routes/health.d.mts +10 -0
  117. package/dist/{routes/health.js → nitro/routes/health.mjs} +4 -3
  118. package/dist/nitro/setup/extend-loader.d.mts +19 -0
  119. package/dist/nitro/setup/extend-loader.mjs +129 -0
  120. package/dist/nitro/setup/file-watcher.d.mts +16 -0
  121. package/dist/nitro/setup/file-watcher.mjs +98 -0
  122. package/dist/nitro/setup/logging.d.mts +17 -0
  123. package/dist/nitro/setup/logging.mjs +66 -0
  124. package/dist/nitro/setup/rollup-integration.d.mts +16 -0
  125. package/dist/nitro/setup/rollup-integration.mjs +90 -0
  126. package/dist/nitro/setup/routes.d.mts +10 -0
  127. package/dist/nitro/setup/routes.mjs +35 -0
  128. package/dist/nitro/setup/ts-config.d.mts +11 -0
  129. package/dist/nitro/setup/ts-config.mjs +69 -0
  130. package/dist/nitro/setup.d.mts +12 -0
  131. package/dist/nitro/setup.mjs +234 -0
  132. package/dist/nitro/types.d.mts +374 -0
  133. package/dist/nitro/types.mjs +1 -0
  134. package/dist/nitro/virtual/generators.d.mts +31 -0
  135. package/dist/nitro/virtual/generators.mjs +113 -0
  136. package/dist/nitro/virtual/stubs.d.mts +20 -0
  137. package/dist/nitro/virtual/stubs.mjs +31 -0
  138. package/dist/{ecosystem/nuxt.d.ts → nuxt.d.mts} +1 -1
  139. package/dist/nuxt.mjs +109 -0
  140. package/dist/{graphql/server.d.ts → stubs/index.d.mts} +5 -1
  141. package/dist/stubs/index.mjs +1 -0
  142. package/package.json +102 -77
  143. package/dist/ecosystem/nuxt.js +0 -67
  144. package/dist/graphql/index.d.ts +0 -5
  145. package/dist/index.d.ts +0 -8
  146. package/dist/index.js +0 -264
  147. package/dist/rollup.js +0 -119
  148. package/dist/routes/apollo-server.d.ts +0 -6
  149. package/dist/routes/apollo-server.js +0 -89
  150. package/dist/routes/graphql-yoga.d.ts +0 -6
  151. package/dist/routes/graphql-yoga.js +0 -91
  152. package/dist/routes/health.d.ts +0 -6
  153. package/dist/types/index.d.ts +0 -128
  154. package/dist/types/standard-schema.d.ts +0 -59
  155. package/dist/utils/apollo.js +0 -61
  156. package/dist/utils/client-codegen.d.ts +0 -38
  157. package/dist/utils/client-codegen.js +0 -290
  158. package/dist/utils/define.js +0 -57
  159. package/dist/utils/index.d.ts +0 -39
  160. package/dist/utils/index.js +0 -250
  161. package/dist/utils/server-codegen.d.ts +0 -7
  162. package/dist/utils/server-codegen.js +0 -136
  163. package/dist/utils/type-generation.d.ts +0 -7
  164. package/dist/utils/type-generation.js +0 -287
  165. package/dist/vite.d.ts +0 -25
  166. package/dist/vite.js +0 -40
  167. /package/dist/{graphql/index.js → core/types/adapter.mjs} +0 -0
  168. /package/dist/{graphql/server.js → core/types/codegen.mjs} +0 -0
@@ -0,0 +1,55 @@
1
+ import * as nitro_deps_h30 from "nitro/deps/h3";
2
+
3
+ //#region src/nitro/routes/debug.d.ts
4
+
5
+ /**
6
+ * Debug endpoint for inspecting virtual modules and GraphQL setup
7
+ * Only available in development mode
8
+ *
9
+ * Routes:
10
+ * - /_nitro/graphql/debug - HTML dashboard
11
+ * - /_nitro/graphql/debug?format=json - JSON API
12
+ */
13
+ declare const _default: nitro_deps_h30.EventHandlerWithFetch<nitro_deps_h30.EventHandlerRequest, Promise<string | {
14
+ timestamp: string;
15
+ environment: {
16
+ dev: any;
17
+ framework: any;
18
+ };
19
+ graphql: {
20
+ framework: any;
21
+ federation: any;
22
+ };
23
+ scanned: {
24
+ schemas: any;
25
+ schemaFiles: any;
26
+ resolvers: any;
27
+ resolverFiles: any;
28
+ directives: any;
29
+ directiveFiles: any;
30
+ documents: any;
31
+ documentFiles: any;
32
+ };
33
+ runtime: {
34
+ loadedResolvers: any;
35
+ loadedSchemas: any;
36
+ loadedDirectives: any;
37
+ };
38
+ virtualModules: any;
39
+ virtualModuleSamples: {
40
+ 'server-resolvers': {
41
+ resolverCount: any;
42
+ sample: any;
43
+ };
44
+ 'server-schemas': {
45
+ schemaCount: any;
46
+ sample: any;
47
+ };
48
+ 'server-directives': {
49
+ directiveCount: any;
50
+ };
51
+ 'module-config': any;
52
+ };
53
+ }>>;
54
+ //#endregion
55
+ export { _default as default };
@@ -0,0 +1,102 @@
1
+ import { generateHtmlDashboard } from "./debug-template.mjs";
2
+ import { defineEventHandler, getQuery } from "nitro/h3";
3
+ import { moduleConfig } from "#nitro-graphql/module-config";
4
+ import { directives } from "#nitro-graphql/server-directives";
5
+ import { resolvers } from "#nitro-graphql/server-resolvers";
6
+ import { schemas } from "#nitro-graphql/server-schemas";
7
+ import { debugInfo } from "#nitro-graphql/debug-info";
8
+
9
+ //#region src/nitro/routes/debug.ts
10
+ /**
11
+ * Debug endpoint for inspecting virtual modules and GraphQL setup
12
+ * Only available in development mode
13
+ *
14
+ * Routes:
15
+ * - /_nitro/graphql/debug - HTML dashboard
16
+ * - /_nitro/graphql/debug?format=json - JSON API
17
+ */
18
+ var debug_default = defineEventHandler(async (event) => {
19
+ const format = getQuery(event).format || "html";
20
+ const processedResolverFiles = debugInfo.scanned.resolverFiles.map((r) => {
21
+ const parts = r.specifier.split("/");
22
+ return {
23
+ file: parts[parts.length - 1],
24
+ fullPath: r.specifier,
25
+ exports: r.imports.map((i) => ({
26
+ name: i.name,
27
+ type: i.type,
28
+ as: i.as
29
+ }))
30
+ };
31
+ });
32
+ const processedDirectiveFiles = debugInfo.scanned.directiveFiles.map((d) => {
33
+ const parts = d.specifier.split("/");
34
+ return {
35
+ file: parts[parts.length - 1],
36
+ fullPath: d.specifier,
37
+ exports: d.imports.map((i) => ({
38
+ name: i.name,
39
+ type: i.type,
40
+ as: i.as
41
+ }))
42
+ };
43
+ });
44
+ const fullDebugInfo = {
45
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
46
+ environment: {
47
+ dev: debugInfo.isDev,
48
+ framework: debugInfo.framework
49
+ },
50
+ graphql: {
51
+ framework: debugInfo.graphqlFramework,
52
+ federation: debugInfo.federation
53
+ },
54
+ scanned: {
55
+ schemas: debugInfo.scanned.schemas,
56
+ schemaFiles: debugInfo.scanned.schemaFiles.map((s) => {
57
+ return s.split("/").slice(-3).join("/");
58
+ }),
59
+ resolvers: debugInfo.scanned.resolvers,
60
+ resolverFiles: processedResolverFiles,
61
+ directives: debugInfo.scanned.directives,
62
+ directiveFiles: processedDirectiveFiles,
63
+ documents: debugInfo.scanned.documents,
64
+ documentFiles: debugInfo.scanned.documentFiles.map((d) => {
65
+ return d.split("/").slice(-3).join("/");
66
+ })
67
+ },
68
+ runtime: {
69
+ loadedResolvers: resolvers.length,
70
+ loadedSchemas: schemas.length,
71
+ loadedDirectives: directives.length
72
+ },
73
+ virtualModules: debugInfo.virtualModules || {},
74
+ virtualModuleSamples: {
75
+ "server-resolvers": {
76
+ resolverCount: resolvers.length,
77
+ sample: resolvers.slice(0, 3).map((r) => ({
78
+ hasResolver: !!r.resolver,
79
+ resolverKeys: r.resolver ? Object.keys(r.resolver) : []
80
+ }))
81
+ },
82
+ "server-schemas": {
83
+ schemaCount: schemas.length,
84
+ sample: schemas.slice(0, 2).map((s) => ({
85
+ defLength: s.def?.length || 0,
86
+ defPreview: s.def?.substring(0, 100) || "Empty"
87
+ }))
88
+ },
89
+ "server-directives": { directiveCount: directives.length },
90
+ "module-config": moduleConfig
91
+ }
92
+ };
93
+ if (format === "json") {
94
+ event.res.headers.set("Content-Type", "application/json");
95
+ return fullDebugInfo;
96
+ }
97
+ event.res.headers.set("Content-Type", "text/html");
98
+ return generateHtmlDashboard(fullDebugInfo);
99
+ });
100
+
101
+ //#endregion
102
+ export { debug_default as default };
@@ -0,0 +1,6 @@
1
+ import * as nitro_deps_h31 from "nitro/deps/h3";
2
+
3
+ //#region src/nitro/routes/graphql-yoga.d.ts
4
+ declare const _default: nitro_deps_h31.EventHandlerWithFetch<nitro_deps_h31.EventHandlerRequest, Promise<Response>>;
5
+ //#endregion
6
+ export { _default as default };
@@ -0,0 +1,62 @@
1
+ import { createMergedSchema } from "../../core/schema/builder.mjs";
2
+ import defu from "defu";
3
+ import { defineEventHandler } from "nitro/h3";
4
+ import { importedConfig } from "#nitro-graphql/graphql-config";
5
+ import { moduleConfig } from "#nitro-graphql/module-config";
6
+ import { directives } from "#nitro-graphql/server-directives";
7
+ import { resolvers } from "#nitro-graphql/server-resolvers";
8
+ import { schemas } from "#nitro-graphql/server-schemas";
9
+ import { createYoga } from "graphql-yoga";
10
+
11
+ //#region src/nitro/routes/graphql-yoga.ts
12
+ const apolloSandboxHtml = `<!DOCTYPE html>
13
+ <html lang="en">
14
+ <body style="margin: 0; overflow-x: hidden; overflow-y: hidden">
15
+ <div id="sandbox" style="height:100vh; width:100vw;"></div>
16
+ <script src="https://embeddable-sandbox.cdn.apollographql.com/02e2da0fccbe0240ef03d2396d6c98559bab5b06/embeddable-sandbox.umd.production.min.js"><\/script>
17
+ <script>
18
+ new window.EmbeddedSandbox({
19
+ target: "#sandbox",
20
+ initialEndpoint: window.location.href,
21
+ hideCookieToggle: false,
22
+ initialState: {
23
+ includeCookies: true
24
+ }
25
+ });
26
+ <\/script>
27
+ </body>
28
+ </html>`;
29
+ let yoga;
30
+ var graphql_yoga_default = defineEventHandler(async (event) => {
31
+ if (!yoga) {
32
+ const schema = await createMergedSchema({
33
+ schemas,
34
+ resolvers,
35
+ directives,
36
+ moduleConfig
37
+ });
38
+ const securityConfig = moduleConfig.security || {
39
+ introspection: true,
40
+ playground: true,
41
+ maskErrors: false,
42
+ disableSuggestions: false
43
+ };
44
+ yoga = createYoga(defu({
45
+ schema,
46
+ graphqlEndpoint: "/api/graphql",
47
+ landingPage: securityConfig.playground,
48
+ graphiql: securityConfig.playground ? { defaultQuery: "# Welcome to GraphQL\n#\n# Try running a query!\n" } : false,
49
+ renderGraphiQL: securityConfig.playground ? () => apolloSandboxHtml : void 0,
50
+ maskedErrors: securityConfig.maskErrors
51
+ }, importedConfig));
52
+ }
53
+ const response = await yoga.handleRequest(event.req, event);
54
+ if (event.res.status && event.res.status !== 200) return new Response(response.body, {
55
+ ...response,
56
+ status: event.res.status
57
+ });
58
+ return new Response(response.body, response);
59
+ });
60
+
61
+ //#endregion
62
+ export { graphql_yoga_default as default };
@@ -0,0 +1,10 @@
1
+ import * as nitro_deps_h33 from "nitro/deps/h3";
2
+
3
+ //#region src/nitro/routes/health.d.ts
4
+ declare const _default: nitro_deps_h33.EventHandlerWithFetch<nitro_deps_h33.EventHandlerRequest, Promise<{
5
+ status: string;
6
+ message: string;
7
+ timestamp: string;
8
+ }>>;
9
+ //#endregion
10
+ export { _default as default };
@@ -1,7 +1,8 @@
1
- import { defineEventHandler } from "h3";
2
- import { useRuntimeConfig } from "nitro/runtime";
1
+ import { defineEventHandler } from "nitro/h3";
2
+ import { $fetch } from "nitro/deps/ofetch";
3
+ import { useRuntimeConfig } from "nitro/runtime-config";
3
4
 
4
- //#region src/routes/health.ts
5
+ //#region src/nitro/routes/health.ts
5
6
  var health_default = defineEventHandler(async (event) => {
6
7
  const runtime = useRuntimeConfig();
7
8
  if (!runtime.graphql || !runtime.graphql.endpoint?.graphql) {
@@ -0,0 +1,19 @@
1
+ import { Nitro } from "nitro/types";
2
+
3
+ //#region src/nitro/setup/extend-loader.d.ts
4
+
5
+ /**
6
+ * Resolve extend directories for file watching
7
+ * Called early in setup (before watcher) to get directories to watch
8
+ */
9
+ declare function resolveExtendDirs(nitro: Nitro): Promise<string[]>;
10
+ interface ResolveExtendOptions {
11
+ silent?: boolean;
12
+ }
13
+ /**
14
+ * Resolve extend configuration and add files to scan results
15
+ * Must be called AFTER scanGraphQLFiles to append to results
16
+ */
17
+ declare function resolveExtendConfig(nitro: Nitro, options?: ResolveExtendOptions): Promise<void>;
18
+ //#endregion
19
+ export { resolveExtendConfig, resolveExtendDirs };
@@ -0,0 +1,129 @@
1
+ import { LOG_TAG } from "../../core/constants.mjs";
2
+ import { loadPackageConfig, resolvePackageFiles } from "../../core/manifest.mjs";
3
+ import { parseSingleFile } from "../../core/scanning/ast-scanner.mjs";
4
+ import { parseResolverCall } from "../../core/scanning/resolvers.mjs";
5
+ import consola from "consola";
6
+ import { dirname, resolve } from "pathe";
7
+
8
+ //#region src/nitro/setup/extend-loader.ts
9
+ const logger = consola.withTag(LOG_TAG);
10
+ /**
11
+ * Resolve extend directories for file watching
12
+ * Called early in setup (before watcher) to get directories to watch
13
+ */
14
+ async function resolveExtendDirs(nitro) {
15
+ const extend = nitro.options.graphql?.extend;
16
+ if (!extend || !Array.isArray(extend) || extend.length === 0) return [];
17
+ const dirs = [];
18
+ for (const source of extend) if (typeof source === "string") {
19
+ const pkg = await loadPackageConfig(source, nitro.options.rootDir);
20
+ if (pkg) {
21
+ const serverDir = resolve(pkg.baseDir, pkg.config.serverDir || "server/graphql");
22
+ dirs.push(serverDir);
23
+ }
24
+ } else if (source && typeof source === "object") {
25
+ const obj = source;
26
+ if (obj.schemas) {
27
+ const schemas = Array.isArray(obj.schemas) ? obj.schemas : [obj.schemas];
28
+ for (const schemaPath of schemas) dirs.push(dirname(resolve(nitro.options.rootDir, schemaPath)));
29
+ }
30
+ if (obj.resolvers) {
31
+ const resolvers = Array.isArray(obj.resolvers) ? obj.resolvers : [obj.resolvers];
32
+ for (const resolverPath of resolvers) dirs.push(dirname(resolve(nitro.options.rootDir, resolverPath)));
33
+ }
34
+ }
35
+ return [...new Set(dirs)];
36
+ }
37
+ /**
38
+ * Resolve extend configuration and add files to scan results
39
+ * Must be called AFTER scanGraphQLFiles to append to results
40
+ */
41
+ async function resolveExtendConfig(nitro, options = {}) {
42
+ const extend = nitro.options.graphql?.extend;
43
+ if (!extend || !Array.isArray(extend) || extend.length === 0) return;
44
+ let schemasAdded = 0;
45
+ let resolversAdded = 0;
46
+ for (const source of extend) {
47
+ const result = await processExtendSource(source, nitro, options.silent);
48
+ schemasAdded += result.schemas;
49
+ resolversAdded += result.resolvers;
50
+ }
51
+ if (!options.silent && (schemasAdded > 0 || resolversAdded > 0)) logger.info(`Extended with ${schemasAdded} schema(s), ${resolversAdded} resolver file(s)`);
52
+ }
53
+ /**
54
+ * Process a single extend source (package name or explicit config)
55
+ */
56
+ async function processExtendSource(source, nitro, silent) {
57
+ if (typeof source === "string") return loadFromPackage(source, nitro, silent);
58
+ if (source && typeof source === "object") return processExplicitPaths(source, nitro);
59
+ return {
60
+ schemas: 0,
61
+ resolvers: 0
62
+ };
63
+ }
64
+ /**
65
+ * Load and scan files from a package's nitro-graphql.config.ts
66
+ */
67
+ async function loadFromPackage(packageName, nitro, silent) {
68
+ const pkg = await loadPackageConfig(packageName, nitro.options.rootDir);
69
+ if (!pkg) throw new Error(`[nitro-graphql] Config not found for "${packageName}". Create a nitro-graphql.config.ts file in the package root.`);
70
+ const files = await resolvePackageFiles(pkg);
71
+ if (!silent) logger.info(`Loaded config from ${packageName}`);
72
+ return addPackageFiles(files, nitro);
73
+ }
74
+ /**
75
+ * Add files from a resolved package to scan results
76
+ */
77
+ async function addPackageFiles(files, nitro) {
78
+ let schemasAdded = 0;
79
+ let resolversAdded = 0;
80
+ for (const schemaPath of files.schemas) if (!nitro.scanSchemas.includes(schemaPath)) {
81
+ nitro.scanSchemas.push(schemaPath);
82
+ schemasAdded++;
83
+ }
84
+ for (const resolverPath of files.resolvers) {
85
+ const parsed = await parseSingleFile(resolverPath, parseResolverCall);
86
+ if (parsed?.imports.length) {
87
+ nitro.scanResolvers.push(parsed);
88
+ resolversAdded++;
89
+ }
90
+ }
91
+ return {
92
+ schemas: schemasAdded,
93
+ resolvers: resolversAdded
94
+ };
95
+ }
96
+ /**
97
+ * Process explicit paths (legacy format)
98
+ */
99
+ async function processExplicitPaths(source, nitro) {
100
+ let schemasAdded = 0;
101
+ let resolversAdded = 0;
102
+ if (source.schemas) {
103
+ const schemas = Array.isArray(source.schemas) ? source.schemas : [source.schemas];
104
+ for (const schemaPath of schemas) {
105
+ const fullPath = resolve(nitro.options.rootDir, schemaPath);
106
+ if (!nitro.scanSchemas.includes(fullPath)) {
107
+ nitro.scanSchemas.push(fullPath);
108
+ schemasAdded++;
109
+ }
110
+ }
111
+ }
112
+ if (source.resolvers) {
113
+ const resolvers = Array.isArray(source.resolvers) ? source.resolvers : [source.resolvers];
114
+ for (const resolverPath of resolvers) {
115
+ const parsed = await parseSingleFile(resolve(nitro.options.rootDir, resolverPath), parseResolverCall);
116
+ if (parsed?.imports.length) {
117
+ nitro.scanResolvers.push(parsed);
118
+ resolversAdded++;
119
+ }
120
+ }
121
+ }
122
+ return {
123
+ schemas: schemasAdded,
124
+ resolvers: resolversAdded
125
+ };
126
+ }
127
+
128
+ //#endregion
129
+ export { resolveExtendConfig, resolveExtendDirs };
@@ -0,0 +1,16 @@
1
+ import { FSWatcher } from "chokidar";
2
+ import { Nitro } from "nitro/types";
3
+
4
+ //#region src/nitro/setup/file-watcher.d.ts
5
+
6
+ /**
7
+ * Setup file watcher for GraphQL files (schemas, resolvers, directives, documents)
8
+ * Watches for changes and triggers type regeneration and dev server reload
9
+ */
10
+ declare function setupFileWatcher(nitro: Nitro, watchDirs: string[]): FSWatcher;
11
+ /**
12
+ * Determine which directories to watch based on framework and configuration
13
+ */
14
+ declare function getWatchDirectories(nitro: Nitro, extendDirs?: string[]): string[];
15
+ //#endregion
16
+ export { getWatchDirectories, setupFileWatcher };
@@ -0,0 +1,98 @@
1
+ import { DIRECTIVE_EXTENSIONS, DIR_SERVER_GRAPHQL, DIR_SERVER_GRAPHQL_WIN, GRAPHQL_EXTENSIONS, LOG_TAG, RESOLVER_EXTENSIONS } from "../../core/constants.mjs";
2
+ import { generateDirectiveSchemas } from "../../core/utils/directive-parser.mjs";
3
+ import { NitroAdapter } from "../adapter.mjs";
4
+ import { generateClientTypes, generateServerTypes } from "../codegen.mjs";
5
+ import { DEFAULT_WATCHER_IGNORE_INITIAL, DEFAULT_WATCHER_PERSISTENT } from "../config.mjs";
6
+ import { resolveExtendConfig } from "./extend-loader.mjs";
7
+ import consola from "consola";
8
+ import { join, resolve } from "pathe";
9
+ import { existsSync, readFileSync, writeFileSync } from "node:fs";
10
+ import { watch } from "chokidar";
11
+
12
+ //#region src/nitro/setup/file-watcher.ts
13
+ const logger = consola.withTag(LOG_TAG);
14
+ /**
15
+ * Touch config.ts to trigger Rolldown's file watcher
16
+ * This is needed because Rolldown doesn't detect changes to .graphql files in external packages
17
+ */
18
+ function triggerRolldownRebuild(nitro) {
19
+ const configPath = resolve(nitro.graphql.serverDir, "config.ts");
20
+ if (existsSync(configPath)) try {
21
+ const content = readFileSync(configPath, "utf-8");
22
+ const timestampComment = `// HMR trigger: ${Date.now()}`;
23
+ writeFileSync(configPath, `${content.replace(/\/\/ HMR trigger: \d+\n?$/, "")}\n${timestampComment}\n`);
24
+ } catch {}
25
+ }
26
+ /**
27
+ * Setup file watcher for GraphQL files (schemas, resolvers, directives, documents)
28
+ * Watches for changes and triggers type regeneration and dev server reload
29
+ */
30
+ function setupFileWatcher(nitro, watchDirs) {
31
+ const watcher = watch(watchDirs, {
32
+ persistent: DEFAULT_WATCHER_PERSISTENT,
33
+ ignoreInitial: DEFAULT_WATCHER_IGNORE_INITIAL,
34
+ ignored: nitro.options.ignore
35
+ });
36
+ watcher.on("all", async (_, path) => {
37
+ if (path.includes("/sdk.ts") || path.includes("/sdk.js") || path.endsWith("/config.ts")) return;
38
+ const isGraphQLFile = GRAPHQL_EXTENSIONS.some((ext) => path.endsWith(ext));
39
+ const isResolverFile = RESOLVER_EXTENSIONS.some((ext) => path.endsWith(ext));
40
+ const isDirectiveFile = DIRECTIVE_EXTENSIONS.some((ext) => path.endsWith(ext));
41
+ if (isGraphQLFile || isResolverFile || isDirectiveFile) if (path.includes(nitro.graphql.serverDir) || path.includes(DIR_SERVER_GRAPHQL) || path.includes(DIR_SERVER_GRAPHQL_WIN) || isResolverFile || isDirectiveFile) {
42
+ const directivesResult = await NitroAdapter.scanDirectives(nitro);
43
+ nitro.scanDirectives = directivesResult.items;
44
+ if (!nitro.scanSchemas) nitro.scanSchemas = [];
45
+ const directivesPath = await generateDirectiveSchemas(nitro, directivesResult.items);
46
+ const schemas = (await NitroAdapter.scanSchemas(nitro)).items;
47
+ if (directivesPath && !schemas.includes(directivesPath)) schemas.push(directivesPath);
48
+ nitro.scanSchemas = schemas;
49
+ nitro.scanResolvers = (await NitroAdapter.scanResolvers(nitro)).items;
50
+ await resolveExtendConfig(nitro, { silent: true });
51
+ logger.success("Types regenerated");
52
+ await generateServerTypes(nitro, { silent: true });
53
+ await generateClientTypes(nitro, { silent: true });
54
+ if (isGraphQLFile) triggerRolldownRebuild(nitro);
55
+ await nitro.hooks.callHook("dev:reload");
56
+ } else {
57
+ logger.success("Types regenerated");
58
+ await generateClientTypes(nitro, { silent: true });
59
+ }
60
+ });
61
+ return watcher;
62
+ }
63
+ /**
64
+ * Determine which directories to watch based on framework and configuration
65
+ */
66
+ function getWatchDirectories(nitro, extendDirs = []) {
67
+ const watchDirs = [];
68
+ switch (nitro.options.framework.name) {
69
+ case "nuxt": {
70
+ watchDirs.push(nitro.graphql.clientDir);
71
+ const layerServerDirs = nitro.options.graphql?.layerServerDirs || [];
72
+ const layerAppDirs = nitro.options.graphql?.layerAppDirs || [];
73
+ for (const layerServerDir of layerServerDirs) watchDirs.push(join(layerServerDir, "graphql"));
74
+ for (const layerAppDir of layerAppDirs) watchDirs.push(join(layerAppDir, "graphql"));
75
+ break;
76
+ }
77
+ case "nitro":
78
+ watchDirs.push(nitro.graphql.clientDir);
79
+ watchDirs.push(nitro.graphql.serverDir);
80
+ break;
81
+ default:
82
+ watchDirs.push(nitro.graphql.clientDir);
83
+ watchDirs.push(nitro.graphql.serverDir);
84
+ }
85
+ for (const dir of extendDirs) if (!watchDirs.includes(dir)) watchDirs.push(dir);
86
+ if (nitro.options.graphql?.externalServices?.length) {
87
+ for (const service of nitro.options.graphql.externalServices) if (service.documents?.length) for (const pattern of service.documents) {
88
+ if (!pattern) continue;
89
+ const baseDir = pattern.split("**")[0]?.replace(/\/$/, "") || ".";
90
+ const resolvedDir = join(nitro.options.rootDir, baseDir);
91
+ if (!watchDirs.includes(resolvedDir)) watchDirs.push(resolvedDir);
92
+ }
93
+ }
94
+ return watchDirs;
95
+ }
96
+
97
+ //#endregion
98
+ export { getWatchDirectories, setupFileWatcher };
@@ -0,0 +1,17 @@
1
+ import { SecurityConfig } from "../types.mjs";
2
+ import { Nitro } from "nitro/types";
3
+
4
+ //#region src/nitro/setup/logging.d.ts
5
+
6
+ /**
7
+ * Resolves security configuration with environment-aware defaults
8
+ * In production: introspection off, playground off, errors masked, suggestions disabled
9
+ * In development: introspection on, playground on, errors shown, suggestions enabled
10
+ */
11
+ declare function resolveSecurityConfig(config?: SecurityConfig): Required<SecurityConfig>;
12
+ /**
13
+ * Log startup information
14
+ */
15
+ declare function logStartupInfo(nitro: Nitro, serverEnabled: boolean): void;
16
+ //#endregion
17
+ export { logStartupInfo, resolveSecurityConfig };
@@ -0,0 +1,66 @@
1
+ import consola from "consola";
2
+
3
+ //#region src/nitro/setup/logging.ts
4
+ /**
5
+ * Resolves security configuration with environment-aware defaults
6
+ * In production: introspection off, playground off, errors masked, suggestions disabled
7
+ * In development: introspection on, playground on, errors shown, suggestions enabled
8
+ */
9
+ function resolveSecurityConfig(config) {
10
+ const isProd = process.env.NODE_ENV === "production";
11
+ return {
12
+ introspection: config?.introspection ?? !isProd,
13
+ playground: config?.playground ?? !isProd,
14
+ maskErrors: config?.maskErrors ?? isProd,
15
+ disableSuggestions: config?.disableSuggestions ?? isProd
16
+ };
17
+ }
18
+ /**
19
+ * Log startup information
20
+ */
21
+ function logStartupInfo(nitro, serverEnabled) {
22
+ const externalServicesCount = nitro.options.graphql?.externalServices?.length || 0;
23
+ const docs = nitro.scanDocuments || [];
24
+ const isProd = process.env.NODE_ENV === "production";
25
+ if (serverEnabled) {
26
+ const securityConfig = resolveSecurityConfig(nitro.options.graphql?.security);
27
+ const framework = nitro.options.graphql?.framework || "unknown";
28
+ const schemas = nitro.scanSchemas?.length || 0;
29
+ const resolvers = nitro.scanResolvers?.length || 0;
30
+ consola.box({
31
+ title: "Nitro GraphQL",
32
+ message: [
33
+ `Framework: ${framework}`,
34
+ `Environment: ${isProd ? "production" : "development"}`,
35
+ `Schemas: ${schemas}`,
36
+ `Resolvers: ${resolvers}`,
37
+ externalServicesCount > 0 ? `External Services: ${externalServicesCount}` : "",
38
+ docs.length > 0 ? `Documents: ${docs.length}` : "",
39
+ "",
40
+ "Security:",
41
+ `├─ Introspection: ${securityConfig.introspection ? "enabled" : "disabled"}`,
42
+ `├─ Playground: ${securityConfig.playground ? "enabled" : "disabled"}`,
43
+ `├─ Error Masking: ${securityConfig.maskErrors ? "enabled" : "disabled"}`,
44
+ `└─ Field Suggestions: ${securityConfig.disableSuggestions ? "disabled" : "enabled"}`
45
+ ].filter(Boolean).join("\n"),
46
+ style: {
47
+ borderColor: isProd ? "yellow" : "cyan",
48
+ borderStyle: "rounded"
49
+ }
50
+ });
51
+ } else consola.box({
52
+ title: "Nitro GraphQL (Client Only)",
53
+ message: [
54
+ "Server mode: disabled",
55
+ `External Services: ${externalServicesCount}`,
56
+ `Documents: ${docs.length}`
57
+ ].join("\n"),
58
+ style: {
59
+ borderColor: "blue",
60
+ borderStyle: "rounded"
61
+ }
62
+ });
63
+ }
64
+
65
+ //#endregion
66
+ export { logStartupInfo, resolveSecurityConfig };
@@ -0,0 +1,16 @@
1
+ import { Nitro } from "nitro/types";
2
+
3
+ //#region src/nitro/setup/rollup-integration.d.ts
4
+
5
+ /**
6
+ * Setup Rollup/Rolldown chunking configuration for GraphQL files
7
+ * Creates separate chunks for schemas and resolvers to optimize bundle size
8
+ */
9
+ declare function setupRollupChunking(nitro: Nitro): void;
10
+ /**
11
+ * Configure external dependencies for Rollup
12
+ * Marks codegen and federation packages as external
13
+ */
14
+ declare function setupRollupExternals(nitro: Nitro): void;
15
+ //#endregion
16
+ export { setupRollupChunking, setupRollupExternals };