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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (204) hide show
  1. package/dist/cli/commands/generate.d.mts +26 -0
  2. package/dist/cli/commands/generate.mjs +196 -0
  3. package/dist/cli/commands/index.d.mts +4 -0
  4. package/dist/cli/commands/index.mjs +5 -0
  5. package/dist/cli/commands/init.d.mts +12 -0
  6. package/dist/cli/commands/init.mjs +100 -0
  7. package/dist/cli/commands/validate.d.mts +10 -0
  8. package/dist/cli/commands/validate.mjs +69 -0
  9. package/dist/cli/config.d.mts +75 -0
  10. package/dist/cli/config.mjs +20 -0
  11. package/dist/cli/index.d.mts +24 -0
  12. package/dist/cli/index.mjs +219 -0
  13. package/dist/core/codegen/client.d.mts +23 -0
  14. package/dist/core/codegen/client.mjs +150 -0
  15. package/dist/core/codegen/document-loader.d.mts +10 -0
  16. package/dist/core/codegen/document-loader.mjs +18 -0
  17. package/dist/core/codegen/index.d.mts +8 -0
  18. package/dist/core/codegen/index.mjs +9 -0
  19. package/dist/{utils/codegen-plugin.d.mts → core/codegen/plugin.d.mts} +2 -2
  20. package/dist/{utils/codegen-plugin.mjs → core/codegen/plugin.mjs} +1 -1
  21. package/dist/core/codegen/runtime.d.mts +20 -0
  22. package/dist/core/codegen/runtime.mjs +60 -0
  23. package/dist/core/codegen/schema-loader.d.mts +28 -0
  24. package/dist/core/codegen/schema-loader.mjs +128 -0
  25. package/dist/core/codegen/server.d.mts +28 -0
  26. package/dist/core/codegen/server.mjs +143 -0
  27. package/dist/{codegen → core/codegen}/validation.d.mts +1 -1
  28. package/dist/{codegen → core/codegen}/validation.mjs +1 -1
  29. package/dist/core/config.d.mts +50 -0
  30. package/dist/core/config.mjs +82 -0
  31. package/dist/core/constants.d.mts +188 -0
  32. package/dist/core/constants.mjs +210 -0
  33. package/dist/core/index.d.mts +32 -0
  34. package/dist/core/index.mjs +26 -0
  35. package/dist/core/scanning/ast-scanner.d.mts +23 -0
  36. package/dist/core/scanning/ast-scanner.mjs +103 -0
  37. package/dist/core/scanning/common.d.mts +37 -0
  38. package/dist/core/scanning/common.mjs +60 -0
  39. package/dist/core/scanning/directives.d.mts +10 -0
  40. package/dist/core/scanning/directives.mjs +29 -0
  41. package/dist/core/scanning/documents.d.mts +21 -0
  42. package/dist/core/scanning/documents.mjs +43 -0
  43. package/dist/core/scanning/index.d.mts +7 -0
  44. package/dist/core/scanning/index.mjs +8 -0
  45. package/dist/core/scanning/resolvers.d.mts +10 -0
  46. package/dist/core/scanning/resolvers.mjs +58 -0
  47. package/dist/core/scanning/schemas.d.mts +14 -0
  48. package/dist/core/scanning/schemas.mjs +64 -0
  49. package/dist/{utils/schema-builder.d.mts → core/schema/builder.d.mts} +7 -2
  50. package/dist/{utils/schema-builder.mjs → core/schema/builder.mjs} +22 -3
  51. package/dist/{utils → core/schema}/federation.d.mts +10 -5
  52. package/dist/{utils → core/schema}/federation.mjs +1 -1
  53. package/dist/core/schema/index.d.mts +3 -0
  54. package/dist/core/schema/index.mjs +4 -0
  55. package/dist/core/types/adapter.d.mts +58 -0
  56. package/dist/core/types/codegen.d.mts +133 -0
  57. package/dist/core/types/config.d.mts +212 -0
  58. package/dist/{types → core/types}/define.d.mts +3 -7
  59. package/dist/core/types/index.d.mts +5 -0
  60. package/dist/core/types/scanning.d.mts +69 -0
  61. package/dist/core/types/scanning.mjs +1 -0
  62. package/dist/{utils → core/utils}/directive-parser.d.mts +21 -5
  63. package/dist/{utils → core/utils}/directive-parser.mjs +25 -36
  64. package/dist/{utils → core/utils}/errors.d.mts +8 -4
  65. package/dist/{utils → core/utils}/errors.mjs +8 -4
  66. package/dist/core/utils/file-io.d.mts +24 -0
  67. package/dist/core/utils/file-io.mjs +47 -0
  68. package/dist/{utils → core/utils}/imports.d.mts +1 -1
  69. package/dist/{utils → core/utils}/imports.mjs +1 -1
  70. package/dist/core/utils/index.d.mts +7 -0
  71. package/dist/core/utils/index.mjs +8 -0
  72. package/dist/core/utils/logger.d.mts +19 -0
  73. package/dist/core/utils/logger.mjs +38 -0
  74. package/dist/{utils → core/utils}/ofetch-templates.d.mts +1 -1
  75. package/dist/{utils → core/utils}/ofetch-templates.mjs +1 -1
  76. package/dist/core/validation/external-services.d.mts +11 -0
  77. package/dist/{utils/validation.mjs → core/validation/external-services.mjs} +3 -3
  78. package/dist/core/validation/index.d.mts +2 -0
  79. package/dist/core/validation/index.mjs +3 -0
  80. package/dist/define.d.mts +1 -3
  81. package/dist/index.d.mts +6 -43
  82. package/dist/index.mjs +5 -62
  83. package/dist/nitro/adapter.d.mts +30 -0
  84. package/dist/nitro/adapter.mjs +97 -0
  85. package/dist/{utils → nitro}/apollo.d.mts +1 -1
  86. package/dist/{utils → nitro}/apollo.mjs +1 -1
  87. package/dist/nitro/codegen.d.mts +19 -0
  88. package/dist/nitro/codegen.mjs +141 -0
  89. package/dist/nitro/config.d.mts +52 -0
  90. package/dist/nitro/config.mjs +58 -0
  91. package/dist/nitro/index.d.mts +46 -0
  92. package/dist/nitro/index.mjs +65 -0
  93. package/dist/{utils/path-resolver.d.mts → nitro/paths.d.mts} +3 -19
  94. package/dist/{utils/path-resolver.mjs → nitro/paths.mjs} +2 -36
  95. package/dist/{rollup.d.mts → nitro/rollup.d.mts} +1 -1
  96. package/dist/{rollup.mjs → nitro/rollup.mjs} +11 -23
  97. package/dist/{routes → nitro/routes}/apollo-server.d.mts +1 -1
  98. package/dist/nitro/routes/apollo-server.mjs +71 -0
  99. package/dist/{routes → nitro/routes}/debug-template.d.mts +1 -1
  100. package/dist/{routes → nitro/routes}/debug-template.mjs +1 -1
  101. package/dist/{routes → nitro/routes}/debug.d.mts +10 -16
  102. package/dist/{routes → nitro/routes}/debug.mjs +2 -2
  103. package/dist/nitro/routes/graphql-yoga.d.mts +6 -0
  104. package/dist/{routes → nitro/routes}/graphql-yoga.mjs +21 -10
  105. package/dist/nitro/routes/health.d.mts +10 -0
  106. package/dist/{routes → nitro/routes}/health.mjs +1 -1
  107. package/dist/nitro/setup/file-watcher.d.mts +16 -0
  108. package/dist/{setup → nitro/setup}/file-watcher.mjs +14 -18
  109. package/dist/nitro/setup/logging.d.mts +17 -0
  110. package/dist/nitro/setup/logging.mjs +66 -0
  111. package/dist/nitro/setup/rollup-integration.d.mts +16 -0
  112. package/dist/{setup → nitro/setup}/rollup-integration.mjs +2 -2
  113. package/dist/nitro/setup/routes.d.mts +10 -0
  114. package/dist/nitro/setup/routes.mjs +35 -0
  115. package/dist/nitro/setup/ts-config.d.mts +11 -0
  116. package/dist/{setup → nitro/setup}/ts-config.mjs +3 -3
  117. package/dist/{setup.d.mts → nitro/setup.d.mts} +3 -2
  118. package/dist/{setup.mjs → nitro/setup.mjs} +73 -62
  119. package/dist/nitro/types.d.mts +378 -0
  120. package/dist/nitro/types.mjs +1 -0
  121. package/dist/nitro/virtual/generators.d.mts +31 -0
  122. package/dist/nitro/virtual/generators.mjs +193 -0
  123. package/dist/nitro/virtual/stubs.d.mts +20 -0
  124. package/dist/nitro/virtual/stubs.mjs +31 -0
  125. package/dist/{ecosystem/nuxt.d.mts → nuxt.d.mts} +1 -1
  126. package/dist/{ecosystem/nuxt.mjs → nuxt.mjs} +2 -2
  127. package/dist/{graphql/server.d.mts → stubs/index.d.mts} +5 -1
  128. package/dist/stubs/index.mjs +1 -0
  129. package/package.json +45 -43
  130. package/dist/codegen/client-types.d.mts +0 -13
  131. package/dist/codegen/client-types.mjs +0 -131
  132. package/dist/codegen/external-types.d.mts +0 -12
  133. package/dist/codegen/external-types.mjs +0 -88
  134. package/dist/codegen/index.d.mts +0 -18
  135. package/dist/codegen/index.mjs +0 -24
  136. package/dist/codegen/server-types.d.mts +0 -13
  137. package/dist/codegen/server-types.mjs +0 -64
  138. package/dist/config/defaults.mjs +0 -36
  139. package/dist/constants/scalars.mjs +0 -27
  140. package/dist/constants.mjs +0 -106
  141. package/dist/graphql/index.d.mts +0 -5
  142. package/dist/routes/apollo-server.mjs +0 -45
  143. package/dist/routes/graphql-yoga.d.mts +0 -6
  144. package/dist/routes/health.d.mts +0 -10
  145. package/dist/setup/graphql-scanner.mjs +0 -25
  146. package/dist/setup/scaffold-generator.mjs +0 -109
  147. package/dist/types/index.d.mts +0 -246
  148. package/dist/types/standard-schema.d.mts +0 -59
  149. package/dist/utils/client-codegen.d.mts +0 -41
  150. package/dist/utils/client-codegen.mjs +0 -267
  151. package/dist/utils/file-generator.d.mts +0 -37
  152. package/dist/utils/file-generator.mjs +0 -72
  153. package/dist/utils/file-writer.d.mts +0 -35
  154. package/dist/utils/file-writer.mjs +0 -32
  155. package/dist/utils/index.d.mts +0 -13
  156. package/dist/utils/index.mjs +0 -13
  157. package/dist/utils/layers.d.mts +0 -22
  158. package/dist/utils/layers.mjs +0 -28
  159. package/dist/utils/scanning/common.d.mts +0 -23
  160. package/dist/utils/scanning/common.mjs +0 -39
  161. package/dist/utils/scanning/directives.d.mts +0 -11
  162. package/dist/utils/scanning/directives.mjs +0 -43
  163. package/dist/utils/scanning/documents.d.mts +0 -15
  164. package/dist/utils/scanning/documents.mjs +0 -46
  165. package/dist/utils/scanning/index.d.mts +0 -6
  166. package/dist/utils/scanning/index.mjs +0 -7
  167. package/dist/utils/scanning/resolvers.d.mts +0 -11
  168. package/dist/utils/scanning/resolvers.mjs +0 -100
  169. package/dist/utils/scanning/schemas.d.mts +0 -15
  170. package/dist/utils/scanning/schemas.mjs +0 -29
  171. package/dist/utils/server-codegen.d.mts +0 -7
  172. package/dist/utils/server-codegen.mjs +0 -113
  173. package/dist/utils/type-generation.d.mts +0 -6
  174. package/dist/utils/type-generation.mjs +0 -7
  175. package/dist/utils/validation.d.mts +0 -11
  176. package/dist/virtual/debug-info.d.mts +0 -9
  177. package/dist/virtual/debug-info.mjs +0 -26
  178. package/dist/virtual/generators/config.d.mts +0 -22
  179. package/dist/virtual/generators/config.mjs +0 -36
  180. package/dist/virtual/generators/debug.d.mts +0 -14
  181. package/dist/virtual/generators/debug.mjs +0 -53
  182. package/dist/virtual/generators/directives.d.mts +0 -14
  183. package/dist/virtual/generators/directives.mjs +0 -52
  184. package/dist/virtual/generators/index.d.mts +0 -6
  185. package/dist/virtual/generators/index.mjs +0 -7
  186. package/dist/virtual/generators/resolvers.d.mts +0 -14
  187. package/dist/virtual/generators/resolvers.mjs +0 -55
  188. package/dist/virtual/generators/schemas.d.mts +0 -14
  189. package/dist/virtual/generators/schemas.mjs +0 -43
  190. package/dist/virtual/graphql-config.d.mts +0 -9
  191. package/dist/virtual/graphql-config.mjs +0 -10
  192. package/dist/virtual/module-config.d.mts +0 -9
  193. package/dist/virtual/module-config.mjs +0 -10
  194. package/dist/virtual/server-directives.d.mts +0 -11
  195. package/dist/virtual/server-directives.mjs +0 -10
  196. package/dist/virtual/server-resolvers.d.mts +0 -11
  197. package/dist/virtual/server-resolvers.mjs +0 -10
  198. package/dist/virtual/server-schemas.d.mts +0 -11
  199. package/dist/virtual/server-schemas.mjs +0 -10
  200. /package/dist/{graphql/index.mjs → core/types/adapter.mjs} +0 -0
  201. /package/dist/{graphql/server.mjs → core/types/codegen.mjs} +0 -0
  202. /package/dist/{types/define.mjs → core/types/config.mjs} +0 -0
  203. /package/dist/{types/index.mjs → core/types/define.mjs} +0 -0
  204. /package/dist/{types/standard-schema.mjs → core/types/index.mjs} +0 -0
@@ -0,0 +1,71 @@
1
+ import { createMergedSchema } from "../../core/schema/builder.mjs";
2
+ import defu from "defu";
3
+ import { ApolloServer } from "@apollo/server";
4
+ import { defineEventHandler } from "nitro/h3";
5
+ import { importedConfig } from "#nitro-graphql/graphql-config";
6
+ import { moduleConfig } from "#nitro-graphql/module-config";
7
+ import { directives } from "#nitro-graphql/server-directives";
8
+ import { resolvers } from "#nitro-graphql/server-resolvers";
9
+ import { schemas } from "#nitro-graphql/server-schemas";
10
+ import { ApolloServerPluginLandingPageDisabled } from "@apollo/server/plugin/disabled";
11
+ import { ApolloServerPluginLandingPageLocalDefault } from "@apollo/server/plugin/landingPage/default";
12
+ import { startServerAndCreateH3Handler } from "nitro-graphql/apollo";
13
+
14
+ //#region src/nitro/routes/apollo-server.ts
15
+ let apolloServer = null;
16
+ let serverStarted = false;
17
+ async function createApolloServer() {
18
+ if (!apolloServer) {
19
+ const schema = await createMergedSchema({
20
+ schemas,
21
+ resolvers,
22
+ directives,
23
+ moduleConfig
24
+ });
25
+ const securityConfig = moduleConfig.security || {
26
+ introspection: true,
27
+ playground: true,
28
+ maskErrors: false,
29
+ disableSuggestions: false
30
+ };
31
+ const plugins = [];
32
+ if (securityConfig.playground) plugins.push(ApolloServerPluginLandingPageLocalDefault({ embed: true }));
33
+ else plugins.push(ApolloServerPluginLandingPageDisabled());
34
+ const userFacingCodes = [
35
+ "BAD_USER_INPUT",
36
+ "GRAPHQL_VALIDATION_FAILED",
37
+ "UNAUTHENTICATED",
38
+ "FORBIDDEN",
39
+ "BAD_REQUEST"
40
+ ];
41
+ apolloServer = new ApolloServer(defu({
42
+ schema,
43
+ introspection: securityConfig.introspection,
44
+ plugins,
45
+ formatError: securityConfig.maskErrors ? (formattedError, _error) => {
46
+ const code = formattedError?.extensions?.code;
47
+ if (code && userFacingCodes.includes(code)) return formattedError;
48
+ return {
49
+ message: "Internal server error",
50
+ extensions: { code: "INTERNAL_SERVER_ERROR" }
51
+ };
52
+ } : void 0
53
+ }, importedConfig));
54
+ if (!serverStarted) {
55
+ await apolloServer.start();
56
+ serverStarted = true;
57
+ }
58
+ }
59
+ return apolloServer;
60
+ }
61
+ let serverPromise = null;
62
+ var apollo_server_default = defineEventHandler(async (event) => {
63
+ if (!serverPromise) serverPromise = createApolloServer();
64
+ return startServerAndCreateH3Handler(await serverPromise, {
65
+ context: async () => ({ event }),
66
+ serverAlreadyStarted: true
67
+ })(event);
68
+ });
69
+
70
+ //#endregion
71
+ export { apollo_server_default as default };
@@ -1,4 +1,4 @@
1
- //#region src/routes/debug-template.d.ts
1
+ //#region src/nitro/routes/debug-template.d.ts
2
2
  /**
3
3
  * Debug dashboard HTML template
4
4
  * Extracted from debug.ts to reduce file complexity
@@ -1,4 +1,4 @@
1
- //#region src/routes/debug-template.ts
1
+ //#region src/nitro/routes/debug-template.ts
2
2
  /**
3
3
  * Debug dashboard HTML template
4
4
  * Extracted from debug.ts to reduce file complexity
@@ -1,6 +1,6 @@
1
1
  import * as nitro_deps_h31 from "nitro/deps/h3";
2
2
 
3
- //#region src/routes/debug.d.ts
3
+ //#region src/nitro/routes/debug.d.ts
4
4
 
5
5
  /**
6
6
  * Debug endpoint for inspecting virtual modules and GraphQL setup
@@ -31,30 +31,24 @@ declare const _default: nitro_deps_h31.EventHandlerWithFetch<nitro_deps_h31.Even
31
31
  documentFiles: any;
32
32
  };
33
33
  runtime: {
34
- loadedResolvers: number;
35
- loadedSchemas: number;
36
- loadedDirectives: number;
34
+ loadedResolvers: any;
35
+ loadedSchemas: any;
36
+ loadedDirectives: any;
37
37
  };
38
38
  virtualModules: any;
39
39
  virtualModuleSamples: {
40
40
  'server-resolvers': {
41
- resolverCount: number;
42
- sample: {
43
- hasResolver: boolean;
44
- resolverKeys: string[];
45
- }[];
41
+ resolverCount: any;
42
+ sample: any;
46
43
  };
47
44
  'server-schemas': {
48
- schemaCount: number;
49
- sample: {
50
- defLength: number;
51
- defPreview: string;
52
- }[];
45
+ schemaCount: any;
46
+ sample: any;
53
47
  };
54
48
  'server-directives': {
55
- directiveCount: number;
49
+ directiveCount: any;
56
50
  };
57
- 'module-config': Record<string, any>;
51
+ 'module-config': any;
58
52
  };
59
53
  }>>;
60
54
  //#endregion
@@ -1,12 +1,12 @@
1
1
  import { generateHtmlDashboard } from "./debug-template.mjs";
2
+ import { defineEventHandler, getQuery } from "nitro/h3";
2
3
  import { moduleConfig } from "#nitro-graphql/module-config";
3
4
  import { directives } from "#nitro-graphql/server-directives";
4
5
  import { resolvers } from "#nitro-graphql/server-resolvers";
5
6
  import { schemas } from "#nitro-graphql/server-schemas";
6
- import { defineEventHandler, getQuery } from "nitro/h3";
7
7
  import { debugInfo } from "#nitro-graphql/debug-info";
8
8
 
9
- //#region src/routes/debug.ts
9
+ //#region src/nitro/routes/debug.ts
10
10
  /**
11
11
  * Debug endpoint for inspecting virtual modules and GraphQL setup
12
12
  * Only available in development mode
@@ -0,0 +1,6 @@
1
+ import * as nitro_deps_h33 from "nitro/deps/h3";
2
+
3
+ //#region src/nitro/routes/graphql-yoga.d.ts
4
+ declare const _default: nitro_deps_h33.EventHandlerWithFetch<nitro_deps_h33.EventHandlerRequest, Promise<Response>>;
5
+ //#endregion
6
+ export { _default as default };
@@ -1,14 +1,14 @@
1
- import { createMergedSchema } from "../utils/schema-builder.mjs";
1
+ import { createMergedSchema } from "../../core/schema/builder.mjs";
2
2
  import defu from "defu";
3
+ import { defineEventHandler } from "nitro/h3";
3
4
  import { importedConfig } from "#nitro-graphql/graphql-config";
4
5
  import { moduleConfig } from "#nitro-graphql/module-config";
5
6
  import { directives } from "#nitro-graphql/server-directives";
6
7
  import { resolvers } from "#nitro-graphql/server-resolvers";
7
8
  import { schemas } from "#nitro-graphql/server-schemas";
8
- import { defineEventHandler } from "nitro/h3";
9
9
  import { createYoga } from "graphql-yoga";
10
10
 
11
- //#region src/routes/graphql-yoga.ts
11
+ //#region src/nitro/routes/graphql-yoga.ts
12
12
  const apolloSandboxHtml = `<!DOCTYPE html>
13
13
  <html lang="en">
14
14
  <body style="margin: 0; overflow-x: hidden; overflow-y: hidden">
@@ -28,17 +28,28 @@ new window.EmbeddedSandbox({
28
28
  </html>`;
29
29
  let yoga;
30
30
  var graphql_yoga_default = defineEventHandler(async (event) => {
31
- if (!yoga) yoga = createYoga(defu({
32
- schema: await createMergedSchema({
31
+ if (!yoga) {
32
+ const schema = await createMergedSchema({
33
33
  schemas,
34
34
  resolvers,
35
35
  directives,
36
36
  moduleConfig
37
- }),
38
- graphqlEndpoint: "/api/graphql",
39
- landingPage: false,
40
- renderGraphiQL: () => apolloSandboxHtml
41
- }, importedConfig));
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
+ }
42
53
  const response = await yoga.handleRequest(event.req, event);
43
54
  if (event.res.status && event.res.status !== 200) return new Response(response.body, {
44
55
  ...response,
@@ -0,0 +1,10 @@
1
+ import * as nitro_deps_h35 from "nitro/deps/h3";
2
+
3
+ //#region src/nitro/routes/health.d.ts
4
+ declare const _default: nitro_deps_h35.EventHandlerWithFetch<nitro_deps_h35.EventHandlerRequest, Promise<{
5
+ status: string;
6
+ message: string;
7
+ timestamp: string;
8
+ }>>;
9
+ //#endregion
10
+ export { _default as default };
@@ -2,7 +2,7 @@ import { defineEventHandler } from "nitro/h3";
2
2
  import { $fetch } from "nitro/deps/ofetch";
3
3
  import { useRuntimeConfig } from "nitro/runtime-config";
4
4
 
5
- //#region src/routes/health.ts
5
+ //#region src/nitro/routes/health.ts
6
6
  var health_default = defineEventHandler(async (event) => {
7
7
  const runtime = useRuntimeConfig();
8
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 };
@@ -1,17 +1,13 @@
1
- import { DIRECTIVE_EXTENSIONS, DIR_SERVER_GRAPHQL, DIR_SERVER_GRAPHQL_WIN, GRAPHQL_EXTENSIONS, LOG_TAG, RESOLVER_EXTENSIONS } from "../constants.mjs";
2
- import { generateServerTypes } from "../codegen/server-types.mjs";
3
- import { generateClientTypes } from "../codegen/index.mjs";
4
- import { DEFAULT_WATCHER_IGNORE_INITIAL, DEFAULT_WATCHER_PERSISTENT } from "../config/defaults.mjs";
5
- import { generateDirectiveSchemas } from "../utils/directive-parser.mjs";
6
- import { generateLayerIgnorePatterns, getLayerAppDirectories, getLayerServerDirectories } from "../utils/layers.mjs";
7
- import { scanDirectives } from "../utils/scanning/directives.mjs";
8
- import { scanResolvers } from "../utils/scanning/resolvers.mjs";
9
- import { scanSchemas } from "../utils/scanning/schemas.mjs";
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";
10
6
  import consola from "consola";
11
7
  import { join } from "pathe";
12
8
  import { watch } from "chokidar";
13
9
 
14
- //#region src/setup/file-watcher.ts
10
+ //#region src/nitro/setup/file-watcher.ts
15
11
  const logger = consola.withTag(LOG_TAG);
16
12
  /**
17
13
  * Setup file watcher for GraphQL files (schemas, resolvers, directives, documents)
@@ -21,21 +17,21 @@ function setupFileWatcher(nitro, watchDirs) {
21
17
  const watcher = watch(watchDirs, {
22
18
  persistent: DEFAULT_WATCHER_PERSISTENT,
23
19
  ignoreInitial: DEFAULT_WATCHER_IGNORE_INITIAL,
24
- ignored: [...nitro.options.ignore, ...generateLayerIgnorePatterns()]
20
+ ignored: nitro.options.ignore
25
21
  });
26
22
  watcher.on("all", async (_, path) => {
27
23
  const isGraphQLFile = GRAPHQL_EXTENSIONS.some((ext) => path.endsWith(ext));
28
24
  const isResolverFile = RESOLVER_EXTENSIONS.some((ext) => path.endsWith(ext));
29
25
  const isDirectiveFile = DIRECTIVE_EXTENSIONS.some((ext) => path.endsWith(ext));
30
26
  if (isGraphQLFile || isResolverFile || isDirectiveFile) if (path.includes(nitro.graphql.serverDir) || path.includes(DIR_SERVER_GRAPHQL) || path.includes(DIR_SERVER_GRAPHQL_WIN) || isResolverFile || isDirectiveFile) {
31
- const directives = await scanDirectives(nitro);
32
- nitro.scanDirectives = directives;
27
+ const directivesResult = await NitroAdapter.scanDirectives(nitro);
28
+ nitro.scanDirectives = directivesResult.items;
33
29
  if (!nitro.scanSchemas) nitro.scanSchemas = [];
34
- const directivesPath = await generateDirectiveSchemas(nitro, directives);
35
- const schemas = await scanSchemas(nitro);
30
+ const directivesPath = await generateDirectiveSchemas(nitro, directivesResult.items);
31
+ const schemas = (await NitroAdapter.scanSchemas(nitro)).items;
36
32
  if (directivesPath && !schemas.includes(directivesPath)) schemas.push(directivesPath);
37
33
  nitro.scanSchemas = schemas;
38
- await scanResolvers(nitro).then((r) => nitro.scanResolvers = r);
34
+ nitro.scanResolvers = (await NitroAdapter.scanResolvers(nitro)).items;
39
35
  logger.success("Types regenerated");
40
36
  await generateServerTypes(nitro, { silent: true });
41
37
  await generateClientTypes(nitro, { silent: true });
@@ -55,8 +51,8 @@ function getWatchDirectories(nitro) {
55
51
  switch (nitro.options.framework.name) {
56
52
  case "nuxt": {
57
53
  watchDirs.push(nitro.graphql.clientDir);
58
- const layerServerDirs = getLayerServerDirectories(nitro);
59
- const layerAppDirs = getLayerAppDirectories(nitro);
54
+ const layerServerDirs = nitro.options.graphql?.layerServerDirs || [];
55
+ const layerAppDirs = nitro.options.graphql?.layerAppDirs || [];
60
56
  for (const layerServerDir of layerServerDirs) watchDirs.push(join(layerServerDir, "graphql"));
61
57
  for (const layerAppDir of layerAppDirs) watchDirs.push(join(layerAppDir, "graphql"));
62
58
  break;
@@ -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 };
@@ -1,6 +1,6 @@
1
- import { CHUNK_NAME_RESOLVERS, CHUNK_NAME_SCHEMAS, CHUNK_PATH_GRAPHQL, CHUNK_PATH_UNKNOWN, GRAPHQL_EXTENSIONS, RESOLVER_EXTENSIONS } from "../constants.mjs";
1
+ import { CHUNK_NAME_RESOLVERS, CHUNK_NAME_SCHEMAS, CHUNK_PATH_GRAPHQL, CHUNK_PATH_UNKNOWN, GRAPHQL_EXTENSIONS, RESOLVER_EXTENSIONS } from "../../core/constants.mjs";
2
2
 
3
- //#region src/setup/rollup-integration.ts
3
+ //#region src/nitro/setup/rollup-integration.ts
4
4
  /**
5
5
  * Setup Rollup/Rolldown chunking configuration for GraphQL files
6
6
  * Creates separate chunks for schemas and resolvers to optimize bundle size
@@ -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 };
@@ -1,8 +1,8 @@
1
- import { getDefaultPaths, getTypesConfig, resolveFilePath } from "../utils/path-resolver.mjs";
2
- import { relativeWithDot } from "../utils/imports.mjs";
1
+ import { relativeWithDot } from "../../core/utils/imports.mjs";
2
+ import { getDefaultPaths, getTypesConfig, resolveFilePath } from "../paths.mjs";
3
3
  import { dirname, join, resolve } from "pathe";
4
4
 
5
- //#region src/setup/ts-config.ts
5
+ //#region src/nitro/setup/ts-config.ts
6
6
  /**
7
7
  * Setup TypeScript path aliases for GraphQL types
8
8
  * Called via nitro:config hook to extend tsconfig.json
@@ -1,6 +1,7 @@
1
+ import { resolveSecurityConfig } from "./setup/logging.mjs";
1
2
  import { Nitro } from "nitro/types";
2
3
 
3
- //#region src/setup.d.ts
4
+ //#region src/nitro/setup.d.ts
4
5
 
5
6
  /**
6
7
  * Main setup function for nitro-graphql
@@ -8,4 +9,4 @@ import { Nitro } from "nitro/types";
8
9
  */
9
10
  declare function setupNitroGraphQL(nitro: Nitro): Promise<void>;
10
11
  //#endregion
11
- export { setupNitroGraphQL };
12
+ export { resolveSecurityConfig, setupNitroGraphQL };