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,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 };
@@ -0,0 +1,12 @@
1
+ import { resolveSecurityConfig } from "./setup/logging.mjs";
2
+ import { Nitro } from "nitro/types";
3
+
4
+ //#region src/nitro/setup.d.ts
5
+
6
+ /**
7
+ * Main setup function for nitro-graphql
8
+ * Coordinates all initialization steps for the module
9
+ */
10
+ declare function setupNitroGraphQL(nitro: Nitro): Promise<void>;
11
+ //#endregion
12
+ export { resolveSecurityConfig, setupNitroGraphQL };
@@ -0,0 +1,234 @@
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";
8
+ import { rollupConfig } from "./rollup.mjs";
9
+ import { resolveExtendConfig, resolveExtendDirs } from "./setup/extend-loader.mjs";
10
+ import { getWatchDirectories, setupFileWatcher } from "./setup/file-watcher.mjs";
11
+ import { logStartupInfo, resolveSecurityConfig } from "./setup/logging.mjs";
12
+ import { setupRollupChunking, setupRollupExternals } from "./setup/rollup-integration.mjs";
13
+ import { registerRouteHandlers } from "./setup/routes.mjs";
14
+ import { setupTypeScriptPaths } from "./setup/ts-config.mjs";
15
+ import defu from "defu";
16
+ import consola from "consola";
17
+ import { relative, resolve } from "pathe";
18
+
19
+ //#region src/nitro/setup.ts
20
+ const logger = consola.withTag(LOG_TAG);
21
+ /**
22
+ * Scan all GraphQL files and update Nitro state
23
+ */
24
+ async function scanAllGraphQLFiles(nitro) {
25
+ const directivesResult = await NitroAdapter.scanDirectives(nitro);
26
+ nitro.scanDirectives = directivesResult.items;
27
+ if (!nitro.scanSchemas) nitro.scanSchemas = [];
28
+ const directivesPath = await generateDirectiveSchemas(nitro, directivesResult.items);
29
+ const schemas = (await NitroAdapter.scanSchemas(nitro)).items;
30
+ if (directivesPath && !schemas.includes(directivesPath)) schemas.push(directivesPath);
31
+ nitro.scanSchemas = schemas;
32
+ nitro.scanDocuments = (await NitroAdapter.scanDocuments(nitro)).items;
33
+ nitro.scanResolvers = (await NitroAdapter.scanResolvers(nitro)).items;
34
+ }
35
+ /**
36
+ * Main setup function for nitro-graphql
37
+ * Coordinates all initialization steps for the module
38
+ */
39
+ async function setupNitroGraphQL(nitro) {
40
+ const serverEnabled = nitro.options.graphql?.server !== false;
41
+ initializeConfiguration(nitro, serverEnabled);
42
+ validateConfiguration(nitro);
43
+ setupBuildDirectories(nitro);
44
+ if (serverEnabled) {
45
+ setupRollupExternals(nitro);
46
+ setupRollupChunking(nitro);
47
+ }
48
+ initializeRuntimeConfig(nitro);
49
+ setupFileWatching(nitro, serverEnabled, await resolveExtendDirs(nitro));
50
+ await scanGraphQLFiles(nitro, serverEnabled);
51
+ await resolveExtendConfig(nitro);
52
+ if (serverEnabled) setupDevHooks(nitro);
53
+ if (serverEnabled) await rollupConfig(nitro);
54
+ await generateTypes(nitro, serverEnabled);
55
+ setupCloseHooks(nitro, serverEnabled);
56
+ if (serverEnabled) registerRouteHandlers(nitro);
57
+ setupTypeScriptConfiguration(nitro);
58
+ setupNuxtIntegration(nitro);
59
+ logStartupInfo(nitro, serverEnabled);
60
+ }
61
+ /**
62
+ * Initialize default configuration values
63
+ */
64
+ function initializeConfiguration(nitro, serverEnabled) {
65
+ nitro.options.graphql ||= {};
66
+ nitro.options.graphql.types = defu(nitro.options.graphql.types, DEFAULT_TYPES_CONFIG);
67
+ if (serverEnabled && !nitro.options.graphql?.framework) logger.warn("No GraphQL framework specified. Please set graphql.framework to \"graphql-yoga\" or \"apollo-server\".");
68
+ const defaultPaths = getDefaultPaths(nitro);
69
+ nitro.graphql ||= {
70
+ buildDir: "",
71
+ watchDirs: [],
72
+ clientDir: defaultPaths.clientDir,
73
+ serverDir: defaultPaths.serverDir,
74
+ dir: {
75
+ build: relative(nitro.options.rootDir, nitro.options.buildDir),
76
+ client: "graphql",
77
+ server: "server"
78
+ }
79
+ };
80
+ nitro.scanSchemas ||= [];
81
+ nitro.scanResolvers ||= [];
82
+ nitro.scanDirectives ||= [];
83
+ nitro.scanDocuments ||= [];
84
+ }
85
+ /**
86
+ * Validate external services configuration
87
+ */
88
+ function validateConfiguration(nitro) {
89
+ if (nitro.options.graphql?.externalServices?.length) {
90
+ const validationErrors = validateExternalServices(nitro.options.graphql.externalServices);
91
+ if (validationErrors.length > 0) {
92
+ logger.error("External services configuration errors:");
93
+ for (const error of validationErrors) logger.error(` - ${error}`);
94
+ throw new Error("Invalid external services configuration");
95
+ }
96
+ logger.info(`Configured ${nitro.options.graphql.externalServices.length} external GraphQL services`);
97
+ }
98
+ if (nitro.options.graphql?.federation?.enabled) logger.info(`Apollo Federation enabled for service: ${nitro.options.graphql.federation.serviceName || "unnamed"}`);
99
+ }
100
+ /**
101
+ * Setup build directories
102
+ */
103
+ function setupBuildDirectories(nitro) {
104
+ const graphqlBuildDir = resolve(nitro.options.buildDir, "graphql");
105
+ nitro.graphql.buildDir = graphqlBuildDir;
106
+ switch (nitro.options.framework.name) {
107
+ case FRAMEWORK_NUXT:
108
+ nitro.graphql.dir.client = relative(nitro.options.rootDir, nitro.graphql.clientDir);
109
+ nitro.graphql.dir.server = relative(nitro.options.rootDir, nitro.graphql.serverDir);
110
+ break;
111
+ case FRAMEWORK_NITRO:
112
+ nitro.graphql.dir.client = relative(nitro.options.rootDir, nitro.graphql.clientDir);
113
+ nitro.graphql.dir.server = relative(nitro.options.rootDir, nitro.graphql.serverDir);
114
+ break;
115
+ default: break;
116
+ }
117
+ }
118
+ /**
119
+ * Initialize runtime configuration
120
+ */
121
+ function initializeRuntimeConfig(nitro) {
122
+ const securityConfig = resolveSecurityConfig(nitro.options.graphql?.security);
123
+ nitro.options.runtimeConfig.graphql = defu(nitro.options.runtimeConfig.graphql || {}, {
124
+ ...DEFAULT_RUNTIME_CONFIG,
125
+ security: securityConfig
126
+ });
127
+ }
128
+ /**
129
+ * Setup file watching for development mode
130
+ */
131
+ function setupFileWatching(nitro, serverEnabled, extendDirs = []) {
132
+ const watchDirs = serverEnabled ? getWatchDirectories(nitro, extendDirs) : [nitro.graphql.clientDir].filter(Boolean);
133
+ nitro.graphql.watchDirs = watchDirs;
134
+ const watcher = setupFileWatcher(nitro, watchDirs);
135
+ nitro.hooks.hook("close", () => {
136
+ watcher.close();
137
+ });
138
+ }
139
+ /**
140
+ * Scan all GraphQL files (schemas, resolvers, directives, documents)
141
+ */
142
+ async function scanGraphQLFiles(nitro, serverEnabled) {
143
+ const skipLocalScan = nitro.options.graphql?.skipLocalScan === true;
144
+ const extendSources = nitro.options.graphql?.extend;
145
+ if (skipLocalScan && extendSources?.length) {
146
+ logger.info(`Using ${extendSources.length} extend source(s), skipping local scanning`);
147
+ nitro.scanSchemas = [];
148
+ nitro.scanResolvers = [];
149
+ nitro.scanDirectives = [];
150
+ nitro.scanDocuments = (await NitroAdapter.scanDocuments(nitro)).items;
151
+ return;
152
+ }
153
+ if (serverEnabled) await scanAllGraphQLFiles(nitro);
154
+ else nitro.scanDocuments = (await NitroAdapter.scanDocuments(nitro)).items;
155
+ }
156
+ /**
157
+ * Setup dev mode hooks for rescanning files
158
+ */
159
+ function setupDevHooks(nitro) {
160
+ let hasShownInitialLogs = false;
161
+ nitro.hooks.hook("dev:start", async () => {
162
+ await scanAllGraphQLFiles(nitro);
163
+ await resolveExtendConfig(nitro);
164
+ if (nitro.options.dev && !hasShownInitialLogs) {
165
+ hasShownInitialLogs = true;
166
+ logResolverDiagnostics(nitro);
167
+ }
168
+ });
169
+ }
170
+ /**
171
+ * Log resolver diagnostics for development
172
+ */
173
+ function logResolverDiagnostics(nitro) {
174
+ const resolvers = nitro.scanResolvers || [];
175
+ if (resolvers.length > 0) {
176
+ const totalExports = resolvers.reduce((sum, r) => sum + r.imports.length, 0);
177
+ const typeCount = {
178
+ query: 0,
179
+ mutation: 0,
180
+ resolver: 0,
181
+ type: 0,
182
+ subscription: 0,
183
+ directive: 0
184
+ };
185
+ for (const resolver of resolvers) for (const imp of resolver.imports) if (imp.type in typeCount) typeCount[imp.type]++;
186
+ const breakdown = [];
187
+ if (typeCount.query > 0) breakdown.push(`${typeCount.query} query`);
188
+ if (typeCount.mutation > 0) breakdown.push(`${typeCount.mutation} mutation`);
189
+ if (typeCount.resolver > 0) breakdown.push(`${typeCount.resolver} resolver`);
190
+ if (typeCount.type > 0) breakdown.push(`${typeCount.type} type`);
191
+ if (typeCount.subscription > 0) breakdown.push(`${typeCount.subscription} subscription`);
192
+ if (typeCount.directive > 0) breakdown.push(`${typeCount.directive} directive`);
193
+ if (breakdown.length > 0) logger.success(`${totalExports} resolver export(s): ${breakdown.join(", ")}`);
194
+ } else logger.warn("No resolvers found. Check /_nitro/graphql/debug for details.");
195
+ }
196
+ /**
197
+ * Generate server and client types
198
+ */
199
+ async function generateTypes(nitro, serverEnabled) {
200
+ if (serverEnabled) {
201
+ await generateServerTypes(nitro);
202
+ await generateClientTypes(nitro, { isInitial: true });
203
+ } else await generateClientTypes(nitro, { isInitial: true });
204
+ }
205
+ /**
206
+ * Setup close hooks for final type generation
207
+ */
208
+ function setupCloseHooks(nitro, serverEnabled) {
209
+ nitro.hooks.hook("close", async () => {
210
+ if (serverEnabled) await generateServerTypes(nitro, { silent: true });
211
+ await generateClientTypes(nitro, { silent: true });
212
+ });
213
+ }
214
+ /**
215
+ * Setup TypeScript configuration and path aliases
216
+ */
217
+ function setupTypeScriptConfiguration(nitro) {
218
+ nitro.options.typescript.strict = DEFAULT_TYPESCRIPT_STRICT;
219
+ nitro.hooks.hook("types:extend", (types) => {
220
+ setupTypeScriptPaths(nitro, types);
221
+ });
222
+ }
223
+ /**
224
+ * Setup Nuxt-specific integration
225
+ */
226
+ function setupNuxtIntegration(nitro) {
227
+ if (nitro.options.framework?.name === FRAMEWORK_NUXT && nitro.options.graphql?.externalServices?.length) nitro.hooks.hook("build:before", () => {
228
+ const nuxtOptions = nitro._nuxt?.options;
229
+ if (nuxtOptions) nuxtOptions.nitroGraphqlExternalServices = nitro.options.graphql?.externalServices || [];
230
+ });
231
+ }
232
+
233
+ //#endregion
234
+ export { resolveSecurityConfig, setupNitroGraphQL };