nitro-graphql 2.0.0-beta.72 → 2.0.0-beta.73

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 (187) hide show
  1. package/README.md +1 -1
  2. package/dist/cli/adapter.d.mts +0 -3
  3. package/dist/cli/adapter.mjs +6 -29
  4. package/dist/cli/commands/generate.mjs +2 -2
  5. package/dist/cli/config.d.mts +4 -5
  6. package/dist/cli/config.mjs +3 -1
  7. package/dist/cli/index.d.mts +3 -6
  8. package/dist/cli/index.mjs +1 -1
  9. package/dist/cli/server/graphql-handler.mjs +2 -1
  10. package/dist/cli/server/watcher.mjs +1 -1
  11. package/dist/core/codegen/client.d.mts +4 -27
  12. package/dist/core/codegen/client.mjs +26 -445
  13. package/dist/core/codegen/file-header.d.mts +7 -0
  14. package/dist/core/codegen/file-header.mjs +12 -0
  15. package/dist/core/codegen/index.d.mts +7 -5
  16. package/dist/core/codegen/index.mjs +7 -5
  17. package/dist/core/codegen/{runtime.d.mts → runtime-generator.d.mts} +1 -1
  18. package/dist/core/codegen/{runtime.mjs → runtime-generator.mjs} +1 -1
  19. package/dist/core/codegen/schema-loader.d.mts +2 -7
  20. package/dist/core/codegen/schema-loader.mjs +65 -70
  21. package/dist/core/codegen/server-type-helpers.d.mts +14 -0
  22. package/dist/core/codegen/server-type-helpers.mjs +76 -0
  23. package/dist/core/codegen/server.d.mts +1 -15
  24. package/dist/core/codegen/server.mjs +15 -105
  25. package/dist/core/codegen/subscription-extractor.d.mts +20 -0
  26. package/dist/core/codegen/subscription-extractor.mjs +30 -0
  27. package/dist/core/codegen/vue-subscription-builder.d.mts +10 -0
  28. package/dist/core/codegen/vue-subscription-builder.mjs +351 -0
  29. package/dist/core/constants.d.mts +5 -53
  30. package/dist/core/constants.mjs +13 -54
  31. package/dist/core/create-config.d.mts +31 -0
  32. package/dist/core/create-config.mjs +42 -0
  33. package/dist/core/debug/index.d.mts +2 -2
  34. package/dist/core/debug/index.mjs +2 -2
  35. package/dist/core/debug/template.d.mts +1 -5
  36. package/dist/core/debug/template.mjs +1 -1
  37. package/dist/core/extend/loader.d.mts +0 -1
  38. package/dist/core/extend/loader.mjs +59 -89
  39. package/dist/core/index.d.mts +22 -17
  40. package/dist/core/index.mjs +19 -15
  41. package/dist/core/manifest.mjs +3 -1
  42. package/dist/core/pubsub/index.d.mts +2 -109
  43. package/dist/core/pubsub/index.mjs +1 -145
  44. package/dist/core/pubsub/memory-pubsub.d.mts +109 -0
  45. package/dist/core/pubsub/memory-pubsub.mjs +146 -0
  46. package/dist/core/scanning/ast-scanner.mjs +4 -2
  47. package/dist/core/scanning/directives.mjs +2 -3
  48. package/dist/core/scanning/documents.d.mts +4 -3
  49. package/dist/core/scanning/documents.mjs +1 -1
  50. package/dist/core/scanning/{common.d.mts → file-scanner.d.mts} +1 -1
  51. package/dist/core/scanning/{common.mjs → file-scanner.mjs} +2 -10
  52. package/dist/core/scanning/index.d.mts +3 -3
  53. package/dist/core/scanning/index.mjs +3 -3
  54. package/dist/core/scanning/resolvers.mjs +8 -9
  55. package/dist/core/scanning/schemas.d.mts +1 -5
  56. package/dist/core/scanning/schemas.mjs +2 -24
  57. package/dist/core/schema/builder.d.mts +4 -2
  58. package/dist/core/schema/builder.mjs +4 -2
  59. package/dist/core/schema/index.d.mts +2 -2
  60. package/dist/core/schema/index.mjs +2 -2
  61. package/dist/core/server/apollo.d.mts +20 -0
  62. package/dist/core/server/apollo.mjs +54 -0
  63. package/dist/core/server/index.d.mts +4 -2
  64. package/dist/core/server/index.mjs +3 -2
  65. package/dist/core/server/types.d.mts +7 -14
  66. package/dist/core/server/types.mjs +15 -1
  67. package/dist/core/server/yoga.d.mts +1 -7
  68. package/dist/core/server/yoga.mjs +4 -13
  69. package/dist/core/types/adapter.d.mts +4 -39
  70. package/dist/core/types/codegen.d.mts +22 -45
  71. package/dist/core/types/config.d.mts +33 -121
  72. package/dist/core/types/define.d.mts +8 -5
  73. package/dist/core/types/index.d.mts +5 -4
  74. package/dist/core/types/scanning.d.mts +4 -1
  75. package/dist/core/types/standard-schema.d.mts +64 -0
  76. package/dist/core/utils/directive-parser.d.mts +8 -63
  77. package/dist/core/utils/directive-parser.mjs +114 -166
  78. package/dist/core/utils/file-io.d.mts +1 -5
  79. package/dist/core/utils/file-io.mjs +1 -11
  80. package/dist/core/utils/index.d.mts +5 -4
  81. package/dist/core/utils/index.mjs +6 -5
  82. package/dist/core/utils/logger.d.mts +1 -10
  83. package/dist/core/utils/logger.mjs +1 -19
  84. package/dist/core/utils/ofetch-templates.mjs +3 -4
  85. package/dist/core/utils/runtime.d.mts +1 -30
  86. package/dist/core/utils/runtime.mjs +2 -44
  87. package/dist/core/utils/string.d.mts +10 -0
  88. package/dist/core/utils/string.mjs +12 -0
  89. package/dist/core/watcher/create-watcher.d.mts +103 -0
  90. package/dist/core/watcher/create-watcher.mjs +143 -0
  91. package/dist/core/watcher/index.d.mts +2 -107
  92. package/dist/core/watcher/index.mjs +1 -139
  93. package/dist/define.d.mts +4 -2
  94. package/dist/define.mjs +7 -6
  95. package/dist/index.d.mts +4 -3
  96. package/dist/index.mjs +1 -1
  97. package/dist/nitro/adapter.d.mts +6 -10
  98. package/dist/nitro/adapter.mjs +12 -42
  99. package/dist/nitro/codegen/client-types.d.mts +12 -0
  100. package/dist/nitro/codegen/client-types.mjs +73 -0
  101. package/dist/nitro/codegen/external-types.d.mts +8 -0
  102. package/dist/nitro/codegen/external-types.mjs +47 -0
  103. package/dist/nitro/codegen/index.d.mts +4 -0
  104. package/dist/nitro/codegen/index.mjs +4 -0
  105. package/dist/nitro/codegen/server-types.d.mts +12 -0
  106. package/dist/nitro/codegen/server-types.mjs +81 -0
  107. package/dist/nitro/defaults.d.mts +28 -0
  108. package/dist/nitro/defaults.mjs +34 -0
  109. package/dist/nitro/index.d.mts +11 -3
  110. package/dist/nitro/index.mjs +1 -1
  111. package/dist/nitro/paths.d.mts +3 -2
  112. package/dist/nitro/paths.mjs +13 -9
  113. package/dist/nitro/rollup.mjs +4 -3
  114. package/dist/nitro/routes/_ws-handler.d.mts +6 -0
  115. package/dist/nitro/routes/_ws-handler.mjs +49 -0
  116. package/dist/nitro/routes/apollo-server-ws.d.mts +1 -1
  117. package/dist/nitro/routes/apollo-server-ws.mjs +9 -44
  118. package/dist/nitro/routes/apollo-server.d.mts +1 -1
  119. package/dist/nitro/routes/apollo-server.mjs +16 -55
  120. package/dist/nitro/routes/debug.d.mts +1 -1
  121. package/dist/nitro/routes/debug.mjs +1 -0
  122. package/dist/nitro/routes/graphql-yoga-ws.d.mts +1 -1
  123. package/dist/nitro/routes/graphql-yoga-ws.mjs +6 -44
  124. package/dist/nitro/routes/graphql-yoga.mjs +7 -5
  125. package/dist/nitro/routes/health.mjs +22 -24
  126. package/dist/nitro/setup/extend-loader.d.mts +6 -5
  127. package/dist/nitro/setup/extend-loader.mjs +30 -58
  128. package/dist/nitro/setup/file-watcher.mjs +6 -4
  129. package/dist/nitro/setup/logging.d.mts +1 -8
  130. package/dist/nitro/setup/logging.mjs +7 -22
  131. package/dist/nitro/setup/rollup-integration.mjs +32 -1
  132. package/dist/nitro/setup/scanner.d.mts +8 -43
  133. package/dist/nitro/setup/scanner.mjs +56 -58
  134. package/dist/nitro/setup/security.d.mts +10 -0
  135. package/dist/nitro/setup/security.mjs +17 -0
  136. package/dist/nitro/setup/type-generation.d.mts +13 -0
  137. package/dist/nitro/setup/type-generation.mjs +16 -0
  138. package/dist/nitro/setup.d.mts +4 -3
  139. package/dist/nitro/setup.mjs +87 -74
  140. package/dist/nitro/state.d.mts +32 -0
  141. package/dist/nitro/state.mjs +58 -0
  142. package/dist/nitro/types/augmentation.d.mts +59 -0
  143. package/dist/nitro/types/augmentation.mjs +1 -0
  144. package/dist/nitro/types/config.d.mts +327 -0
  145. package/dist/nitro/types/config.mjs +1 -0
  146. package/dist/nitro/types/define.d.mts +13 -0
  147. package/dist/nitro/types/define.mjs +1 -0
  148. package/dist/nitro/types/index.d.mts +10 -0
  149. package/dist/nitro/types/index.mjs +1 -0
  150. package/dist/nitro/virtual/debug-info.d.mts +9 -0
  151. package/dist/nitro/virtual/debug-info.mjs +35 -0
  152. package/dist/nitro/virtual/graphql-config.d.mts +9 -0
  153. package/dist/nitro/virtual/graphql-config.mjs +33 -0
  154. package/dist/nitro/virtual/index.d.mts +25 -0
  155. package/dist/nitro/virtual/index.mjs +45 -0
  156. package/dist/nitro/virtual/module-config.d.mts +9 -0
  157. package/dist/nitro/virtual/module-config.mjs +10 -0
  158. package/dist/nitro/virtual/pubsub.d.mts +9 -0
  159. package/dist/nitro/virtual/pubsub.mjs +17 -0
  160. package/dist/nitro/virtual/server-directives.d.mts +9 -0
  161. package/dist/nitro/virtual/server-directives.mjs +12 -0
  162. package/dist/nitro/virtual/server-resolvers.d.mts +9 -0
  163. package/dist/nitro/virtual/server-resolvers.mjs +17 -0
  164. package/dist/nitro/virtual/server-schemas.d.mts +9 -0
  165. package/dist/nitro/virtual/server-schemas.mjs +31 -0
  166. package/dist/nitro/virtual/stubs.d.mts +42 -10
  167. package/dist/nitro/virtual/stubs.mjs +0 -5
  168. package/dist/nitro/virtual/utils.d.mts +15 -0
  169. package/dist/nitro/virtual/utils.mjs +26 -0
  170. package/dist/nitro/virtual/validation-schemas.d.mts +9 -0
  171. package/dist/nitro/virtual/validation-schemas.mjs +33 -0
  172. package/native/index.js +52 -52
  173. package/package.json +15 -15
  174. package/dist/cli/commands/index.d.mts +0 -5
  175. package/dist/cli/commands/index.mjs +0 -5
  176. package/dist/core/codegen/plugin.d.mts +0 -19
  177. package/dist/core/codegen/plugin.mjs +0 -29
  178. package/dist/core/config.d.mts +0 -45
  179. package/dist/core/config.mjs +0 -76
  180. package/dist/nitro/codegen.d.mts +0 -18
  181. package/dist/nitro/codegen.mjs +0 -171
  182. package/dist/nitro/config.d.mts +0 -50
  183. package/dist/nitro/config.mjs +0 -55
  184. package/dist/nitro/types.d.mts +0 -549
  185. package/dist/nitro/virtual/generators.d.mts +0 -38
  186. package/dist/nitro/virtual/generators.mjs +0 -190
  187. /package/dist/{nitro/types.mjs → core/types/standard-schema.mjs} +0 -0
@@ -1,50 +1,15 @@
1
- import { createMergedSchema } from "../../core/schema/builder.mjs";
1
+ import { wsHooks } from "./_ws-handler.mjs";
2
2
  import { defineWebSocketHandler } from "nitro/h3";
3
- import { handleProtocols } from "graphql-ws";
4
- import { makeHooks } from "graphql-ws/use/crossws";
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
3
  //#region src/nitro/routes/apollo-server-ws.ts
11
- let schema = null;
12
4
  /**
13
- * Get or create the merged GraphQL schema
5
+ * Apollo Server WebSocket handler for subscriptions
6
+ * Uses shared WebSocket handler with graphql-ws and crossws
7
+ *
8
+ * Note: This handler works independently from Apollo Server for subscriptions,
9
+ * as Apollo Server v5 requires separate WebSocket handling.
10
+ *
11
+ * @see https://github.com/enisdenjo/graphql-ws
14
12
  */
15
- async function getSchema() {
16
- if (!schema) schema = await createMergedSchema({
17
- schemas,
18
- resolvers,
19
- directives,
20
- moduleConfig
21
- });
22
- return schema;
23
- }
24
- var apollo_server_ws_default = defineWebSocketHandler({
25
- upgrade(request) {
26
- const selected = handleProtocols(request.headers.get("sec-websocket-protocol") || "");
27
- if (selected) return { headers: { "Sec-WebSocket-Protocol": selected } };
28
- return {};
29
- },
30
- ...makeHooks({
31
- schema: () => getSchema(),
32
- context: async (ctx) => {
33
- const baseContext = { connectionParams: ctx.connectionParams };
34
- if (typeof importedConfig.context === "function") {
35
- const userContext = await importedConfig.context(baseContext);
36
- return {
37
- ...baseContext,
38
- ...userContext
39
- };
40
- }
41
- if (importedConfig.context && typeof importedConfig.context === "object") return {
42
- ...baseContext,
43
- ...importedConfig.context
44
- };
45
- return baseContext;
46
- }
47
- })
48
- });
13
+ var apollo_server_ws_default = defineWebSocketHandler(wsHooks);
49
14
  //#endregion
50
15
  export { apollo_server_ws_default as default };
@@ -1,6 +1,6 @@
1
1
  import * as nitro_h30 from "nitro/h3";
2
2
 
3
3
  //#region src/nitro/routes/apollo-server.d.ts
4
- declare const _default: nitro_h30.EventHandlerWithFetch<nitro_h30.EventHandlerRequest, Promise<any>>;
4
+ declare const _default: nitro_h30.EventHandlerWithFetch<nitro_h30.EventHandlerRequest, Promise<unknown>>;
5
5
  //#endregion
6
6
  export { _default as default };
@@ -1,69 +1,30 @@
1
- import { createMergedSchema } from "../../core/schema/builder.mjs";
2
- import defu from "defu";
3
- import { ApolloServer } from "@apollo/server";
1
+ import { BASE_SCHEMA_DEF } from "../../core/schema/builder.mjs";
2
+ import { createApolloServerInstance } from "../../core/server/apollo.mjs";
4
3
  import { defineEventHandler } from "nitro/h3";
5
4
  import { importedConfig } from "#nitro-graphql/graphql-config";
6
5
  import { moduleConfig } from "#nitro-graphql/module-config";
7
6
  import { directives } from "#nitro-graphql/server-directives";
8
7
  import { resolvers } from "#nitro-graphql/server-resolvers";
9
8
  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
9
  import { startServerAndCreateH3Handler } from "nitro-graphql/apollo";
13
10
  //#region src/nitro/routes/apollo-server.ts
14
- let apolloServer = null;
15
- let serverStarted = false;
16
- async function createApolloServer() {
17
- if (!apolloServer) {
18
- const schema = await createMergedSchema({
19
- schemas,
20
- resolvers,
21
- directives,
22
- moduleConfig
23
- });
24
- const securityConfig = moduleConfig.security || {
25
- introspection: true,
26
- playground: true,
27
- maskErrors: false,
28
- disableSuggestions: false
29
- };
30
- const plugins = [];
31
- if (securityConfig.playground) plugins.push(ApolloServerPluginLandingPageLocalDefault({ embed: true }));
32
- else plugins.push(ApolloServerPluginLandingPageDisabled());
33
- const userFacingCodes = [
34
- "BAD_USER_INPUT",
35
- "GRAPHQL_VALIDATION_FAILED",
36
- "UNAUTHENTICATED",
37
- "FORBIDDEN",
38
- "BAD_REQUEST"
39
- ];
40
- apolloServer = new ApolloServer(defu({
41
- schema,
42
- introspection: securityConfig.introspection,
43
- plugins,
44
- formatError: securityConfig.maskErrors ? (formattedError, _error) => {
45
- const code = formattedError?.extensions?.code;
46
- if (code && userFacingCodes.includes(code)) return formattedError;
47
- return {
48
- message: "Internal server error",
49
- extensions: { code: "INTERNAL_SERVER_ERROR" }
50
- };
51
- } : void 0
52
- }, importedConfig));
53
- if (!serverStarted) {
54
- await apolloServer.start();
55
- serverStarted = true;
56
- }
57
- }
58
- return apolloServer;
59
- }
60
11
  let serverPromise = null;
12
+ let cachedH3Handler = null;
61
13
  var apollo_server_default = defineEventHandler(async (event) => {
62
- if (!serverPromise) serverPromise = createApolloServer();
63
- return startServerAndCreateH3Handler(await serverPromise, {
64
- context: async () => ({ event }),
14
+ if (!serverPromise) serverPromise = createApolloServerInstance({
15
+ schemas: [BASE_SCHEMA_DEF, ...schemas],
16
+ resolvers,
17
+ directives,
18
+ moduleConfig,
19
+ security: moduleConfig.security,
20
+ importedConfig
21
+ });
22
+ const server = await serverPromise;
23
+ if (!cachedH3Handler) cachedH3Handler = startServerAndCreateH3Handler(server, {
24
+ context: async (req) => ({ event: req.event }),
65
25
  serverAlreadyStarted: true
66
- })(event);
26
+ });
27
+ return cachedH3Handler(event);
67
28
  });
68
29
  //#endregion
69
30
  export { apollo_server_default as default };
@@ -9,7 +9,7 @@ import * as nitro_h30 from "nitro/h3";
9
9
  * - /_nitro/graphql/debug - HTML dashboard
10
10
  * - /_nitro/graphql/debug?format=json - JSON API
11
11
  */
12
- declare const _default: nitro_h30.EventHandlerWithFetch<nitro_h30.EventHandlerRequest, Promise<string | {
12
+ declare const _default: nitro_h30.EventHandlerWithFetch<nitro_h30.EventHandlerRequest, Promise<string | Response | {
13
13
  timestamp: string;
14
14
  environment: {
15
15
  dev: any;
@@ -15,6 +15,7 @@ import { debugInfo } from "#nitro-graphql/debug-info";
15
15
  * - /_nitro/graphql/debug?format=json - JSON API
16
16
  */
17
17
  var debug_default = defineEventHandler(async (event) => {
18
+ if (import.meta.env?.PROD || process.env.NODE_ENV === "production") return new Response("Not Found", { status: 404 });
18
19
  const format = getQuery(event).format || "html";
19
20
  const processedResolverFiles = debugInfo.scanned.resolverFiles.map((r) => {
20
21
  return {
@@ -3,7 +3,7 @@ import * as nitro_h30 from "nitro/h3";
3
3
  //#region src/nitro/routes/graphql-yoga-ws.d.ts
4
4
  /**
5
5
  * GraphQL Yoga WebSocket handler for subscriptions
6
- * Uses graphql-ws library with crossws adapter for proper protocol handling
6
+ * Uses shared WebSocket handler with graphql-ws and crossws
7
7
  *
8
8
  * @see https://github.com/enisdenjo/graphql-ws
9
9
  */
@@ -1,50 +1,12 @@
1
- import { createMergedSchema } from "../../core/schema/builder.mjs";
1
+ import { wsHooks } from "./_ws-handler.mjs";
2
2
  import { defineWebSocketHandler } from "nitro/h3";
3
- import { handleProtocols } from "graphql-ws";
4
- import { makeHooks } from "graphql-ws/use/crossws";
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
3
  //#region src/nitro/routes/graphql-yoga-ws.ts
11
- let schema = null;
12
4
  /**
13
- * Get or create the merged GraphQL schema
5
+ * GraphQL Yoga WebSocket handler for subscriptions
6
+ * Uses shared WebSocket handler with graphql-ws and crossws
7
+ *
8
+ * @see https://github.com/enisdenjo/graphql-ws
14
9
  */
15
- async function getSchema() {
16
- if (!schema) schema = await createMergedSchema({
17
- schemas,
18
- resolvers,
19
- directives,
20
- moduleConfig
21
- });
22
- return schema;
23
- }
24
- var graphql_yoga_ws_default = defineWebSocketHandler({
25
- upgrade(request) {
26
- const selected = handleProtocols(request.headers.get("sec-websocket-protocol") || "");
27
- if (selected) return { headers: { "Sec-WebSocket-Protocol": selected } };
28
- return {};
29
- },
30
- ...makeHooks({
31
- schema: () => getSchema(),
32
- context: async (ctx) => {
33
- const baseContext = { connectionParams: ctx.connectionParams };
34
- if (typeof importedConfig.context === "function") {
35
- const userContext = await importedConfig.context(baseContext);
36
- return {
37
- ...baseContext,
38
- ...userContext
39
- };
40
- }
41
- if (importedConfig.context && typeof importedConfig.context === "object") return {
42
- ...baseContext,
43
- ...importedConfig.context
44
- };
45
- return baseContext;
46
- }
47
- })
48
- });
10
+ var graphql_yoga_ws_default = defineWebSocketHandler(wsHooks);
49
11
  //#endregion
50
12
  export { graphql_yoga_ws_default as default };
@@ -1,4 +1,5 @@
1
- import { BASE_SCHEMA, createYogaServer } from "../../core/server/yoga.mjs";
1
+ import { BASE_SCHEMA_DEF } from "../../core/schema/builder.mjs";
2
+ import { createYogaServer } from "../../core/server/yoga.mjs";
2
3
  import { defineEventHandler, getQuery } from "nitro/h3";
3
4
  import { importedConfig } from "#nitro-graphql/graphql-config";
4
5
  import { moduleConfig } from "#nitro-graphql/module-config";
@@ -10,19 +11,20 @@ const PLAYGROUND_CACHE_HEADER = "public, max-age=2592000, stale-while-revalidate
10
11
  let server = null;
11
12
  var graphql_yoga_default = defineEventHandler(async (event) => {
12
13
  if (!server) server = await createYogaServer({
13
- schemas: [BASE_SCHEMA, ...schemas],
14
+ schemas: [BASE_SCHEMA_DEF, ...schemas],
14
15
  resolvers,
15
16
  directives,
16
17
  moduleConfig,
17
- endpoint: "/api/graphql",
18
+ endpoint: moduleConfig.endpoint?.graphql || "/api/graphql",
18
19
  security: moduleConfig.security,
19
20
  importedConfig
20
21
  });
21
22
  const response = await server.fetch(event.req, event);
22
23
  const isPlaygroundRequest = event.req.method === "GET" && !getQuery(event).query;
23
24
  if (event.res.status && event.res.status !== 200) return new Response(response.body, {
24
- ...response,
25
- status: event.res.status
25
+ status: event.res.status,
26
+ statusText: response.statusText,
27
+ headers: response.headers
26
28
  });
27
29
  if (isPlaygroundRequest && response.headers.get("content-type")?.includes("text/html")) {
28
30
  const headers = new Headers(response.headers);
@@ -1,36 +1,34 @@
1
+ import { createMergedSchema } from "../../core/schema/builder.mjs";
2
+ import { execute, parse } from "graphql";
1
3
  import { defineEventHandler } from "nitro/h3";
2
- import { useRuntimeConfig } from "nitro/runtime-config";
3
- import { $fetch } from "ofetch";
4
+ import { moduleConfig } from "#nitro-graphql/module-config";
5
+ import { directives } from "#nitro-graphql/server-directives";
6
+ import { resolvers } from "#nitro-graphql/server-resolvers";
7
+ import { schemas } from "#nitro-graphql/server-schemas";
4
8
  //#region src/nitro/routes/health.ts
9
+ let schema = null;
10
+ async function getSchema() {
11
+ if (!schema) schema = await createMergedSchema({
12
+ schemas,
13
+ resolvers,
14
+ directives,
15
+ moduleConfig
16
+ });
17
+ return schema;
18
+ }
19
+ const HEALTH_QUERY = parse("query Health { __typename }");
5
20
  var health_default = defineEventHandler(async (event) => {
6
- const runtime = useRuntimeConfig();
7
- if (!runtime.graphql || !runtime.graphql.endpoint?.graphql) {
8
- event.res.status = 404;
9
- event.res.statusText = "Not Found";
10
- return {
11
- status: "error",
12
- message: "GraphQL health check endpoint is not configured",
13
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
14
- };
15
- }
16
21
  try {
17
- const response = await $fetch(runtime.graphql.endpoint?.graphql, {
18
- method: "POST",
19
- body: {
20
- query: "query Health { __typename }",
21
- operationName: "Health"
22
- },
23
- headers: {
24
- "Content-Type": "application/json",
25
- "Accept": "application/json"
26
- }
22
+ const result = await execute({
23
+ schema: await getSchema(),
24
+ document: HEALTH_QUERY
27
25
  });
28
- if (response && typeof response === "object" && "data" in response) return {
26
+ if (result.data) return {
29
27
  status: "healthy",
30
28
  message: "GraphQL server is running",
31
29
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
32
30
  };
33
- throw new Error("Invalid response from GraphQL server");
31
+ throw new Error(result.errors?.map((e) => e.message).join(", ") || "Invalid response from GraphQL server");
34
32
  } catch (error) {
35
33
  event.res.status = 503;
36
34
  event.res.statusText = "Service Unavailable";
@@ -1,3 +1,4 @@
1
+ import { GraphQLScanState } from "../types/augmentation.mjs";
1
2
  import { Nitro } from "nitro/types";
2
3
 
3
4
  //#region src/nitro/setup/extend-loader.d.ts
@@ -5,12 +6,12 @@ import { Nitro } from "nitro/types";
5
6
  * Resolve extend directories for file watching
6
7
  */
7
8
  declare function resolveExtendDirs(nitro: Nitro): Promise<string[]>;
8
- interface ResolveExtendOptions {
9
- silent?: boolean;
10
- }
11
9
  /**
12
- * Resolve extend configuration and add files to Nitro scan results
10
+ * Resolve extend configuration and merge into scan state.
11
+ * Returns a new frozen state — does NOT mutate nitro.
13
12
  */
14
- declare function resolveExtendConfig(nitro: Nitro, options?: ResolveExtendOptions): Promise<void>;
13
+ declare function resolveExtendConfig(nitro: Nitro, state: GraphQLScanState, options?: {
14
+ silent?: boolean;
15
+ }): Promise<GraphQLScanState>;
15
16
  //#endregion
16
17
  export { resolveExtendConfig, resolveExtendDirs };
@@ -1,6 +1,7 @@
1
1
  import { LOG_TAG } from "../../core/constants.mjs";
2
2
  import { generateDirectiveSchemas } from "../../core/utils/directive-parser.mjs";
3
3
  import { resolveExtendDirs as resolveExtendDirs$1, scanAllExtendSources } from "../../core/extend/loader.mjs";
4
+ import { mergeScanState } from "../state.mjs";
4
5
  import consola from "consola";
5
6
  //#region src/nitro/setup/extend-loader.ts
6
7
  const logger = consola.withTag(LOG_TAG);
@@ -12,69 +13,40 @@ async function resolveExtendDirs(nitro) {
12
13
  return resolveExtendDirs$1(extend, nitro.options.rootDir);
13
14
  }
14
15
  /**
15
- * Resolve extend configuration and add files to Nitro scan results
16
+ * Resolve extend configuration and merge into scan state.
17
+ * Returns a new frozen state — does NOT mutate nitro.
16
18
  */
17
- async function resolveExtendConfig(nitro, options = {}) {
19
+ async function resolveExtendConfig(nitro, state, options = {}) {
18
20
  const extend = nitro.options.graphql?.extend;
19
- if (!extend || !Array.isArray(extend) || extend.length === 0) return;
20
- const stats = applyExtendResult(nitro, await scanAllExtendSources(extend, nitro.options.rootDir));
21
- if (stats.directives > 0) {
22
- const directiveSchemas = await generateDirectiveSchemas(nitro.scanDirectives, nitro.graphql.buildDir);
23
- nitro.graphql.directiveSchemas = directiveSchemas;
24
- }
25
- if (!options.silent && (stats.schemas > 0 || stats.resolvers > 0 || stats.directives > 0 || stats.documents > 0)) {
21
+ if (!extend || !Array.isArray(extend) || extend.length === 0) return state;
22
+ const result = await scanAllExtendSources(extend, nitro.options.rootDir);
23
+ let newState = mergeScanState(state, result);
24
+ if (result.directives.length > 0) {
25
+ const directiveSchemas = await generateDirectiveSchemas([...newState.directives], nitro.graphql.buildDir);
26
+ newState = Object.freeze({
27
+ ...newState,
28
+ directiveSchemas
29
+ });
30
+ }
31
+ const added = {
32
+ schemas: newState.schemas.length - state.schemas.length,
33
+ resolvers: newState.resolvers.length - state.resolvers.length,
34
+ directives: newState.directives.length - state.directives.length,
35
+ documents: newState.documents.length - state.documents.length,
36
+ configs: newState.extendConfigs.length - state.extendConfigs.length,
37
+ programmaticSchemas: newState.extendSchemas.length - state.extendSchemas.length
38
+ };
39
+ if (!options.silent && Object.values(added).some((v) => v > 0)) {
26
40
  const parts = [];
27
- if (stats.schemas > 0) parts.push(`${stats.schemas} schema(s)`);
28
- if (stats.resolvers > 0) parts.push(`${stats.resolvers} resolver(s)`);
29
- if (stats.directives > 0) parts.push(`${stats.directives} directive(s)`);
30
- if (stats.documents > 0) parts.push(`${stats.documents} document(s)`);
31
- if (stats.configs > 0) parts.push(`${stats.configs} config(s)`);
32
- if (stats.programmaticSchemas > 0) parts.push(`${stats.programmaticSchemas} programmatic schema(s)`);
41
+ if (added.schemas > 0) parts.push(`${added.schemas} schema(s)`);
42
+ if (added.resolvers > 0) parts.push(`${added.resolvers} resolver(s)`);
43
+ if (added.directives > 0) parts.push(`${added.directives} directive(s)`);
44
+ if (added.documents > 0) parts.push(`${added.documents} document(s)`);
45
+ if (added.configs > 0) parts.push(`${added.configs} config(s)`);
46
+ if (added.programmaticSchemas > 0) parts.push(`${added.programmaticSchemas} programmatic schema(s)`);
33
47
  logger.info(`Extended with ${parts.join(", ")}`);
34
48
  }
35
- }
36
- /**
37
- * Apply extend scan result to Nitro state
38
- */
39
- function applyExtendResult(nitro, result) {
40
- let schemasAdded = 0;
41
- let resolversAdded = 0;
42
- let directivesAdded = 0;
43
- let documentsAdded = 0;
44
- let configsAdded = 0;
45
- let programmaticSchemasAdded = 0;
46
- for (const schemaPath of result.schemas) if (!nitro.scanSchemas.includes(schemaPath)) {
47
- nitro.scanSchemas.push(schemaPath);
48
- schemasAdded++;
49
- }
50
- for (const resolver of result.resolvers) if (!nitro.scanResolvers.some((r) => r.specifier === resolver.specifier)) {
51
- nitro.scanResolvers.push(resolver);
52
- resolversAdded++;
53
- }
54
- for (const directive of result.directives) if (!nitro.scanDirectives.some((d) => d.specifier === directive.specifier)) {
55
- nitro.scanDirectives.push(directive);
56
- directivesAdded++;
57
- }
58
- for (const docPath of result.documents) if (!nitro.scanDocuments.includes(docPath)) {
59
- nitro.scanDocuments.push(docPath);
60
- documentsAdded++;
61
- }
62
- if (result.configPath && !nitro.graphql.extendConfigs.includes(result.configPath)) {
63
- nitro.graphql.extendConfigs.push(result.configPath);
64
- configsAdded++;
65
- }
66
- if (result.schemaPath && !nitro.graphql.extendSchemas.includes(result.schemaPath)) {
67
- nitro.graphql.extendSchemas.push(result.schemaPath);
68
- programmaticSchemasAdded++;
69
- }
70
- return {
71
- schemas: schemasAdded,
72
- resolvers: resolversAdded,
73
- directives: directivesAdded,
74
- documents: documentsAdded,
75
- configs: configsAdded,
76
- programmaticSchemas: programmaticSchemasAdded
77
- };
49
+ return newState;
78
50
  }
79
51
  //#endregion
80
52
  export { resolveExtendConfig, resolveExtendDirs };
@@ -1,7 +1,9 @@
1
1
  import { LOG_TAG } from "../../core/constants.mjs";
2
- import { generateClientTypes, generateServerTypes } from "../codegen.mjs";
3
- import { createCoreWatcher } from "../../core/watcher/index.mjs";
2
+ import { refreshVirtualModules } from "../virtual/index.mjs";
3
+ import { createCoreWatcher } from "../../core/watcher/create-watcher.mjs";
4
+ import { generateClientTypes } from "../codegen/client-types.mjs";
4
5
  import { performGraphQLScan, shouldScanLocalFiles } from "./scanner.mjs";
6
+ import { regenerateTypes } from "./type-generation.mjs";
5
7
  import consola from "consola";
6
8
  import { join } from "pathe";
7
9
  //#region src/nitro/setup/file-watcher.ts
@@ -24,8 +26,8 @@ function setupFileWatcher(nitro, watchDirs) {
24
26
  silent: true,
25
27
  isRescan: true
26
28
  });
27
- await generateServerTypes(nitro, { silent: true });
28
- await generateClientTypes(nitro, { silent: true });
29
+ refreshVirtualModules(nitro);
30
+ await regenerateTypes(nitro, { silent: true });
29
31
  logger.success("Types regenerated");
30
32
  await nitro.hooks.callHook("dev:reload");
31
33
  },
@@ -1,16 +1,9 @@
1
- import { SecurityConfig } from "../types.mjs";
2
1
  import { Nitro } from "nitro/types";
3
2
 
4
3
  //#region src/nitro/setup/logging.d.ts
5
- /**
6
- * Resolves security configuration with environment-aware defaults
7
- * In production: introspection off, playground off, errors masked, suggestions disabled
8
- * In development: introspection on, playground on, errors shown, suggestions enabled
9
- */
10
- declare function resolveSecurityConfig(config?: SecurityConfig): Required<SecurityConfig>;
11
4
  /**
12
5
  * Log startup information
13
6
  */
14
7
  declare function logStartupInfo(nitro: Nitro, serverEnabled: boolean): void;
15
8
  //#endregion
16
- export { logStartupInfo, resolveSecurityConfig };
9
+ export { logStartupInfo };
@@ -1,40 +1,25 @@
1
+ import { resolveSecurityConfig } from "./security.mjs";
1
2
  import consola from "consola";
2
3
  //#region src/nitro/setup/logging.ts
3
4
  /**
4
- * Resolves security configuration with environment-aware defaults
5
- * In production: introspection off, playground off, errors masked, suggestions disabled
6
- * In development: introspection on, playground on, errors shown, suggestions enabled
7
- */
8
- function resolveSecurityConfig(config) {
9
- const isProd = process.env.NODE_ENV === "production";
10
- return {
11
- introspection: config?.introspection ?? !isProd,
12
- playground: config?.playground ?? !isProd,
13
- maskErrors: config?.maskErrors ?? isProd,
14
- disableSuggestions: config?.disableSuggestions ?? isProd
15
- };
16
- }
17
- /**
18
5
  * Log startup information
19
6
  */
20
7
  function logStartupInfo(nitro, serverEnabled) {
8
+ const { state } = nitro.graphql;
21
9
  const externalServicesCount = nitro.options.graphql?.externalServices?.length || 0;
22
- const docs = nitro.scanDocuments || [];
23
10
  const isProd = process.env.NODE_ENV === "production";
24
11
  if (serverEnabled) {
25
12
  const securityConfig = resolveSecurityConfig(nitro.options.graphql?.security);
26
13
  const framework = nitro.options.graphql?.framework || "unknown";
27
- const schemas = nitro.scanSchemas?.length || 0;
28
- const resolvers = nitro.scanResolvers?.length || 0;
29
14
  consola.box({
30
15
  title: "Nitro GraphQL",
31
16
  message: [
32
17
  `Framework: ${framework}`,
33
18
  `Environment: ${isProd ? "production" : "development"}`,
34
- `Schemas: ${schemas}`,
35
- `Resolvers: ${resolvers}`,
19
+ `Schemas: ${state.schemas.length}`,
20
+ `Resolvers: ${state.resolvers.length}`,
36
21
  externalServicesCount > 0 ? `External Services: ${externalServicesCount}` : "",
37
- docs.length > 0 ? `Documents: ${docs.length}` : "",
22
+ state.documents.length > 0 ? `Documents: ${state.documents.length}` : "",
38
23
  "",
39
24
  "Security:",
40
25
  `├─ Introspection: ${securityConfig.introspection ? "enabled" : "disabled"}`,
@@ -52,7 +37,7 @@ function logStartupInfo(nitro, serverEnabled) {
52
37
  message: [
53
38
  "Server mode: disabled",
54
39
  `External Services: ${externalServicesCount}`,
55
- `Documents: ${docs.length}`
40
+ `Documents: ${state.documents.length}`
56
41
  ].join("\n"),
57
42
  style: {
58
43
  borderColor: "blue",
@@ -61,4 +46,4 @@ function logStartupInfo(nitro, serverEnabled) {
61
46
  });
62
47
  }
63
48
  //#endregion
64
- export { logStartupInfo, resolveSecurityConfig };
49
+ export { logStartupInfo };
@@ -1,3 +1,4 @@
1
+ import { CHUNK_NAME_RESOLVERS, CHUNK_NAME_SCHEMAS, CHUNK_PATH_UNKNOWN, GRAPHQL_EXTENSIONS, RESOLVER_EXTENSIONS } from "../../core/constants.mjs";
1
2
  //#region src/nitro/setup/rollup-integration.ts
2
3
  const NITRO_GRAPHQL_ROUTES_RE = /nitro-graphql[/\\]dist[/\\]nitro[/\\]routes/;
3
4
  const NITRO_GRAPHQL_SCHEMA_RE = /nitro-graphql[/\\]dist[/\\]core[/\\]schema/;
@@ -20,7 +21,37 @@ function setupNoExternals(nitro) {
20
21
  * interfering with Nitro's node_modules chunking which uses advancedChunks.
21
22
  */
22
23
  function setupRollupChunking(nitro) {
23
- nitro.hooks.hook("rollup:before", (_, rollupConfig) => {});
24
+ nitro.hooks.hook("rollup:before", (_, rollupConfig) => {
25
+ if (rollupConfig.output.inlineDynamicImports) return;
26
+ const output = rollupConfig.output;
27
+ if (output.advancedChunks || "codeSplitting" in output) return;
28
+ const existingManualChunks = rollupConfig.output?.manualChunks;
29
+ rollupConfig.output.manualChunks = (id, meta) => {
30
+ if (isGraphQLFile(id)) return `graphql/${CHUNK_NAME_SCHEMAS}`;
31
+ if (isResolverFile(id)) return `graphql/${CHUNK_NAME_RESOLVERS}`;
32
+ if (typeof existingManualChunks === "function") return existingManualChunks(id, meta);
33
+ };
34
+ const existingChunkFileNames = rollupConfig.output.chunkFileNames;
35
+ rollupConfig.output.chunkFileNames = (chunkInfo) => {
36
+ const name = chunkInfo.name || "";
37
+ if (name.startsWith("graphql/")) return `chunks/${name}.mjs`;
38
+ if (typeof existingChunkFileNames === "function") return existingChunkFileNames(chunkInfo);
39
+ if (typeof existingChunkFileNames === "string") return existingChunkFileNames;
40
+ return CHUNK_PATH_UNKNOWN;
41
+ };
42
+ });
43
+ }
44
+ /**
45
+ * Check if a file is a GraphQL schema file
46
+ */
47
+ function isGraphQLFile(id) {
48
+ return GRAPHQL_EXTENSIONS.some((ext) => id.endsWith(ext));
49
+ }
50
+ /**
51
+ * Check if a file is a resolver file
52
+ */
53
+ function isResolverFile(id) {
54
+ return RESOLVER_EXTENSIONS.some((ext) => id.endsWith(ext));
24
55
  }
25
56
  /**
26
57
  * Configure external dependencies for Rollup