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

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 (162) hide show
  1. package/README.md +441 -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/core/codegen/client.d.mts +23 -0
  17. package/dist/core/codegen/client.mjs +150 -0
  18. package/dist/core/codegen/document-loader.d.mts +10 -0
  19. package/dist/core/codegen/document-loader.mjs +18 -0
  20. package/dist/core/codegen/index.d.mts +8 -0
  21. package/dist/core/codegen/index.mjs +9 -0
  22. package/dist/core/codegen/plugin.d.mts +20 -0
  23. package/dist/core/codegen/plugin.mjs +30 -0
  24. package/dist/core/codegen/runtime.d.mts +20 -0
  25. package/dist/core/codegen/runtime.mjs +60 -0
  26. package/dist/core/codegen/schema-loader.d.mts +28 -0
  27. package/dist/core/codegen/schema-loader.mjs +128 -0
  28. package/dist/core/codegen/server.d.mts +28 -0
  29. package/dist/core/codegen/server.mjs +143 -0
  30. package/dist/core/codegen/validation.d.mts +13 -0
  31. package/dist/core/codegen/validation.mjs +96 -0
  32. package/dist/core/config.d.mts +50 -0
  33. package/dist/core/config.mjs +82 -0
  34. package/dist/core/constants.d.mts +188 -0
  35. package/dist/core/constants.mjs +210 -0
  36. package/dist/core/index.d.mts +32 -0
  37. package/dist/core/index.mjs +26 -0
  38. package/dist/core/scanning/ast-scanner.d.mts +23 -0
  39. package/dist/core/scanning/ast-scanner.mjs +103 -0
  40. package/dist/core/scanning/common.d.mts +37 -0
  41. package/dist/core/scanning/common.mjs +60 -0
  42. package/dist/core/scanning/directives.d.mts +10 -0
  43. package/dist/core/scanning/directives.mjs +29 -0
  44. package/dist/core/scanning/documents.d.mts +21 -0
  45. package/dist/core/scanning/documents.mjs +43 -0
  46. package/dist/core/scanning/index.d.mts +7 -0
  47. package/dist/core/scanning/index.mjs +8 -0
  48. package/dist/core/scanning/resolvers.d.mts +10 -0
  49. package/dist/core/scanning/resolvers.mjs +58 -0
  50. package/dist/core/scanning/schemas.d.mts +14 -0
  51. package/dist/core/scanning/schemas.mjs +64 -0
  52. package/dist/core/schema/builder.d.mts +53 -0
  53. package/dist/core/schema/builder.mjs +70 -0
  54. package/dist/core/schema/federation.d.mts +34 -0
  55. package/dist/core/schema/federation.mjs +40 -0
  56. package/dist/core/schema/index.d.mts +3 -0
  57. package/dist/core/schema/index.mjs +4 -0
  58. package/dist/core/types/adapter.d.mts +58 -0
  59. package/dist/core/types/codegen.d.mts +133 -0
  60. package/dist/core/types/config.d.mts +212 -0
  61. package/dist/core/types/config.mjs +1 -0
  62. package/dist/{utils/define.d.ts → core/types/define.d.mts} +3 -30
  63. package/dist/core/types/define.mjs +1 -0
  64. package/dist/core/types/index.d.mts +5 -0
  65. package/dist/core/types/index.mjs +1 -0
  66. package/dist/core/types/scanning.d.mts +69 -0
  67. package/dist/core/types/scanning.mjs +1 -0
  68. package/dist/{utils/directive-parser.d.ts → core/utils/directive-parser.d.mts} +21 -4
  69. package/dist/{utils/directive-parser.js → core/utils/directive-parser.mjs} +25 -34
  70. package/dist/core/utils/errors.d.mts +77 -0
  71. package/dist/core/utils/errors.mjs +93 -0
  72. package/dist/core/utils/file-io.d.mts +24 -0
  73. package/dist/core/utils/file-io.mjs +47 -0
  74. package/dist/core/utils/imports.d.mts +15 -0
  75. package/dist/core/utils/imports.mjs +25 -0
  76. package/dist/core/utils/index.d.mts +7 -0
  77. package/dist/core/utils/index.mjs +8 -0
  78. package/dist/core/utils/logger.d.mts +19 -0
  79. package/dist/core/utils/logger.mjs +38 -0
  80. package/dist/core/utils/ofetch-templates.d.mts +30 -0
  81. package/dist/core/utils/ofetch-templates.mjs +135 -0
  82. package/dist/core/validation/external-services.d.mts +11 -0
  83. package/dist/core/validation/external-services.mjs +34 -0
  84. package/dist/core/validation/index.d.mts +2 -0
  85. package/dist/core/validation/index.mjs +3 -0
  86. package/dist/define.d.mts +294 -0
  87. package/dist/define.mjs +323 -0
  88. package/dist/index.d.mts +6 -0
  89. package/dist/index.mjs +6 -0
  90. package/dist/nitro/adapter.d.mts +30 -0
  91. package/dist/nitro/adapter.mjs +97 -0
  92. package/dist/{utils/apollo.d.ts → nitro/apollo.d.mts} +3 -3
  93. package/dist/nitro/apollo.mjs +59 -0
  94. package/dist/nitro/codegen.d.mts +19 -0
  95. package/dist/nitro/codegen.mjs +141 -0
  96. package/dist/nitro/config.d.mts +52 -0
  97. package/dist/nitro/config.mjs +58 -0
  98. package/dist/nitro/index.d.mts +46 -0
  99. package/dist/nitro/index.mjs +65 -0
  100. package/dist/nitro/paths.d.mts +54 -0
  101. package/dist/nitro/paths.mjs +93 -0
  102. package/dist/nitro/rollup.d.mts +6 -0
  103. package/dist/nitro/rollup.mjs +95 -0
  104. package/dist/nitro/routes/apollo-server.d.mts +6 -0
  105. package/dist/nitro/routes/apollo-server.mjs +71 -0
  106. package/dist/nitro/routes/debug-template.d.mts +15 -0
  107. package/dist/nitro/routes/debug-template.mjs +385 -0
  108. package/dist/nitro/routes/debug.d.mts +55 -0
  109. package/dist/nitro/routes/debug.mjs +102 -0
  110. package/dist/nitro/routes/graphql-yoga.d.mts +6 -0
  111. package/dist/nitro/routes/graphql-yoga.mjs +62 -0
  112. package/dist/nitro/routes/health.d.mts +10 -0
  113. package/dist/{routes/health.js → nitro/routes/health.mjs} +4 -3
  114. package/dist/nitro/setup/file-watcher.d.mts +16 -0
  115. package/dist/nitro/setup/file-watcher.mjs +80 -0
  116. package/dist/nitro/setup/logging.d.mts +17 -0
  117. package/dist/nitro/setup/logging.mjs +66 -0
  118. package/dist/nitro/setup/rollup-integration.d.mts +16 -0
  119. package/dist/nitro/setup/rollup-integration.mjs +90 -0
  120. package/dist/nitro/setup/routes.d.mts +10 -0
  121. package/dist/nitro/setup/routes.mjs +35 -0
  122. package/dist/nitro/setup/ts-config.d.mts +11 -0
  123. package/dist/nitro/setup/ts-config.mjs +69 -0
  124. package/dist/nitro/setup.d.mts +12 -0
  125. package/dist/nitro/setup.mjs +231 -0
  126. package/dist/nitro/types.d.mts +378 -0
  127. package/dist/nitro/types.mjs +1 -0
  128. package/dist/nitro/virtual/generators.d.mts +31 -0
  129. package/dist/nitro/virtual/generators.mjs +193 -0
  130. package/dist/nitro/virtual/stubs.d.mts +20 -0
  131. package/dist/nitro/virtual/stubs.mjs +31 -0
  132. package/dist/{ecosystem/nuxt.d.ts → nuxt.d.mts} +1 -1
  133. package/dist/nuxt.mjs +109 -0
  134. package/dist/{graphql/server.d.ts → stubs/index.d.mts} +5 -1
  135. package/dist/stubs/index.mjs +1 -0
  136. package/package.json +97 -78
  137. package/dist/ecosystem/nuxt.js +0 -67
  138. package/dist/graphql/index.d.ts +0 -5
  139. package/dist/index.d.ts +0 -8
  140. package/dist/index.js +0 -264
  141. package/dist/rollup.js +0 -119
  142. package/dist/routes/apollo-server.d.ts +0 -6
  143. package/dist/routes/apollo-server.js +0 -89
  144. package/dist/routes/graphql-yoga.d.ts +0 -6
  145. package/dist/routes/graphql-yoga.js +0 -91
  146. package/dist/routes/health.d.ts +0 -6
  147. package/dist/types/index.d.ts +0 -128
  148. package/dist/types/standard-schema.d.ts +0 -59
  149. package/dist/utils/apollo.js +0 -61
  150. package/dist/utils/client-codegen.d.ts +0 -38
  151. package/dist/utils/client-codegen.js +0 -290
  152. package/dist/utils/define.js +0 -57
  153. package/dist/utils/index.d.ts +0 -39
  154. package/dist/utils/index.js +0 -250
  155. package/dist/utils/server-codegen.d.ts +0 -7
  156. package/dist/utils/server-codegen.js +0 -136
  157. package/dist/utils/type-generation.d.ts +0 -7
  158. package/dist/utils/type-generation.js +0 -287
  159. package/dist/vite.d.ts +0 -25
  160. package/dist/vite.js +0 -40
  161. /package/dist/{graphql/index.js → core/types/adapter.mjs} +0 -0
  162. /package/dist/{graphql/server.js → core/types/codegen.mjs} +0 -0
@@ -0,0 +1,55 @@
1
+ import * as nitro_deps_h35 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_h35.EventHandlerWithFetch<nitro_deps_h35.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,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): string[];
15
+ //#endregion
16
+ export { getWatchDirectories, setupFileWatcher };
@@ -0,0 +1,80 @@
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 consola from "consola";
7
+ import { join } from "pathe";
8
+ import { watch } from "chokidar";
9
+
10
+ //#region src/nitro/setup/file-watcher.ts
11
+ const logger = consola.withTag(LOG_TAG);
12
+ /**
13
+ * Setup file watcher for GraphQL files (schemas, resolvers, directives, documents)
14
+ * Watches for changes and triggers type regeneration and dev server reload
15
+ */
16
+ function setupFileWatcher(nitro, watchDirs) {
17
+ const watcher = watch(watchDirs, {
18
+ persistent: DEFAULT_WATCHER_PERSISTENT,
19
+ ignoreInitial: DEFAULT_WATCHER_IGNORE_INITIAL,
20
+ ignored: nitro.options.ignore
21
+ });
22
+ watcher.on("all", async (_, path) => {
23
+ const isGraphQLFile = GRAPHQL_EXTENSIONS.some((ext) => path.endsWith(ext));
24
+ const isResolverFile = RESOLVER_EXTENSIONS.some((ext) => path.endsWith(ext));
25
+ const isDirectiveFile = DIRECTIVE_EXTENSIONS.some((ext) => path.endsWith(ext));
26
+ if (isGraphQLFile || isResolverFile || isDirectiveFile) if (path.includes(nitro.graphql.serverDir) || path.includes(DIR_SERVER_GRAPHQL) || path.includes(DIR_SERVER_GRAPHQL_WIN) || isResolverFile || isDirectiveFile) {
27
+ const directivesResult = await NitroAdapter.scanDirectives(nitro);
28
+ nitro.scanDirectives = directivesResult.items;
29
+ if (!nitro.scanSchemas) nitro.scanSchemas = [];
30
+ const directivesPath = await generateDirectiveSchemas(nitro, directivesResult.items);
31
+ const schemas = (await NitroAdapter.scanSchemas(nitro)).items;
32
+ if (directivesPath && !schemas.includes(directivesPath)) schemas.push(directivesPath);
33
+ nitro.scanSchemas = schemas;
34
+ nitro.scanResolvers = (await NitroAdapter.scanResolvers(nitro)).items;
35
+ logger.success("Types regenerated");
36
+ await generateServerTypes(nitro, { silent: true });
37
+ await generateClientTypes(nitro, { silent: true });
38
+ await nitro.hooks.callHook("dev:reload");
39
+ } else {
40
+ logger.success("Types regenerated");
41
+ await generateClientTypes(nitro, { silent: true });
42
+ }
43
+ });
44
+ return watcher;
45
+ }
46
+ /**
47
+ * Determine which directories to watch based on framework and configuration
48
+ */
49
+ function getWatchDirectories(nitro) {
50
+ const watchDirs = [];
51
+ switch (nitro.options.framework.name) {
52
+ case "nuxt": {
53
+ watchDirs.push(nitro.graphql.clientDir);
54
+ const layerServerDirs = nitro.options.graphql?.layerServerDirs || [];
55
+ const layerAppDirs = nitro.options.graphql?.layerAppDirs || [];
56
+ for (const layerServerDir of layerServerDirs) watchDirs.push(join(layerServerDir, "graphql"));
57
+ for (const layerAppDir of layerAppDirs) watchDirs.push(join(layerAppDir, "graphql"));
58
+ break;
59
+ }
60
+ case "nitro":
61
+ watchDirs.push(nitro.graphql.clientDir);
62
+ watchDirs.push(nitro.graphql.serverDir);
63
+ break;
64
+ default:
65
+ watchDirs.push(nitro.graphql.clientDir);
66
+ watchDirs.push(nitro.graphql.serverDir);
67
+ }
68
+ if (nitro.options.graphql?.externalServices?.length) {
69
+ for (const service of nitro.options.graphql.externalServices) if (service.documents?.length) for (const pattern of service.documents) {
70
+ if (!pattern) continue;
71
+ const baseDir = pattern.split("**")[0]?.replace(/\/$/, "") || ".";
72
+ const resolvedDir = join(nitro.options.rootDir, baseDir);
73
+ if (!watchDirs.includes(resolvedDir)) watchDirs.push(resolvedDir);
74
+ }
75
+ }
76
+ return watchDirs;
77
+ }
78
+
79
+ //#endregion
80
+ 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 };
@@ -0,0 +1,90 @@
1
+ import { CHUNK_NAME_RESOLVERS, CHUNK_NAME_SCHEMAS, CHUNK_PATH_GRAPHQL, CHUNK_PATH_UNKNOWN, GRAPHQL_EXTENSIONS, RESOLVER_EXTENSIONS } from "../../core/constants.mjs";
2
+
3
+ //#region src/nitro/setup/rollup-integration.ts
4
+ /**
5
+ * Setup Rollup/Rolldown chunking configuration for GraphQL files
6
+ * Creates separate chunks for schemas and resolvers to optimize bundle size
7
+ */
8
+ function setupRollupChunking(nitro) {
9
+ nitro.hooks.hook("rollup:before", (_, rollupConfig) => {
10
+ const manualChunks = rollupConfig.output?.manualChunks;
11
+ const chunkFiles = rollupConfig.output?.chunkFileNames;
12
+ if (!rollupConfig.output.inlineDynamicImports) {
13
+ rollupConfig.output.manualChunks = (id, _meta) => {
14
+ if (isGraphQLFile(id)) return getSchemaChunkName(id);
15
+ if (isResolverFile(id)) return getResolverChunkName(id);
16
+ if (typeof manualChunks === "function") return manualChunks(id, meta);
17
+ };
18
+ rollupConfig.output.advancedChunks = {
19
+ groups: [{
20
+ name: CHUNK_NAME_SCHEMAS,
21
+ test: /* @__PURE__ */ new RegExp(`\\.(${GRAPHQL_EXTENSIONS.map((e) => e.slice(1)).join("|")})$`)
22
+ }, {
23
+ name: CHUNK_NAME_RESOLVERS,
24
+ test: /\.resolver\.(ts|js)$/
25
+ }],
26
+ minSize: 0,
27
+ minShareCount: 1
28
+ };
29
+ }
30
+ rollupConfig.output.chunkFileNames = (chunkInfo) => {
31
+ if (chunkInfo.moduleIds && chunkInfo.moduleIds.some((id) => isGraphQLFile(id) || isResolverFile(id))) return CHUNK_PATH_GRAPHQL;
32
+ if (typeof chunkFiles === "function") return chunkFiles(chunkInfo);
33
+ return CHUNK_PATH_UNKNOWN;
34
+ };
35
+ });
36
+ }
37
+ /**
38
+ * Check if a file is a GraphQL schema file
39
+ */
40
+ function isGraphQLFile(id) {
41
+ return GRAPHQL_EXTENSIONS.some((ext) => id.endsWith(ext));
42
+ }
43
+ /**
44
+ * Check if a file is a resolver file
45
+ */
46
+ function isResolverFile(id) {
47
+ return RESOLVER_EXTENSIONS.some((ext) => id.endsWith(ext));
48
+ }
49
+ /**
50
+ * Get chunk name for GraphQL schema files
51
+ * All schemas are bundled into a single chunk since GraphQL server
52
+ * merges them at runtime anyway - no benefit from separate chunks
53
+ */
54
+ function getSchemaChunkName(_id) {
55
+ return CHUNK_NAME_SCHEMAS;
56
+ }
57
+ /**
58
+ * Get chunk name for resolver files
59
+ * All resolvers are bundled into a single chunk since GraphQL server
60
+ * requires all resolvers to be registered at startup - no runtime lazy loading
61
+ */
62
+ function getResolverChunkName(_id) {
63
+ return CHUNK_NAME_RESOLVERS;
64
+ }
65
+ /**
66
+ * Configure external dependencies for Rollup
67
+ * Marks codegen and federation packages as external
68
+ */
69
+ function setupRollupExternals(nitro) {
70
+ nitro.hooks.hook("rollup:before", (_, rollupConfig) => {
71
+ rollupConfig.external = rollupConfig.external || [];
72
+ const allExternals = [...["oxc-parser", "@oxc-parser"]];
73
+ if (!nitro.options.graphql?.federation?.enabled) allExternals.push(...[
74
+ "@apollo/subgraph",
75
+ "@apollo/federation-internals",
76
+ "@apollo/cache-control-types"
77
+ ]);
78
+ if (Array.isArray(rollupConfig.external)) rollupConfig.external.push(...allExternals);
79
+ else if (typeof rollupConfig.external === "function") {
80
+ const originalExternal = rollupConfig.external;
81
+ rollupConfig.external = (id, parent, isResolved) => {
82
+ if (allExternals.some((external) => id.includes(external))) return true;
83
+ return originalExternal(id, parent, isResolved);
84
+ };
85
+ }
86
+ });
87
+ }
88
+
89
+ //#endregion
90
+ export { setupRollupChunking, setupRollupExternals };
@@ -0,0 +1,10 @@
1
+ import { Nitro } from "nitro/types";
2
+
3
+ //#region src/nitro/setup/routes.d.ts
4
+
5
+ /**
6
+ * Register GraphQL route handlers
7
+ */
8
+ declare function registerRouteHandlers(nitro: Nitro): void;
9
+ //#endregion
10
+ export { registerRouteHandlers };
@@ -0,0 +1,35 @@
1
+ import { ENDPOINT_DEBUG, GRAPHQL_HTTP_METHODS } from "../../core/constants.mjs";
2
+ import { join } from "pathe";
3
+ import { fileURLToPath } from "node:url";
4
+
5
+ //#region src/nitro/setup/routes.ts
6
+ /**
7
+ * Register GraphQL route handlers
8
+ */
9
+ function registerRouteHandlers(nitro) {
10
+ const runtime = fileURLToPath(new URL("../routes", import.meta.url));
11
+ const framework = nitro.options.graphql?.framework;
12
+ if (framework === "graphql-yoga") for (const method of GRAPHQL_HTTP_METHODS) nitro.options.handlers.push({
13
+ route: nitro.options.runtimeConfig.graphql?.endpoint?.graphql || "/api/graphql",
14
+ handler: join(runtime, "graphql-yoga"),
15
+ method
16
+ });
17
+ if (framework === "apollo-server") for (const method of GRAPHQL_HTTP_METHODS) nitro.options.handlers.push({
18
+ route: nitro.options.runtimeConfig.graphql?.endpoint?.graphql || "/api/graphql",
19
+ handler: join(runtime, "apollo-server"),
20
+ method
21
+ });
22
+ nitro.options.handlers.push({
23
+ route: nitro.options.runtimeConfig.graphql?.endpoint?.healthCheck || "/api/graphql/health",
24
+ handler: join(runtime, "health"),
25
+ method: "GET"
26
+ });
27
+ if (nitro.options.dev) nitro.options.handlers.push({
28
+ route: ENDPOINT_DEBUG,
29
+ handler: join(runtime, "debug"),
30
+ method: "GET"
31
+ });
32
+ }
33
+
34
+ //#endregion
35
+ export { registerRouteHandlers };
@@ -0,0 +1,11 @@
1
+ import { Nitro, NitroTypes } from "nitro/types";
2
+
3
+ //#region src/nitro/setup/ts-config.d.ts
4
+
5
+ /**
6
+ * Setup TypeScript path aliases for GraphQL types
7
+ * Called via nitro:config hook to extend tsconfig.json
8
+ */
9
+ declare function setupTypeScriptPaths(nitro: Nitro, types: NitroTypes): void;
10
+ //#endregion
11
+ export { setupTypeScriptPaths };
@@ -0,0 +1,69 @@
1
+ import { relativeWithDot } from "../../core/utils/imports.mjs";
2
+ import { getDefaultPaths, getTypesConfig, resolveFilePath } from "../paths.mjs";
3
+ import { dirname, join, resolve } from "pathe";
4
+
5
+ //#region src/nitro/setup/ts-config.ts
6
+ /**
7
+ * Setup TypeScript path aliases for GraphQL types
8
+ * Called via nitro:config hook to extend tsconfig.json
9
+ */
10
+ function setupTypeScriptPaths(nitro, types) {
11
+ const tsconfigDir = dirname(resolve(nitro.options.buildDir, nitro.options.typescript.tsconfigPath));
12
+ types.tsConfig ||= {};
13
+ types.tsConfig.compilerOptions ??= {};
14
+ types.tsConfig.compilerOptions.paths ??= {};
15
+ types.tsConfig.include = types.tsConfig.include || [];
16
+ const placeholders = getDefaultPaths(nitro);
17
+ const typesConfig = getTypesConfig(nitro);
18
+ setupServerTypesPath(nitro, types, tsconfigDir, placeholders, typesConfig);
19
+ setupClientTypesPath(nitro, types, tsconfigDir, placeholders, typesConfig);
20
+ setupSchemaPath(nitro, types, tsconfigDir);
21
+ setupExternalServicePaths(nitro, types, tsconfigDir, placeholders, typesConfig);
22
+ types.tsConfig.include.push(relativeWithDot(tsconfigDir, join(placeholders.typesDir, "graphql.d.ts")));
23
+ }
24
+ /**
25
+ * Setup #graphql/server path alias
26
+ */
27
+ function setupServerTypesPath(nitro, types, tsconfigDir, placeholders, typesConfig) {
28
+ const serverTypesPath = resolveFilePath(typesConfig.server, typesConfig.enabled, true, "{typesDir}/nitro-graphql-server.d.ts", placeholders);
29
+ if (serverTypesPath) {
30
+ types.tsConfig.compilerOptions.paths["#graphql/server"] = [relativeWithDot(tsconfigDir, serverTypesPath)];
31
+ types.tsConfig.include.push(relativeWithDot(tsconfigDir, serverTypesPath));
32
+ }
33
+ }
34
+ /**
35
+ * Setup #graphql/client path alias
36
+ */
37
+ function setupClientTypesPath(nitro, types, tsconfigDir, placeholders, typesConfig) {
38
+ const clientTypesPath = resolveFilePath(typesConfig.client, typesConfig.enabled, true, "{typesDir}/nitro-graphql-client.d.ts", placeholders);
39
+ if (clientTypesPath) {
40
+ types.tsConfig.compilerOptions.paths["#graphql/client"] = [relativeWithDot(tsconfigDir, clientTypesPath)];
41
+ types.tsConfig.include.push(relativeWithDot(tsconfigDir, clientTypesPath));
42
+ }
43
+ }
44
+ /**
45
+ * Setup #graphql/schema path alias
46
+ */
47
+ function setupSchemaPath(nitro, types, tsconfigDir) {
48
+ types.tsConfig.compilerOptions.paths["#graphql/schema"] = [relativeWithDot(tsconfigDir, join(nitro.graphql.serverDir, "schema.ts"))];
49
+ }
50
+ /**
51
+ * Setup #graphql/client/{serviceName} path aliases for external services
52
+ */
53
+ function setupExternalServicePaths(nitro, types, tsconfigDir, placeholders, typesConfig) {
54
+ if (!nitro.options.graphql?.externalServices?.length) return;
55
+ for (const service of nitro.options.graphql.externalServices) {
56
+ const servicePlaceholders = {
57
+ ...placeholders,
58
+ serviceName: service.name
59
+ };
60
+ const externalTypesPath = resolveFilePath(service.paths?.types ?? typesConfig.external, typesConfig.enabled, true, "{typesDir}/nitro-graphql-client-{serviceName}.d.ts", servicePlaceholders);
61
+ if (externalTypesPath) {
62
+ types.tsConfig.compilerOptions.paths[`#graphql/client/${service.name}`] = [relativeWithDot(tsconfigDir, externalTypesPath)];
63
+ types.tsConfig.include.push(relativeWithDot(tsconfigDir, externalTypesPath));
64
+ }
65
+ }
66
+ }
67
+
68
+ //#endregion
69
+ export { setupTypeScriptPaths };