nitro-graphql 2.0.0-beta.7 → 2.0.0-beta.70

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 (239) hide show
  1. package/README.md +31 -1196
  2. package/dist/cli/adapter.d.mts +13 -0
  3. package/dist/cli/adapter.mjs +69 -0
  4. package/dist/cli/commands/build.d.mts +21 -0
  5. package/dist/cli/commands/build.mjs +52 -0
  6. package/dist/cli/commands/dev.d.mts +40 -0
  7. package/dist/cli/commands/dev.mjs +76 -0
  8. package/dist/cli/commands/generate.d.mts +25 -0
  9. package/dist/cli/commands/generate.mjs +198 -0
  10. package/dist/cli/commands/index.d.mts +5 -0
  11. package/dist/cli/commands/index.mjs +6 -0
  12. package/dist/cli/commands/init.d.mts +45 -0
  13. package/dist/cli/commands/init.mjs +195 -0
  14. package/dist/cli/commands/validate.d.mts +9 -0
  15. package/dist/cli/commands/validate.mjs +67 -0
  16. package/dist/cli/completions.d.mts +6 -0
  17. package/dist/cli/completions.mjs +34 -0
  18. package/dist/cli/config.d.mts +18 -0
  19. package/dist/cli/config.mjs +20 -0
  20. package/dist/cli/index.d.mts +26 -0
  21. package/dist/cli/index.mjs +317 -0
  22. package/dist/cli/server/debug-handler.d.mts +9 -0
  23. package/dist/cli/server/debug-handler.mjs +71 -0
  24. package/dist/cli/server/dev-server.d.mts +29 -0
  25. package/dist/cli/server/dev-server.mjs +64 -0
  26. package/dist/cli/server/graphql-handler.d.mts +21 -0
  27. package/dist/cli/server/graphql-handler.mjs +45 -0
  28. package/dist/cli/server/health-handler.d.mts +12 -0
  29. package/dist/cli/server/health-handler.mjs +30 -0
  30. package/dist/cli/server/loader.d.mts +33 -0
  31. package/dist/cli/server/loader.mjs +146 -0
  32. package/dist/cli/server/sandbox-handler.d.mts +12 -0
  33. package/dist/cli/server/sandbox-handler.mjs +19 -0
  34. package/dist/cli/server/watcher.d.mts +20 -0
  35. package/dist/cli/server/watcher.mjs +66 -0
  36. package/dist/cli/server/ws-handler.d.mts +28 -0
  37. package/dist/cli/server/ws-handler.mjs +50 -0
  38. package/dist/config.d.mts +2 -0
  39. package/dist/config.mjs +3 -0
  40. package/dist/core/codegen/client.d.mts +42 -0
  41. package/dist/core/codegen/client.mjs +553 -0
  42. package/dist/core/codegen/document-loader.d.mts +9 -0
  43. package/dist/core/codegen/document-loader.mjs +18 -0
  44. package/dist/core/codegen/index.d.mts +8 -0
  45. package/dist/core/codegen/index.mjs +9 -0
  46. package/dist/core/codegen/plugin.d.mts +19 -0
  47. package/dist/core/codegen/plugin.mjs +30 -0
  48. package/dist/core/codegen/runtime.d.mts +19 -0
  49. package/dist/core/codegen/runtime.mjs +60 -0
  50. package/dist/core/codegen/schema-loader.d.mts +27 -0
  51. package/dist/core/codegen/schema-loader.mjs +128 -0
  52. package/dist/core/codegen/server.d.mts +27 -0
  53. package/dist/core/codegen/server.mjs +144 -0
  54. package/dist/core/codegen/validation.d.mts +17 -0
  55. package/dist/core/codegen/validation.mjs +35 -0
  56. package/dist/core/config.d.mts +45 -0
  57. package/dist/core/config.mjs +78 -0
  58. package/dist/core/constants.d.mts +188 -0
  59. package/dist/core/constants.mjs +210 -0
  60. package/dist/core/debug/index.d.mts +2 -0
  61. package/dist/core/debug/index.mjs +3 -0
  62. package/dist/core/debug/template.d.mts +52 -0
  63. package/dist/core/debug/template.mjs +383 -0
  64. package/dist/core/extend/index.d.mts +2 -0
  65. package/dist/core/extend/index.mjs +3 -0
  66. package/dist/core/extend/loader.d.mts +40 -0
  67. package/dist/core/extend/loader.mjs +198 -0
  68. package/dist/core/index.d.mts +37 -0
  69. package/dist/core/index.mjs +29 -0
  70. package/dist/core/manifest.d.mts +56 -0
  71. package/dist/core/manifest.mjs +102 -0
  72. package/dist/core/pubsub/index.d.mts +109 -0
  73. package/dist/core/pubsub/index.mjs +148 -0
  74. package/dist/core/scanning/ast-scanner.d.mts +27 -0
  75. package/dist/core/scanning/ast-scanner.mjs +116 -0
  76. package/dist/core/scanning/common.d.mts +25 -0
  77. package/dist/core/scanning/common.mjs +59 -0
  78. package/dist/core/scanning/directives.d.mts +13 -0
  79. package/dist/core/scanning/directives.mjs +29 -0
  80. package/dist/core/scanning/documents.d.mts +20 -0
  81. package/dist/core/scanning/documents.mjs +37 -0
  82. package/dist/core/scanning/index.d.mts +7 -0
  83. package/dist/core/scanning/index.mjs +8 -0
  84. package/dist/core/scanning/resolvers.d.mts +14 -0
  85. package/dist/core/scanning/resolvers.mjs +59 -0
  86. package/dist/core/scanning/schemas.d.mts +13 -0
  87. package/dist/core/scanning/schemas.mjs +52 -0
  88. package/dist/core/schema/builder.d.mts +59 -0
  89. package/dist/core/schema/builder.mjs +78 -0
  90. package/dist/core/schema/federation.d.mts +33 -0
  91. package/dist/core/schema/federation.mjs +40 -0
  92. package/dist/core/schema/index.d.mts +3 -0
  93. package/dist/core/schema/index.mjs +4 -0
  94. package/dist/core/server/index.d.mts +4 -0
  95. package/dist/core/server/index.mjs +4 -0
  96. package/dist/core/server/sandbox.d.mts +18 -0
  97. package/dist/core/server/sandbox.mjs +39 -0
  98. package/dist/core/server/types.d.mts +54 -0
  99. package/dist/core/server/yoga.d.mts +42 -0
  100. package/dist/core/server/yoga.mjs +89 -0
  101. package/dist/core/types/adapter.d.mts +57 -0
  102. package/dist/core/types/codegen.d.mts +136 -0
  103. package/dist/core/types/codegen.mjs +1 -0
  104. package/dist/core/types/config.d.mts +188 -0
  105. package/dist/core/types/config.mjs +1 -0
  106. package/dist/{utils/define.d.ts → core/types/define.d.mts} +2 -30
  107. package/dist/core/types/define.mjs +1 -0
  108. package/dist/core/types/index.d.mts +5 -0
  109. package/dist/core/types/index.mjs +1 -0
  110. package/dist/core/types/scanning.d.mts +64 -0
  111. package/dist/core/types/scanning.mjs +1 -0
  112. package/dist/{utils/directive-parser.d.ts → core/utils/directive-parser.d.mts} +18 -4
  113. package/dist/{utils/directive-parser.js → core/utils/directive-parser.mjs} +28 -34
  114. package/dist/core/utils/errors.d.mts +77 -0
  115. package/dist/core/utils/errors.mjs +93 -0
  116. package/dist/core/utils/file-io.d.mts +24 -0
  117. package/dist/core/utils/file-io.mjs +47 -0
  118. package/dist/core/utils/imports.d.mts +15 -0
  119. package/dist/core/utils/imports.mjs +25 -0
  120. package/dist/core/utils/index.d.mts +7 -0
  121. package/dist/core/utils/index.mjs +8 -0
  122. package/dist/core/utils/logger.d.mts +18 -0
  123. package/dist/core/utils/logger.mjs +38 -0
  124. package/dist/core/utils/ofetch-templates.d.mts +30 -0
  125. package/dist/core/utils/ofetch-templates.mjs +135 -0
  126. package/dist/core/utils/runtime.d.mts +74 -0
  127. package/dist/core/utils/runtime.mjs +111 -0
  128. package/dist/core/utils/subscribe-templates.d.mts +8 -0
  129. package/dist/core/utils/subscribe-templates.mjs +59 -0
  130. package/dist/core/validation/external-services.d.mts +11 -0
  131. package/dist/core/validation/external-services.mjs +33 -0
  132. package/dist/core/validation/index.d.mts +2 -0
  133. package/dist/core/validation/index.mjs +3 -0
  134. package/dist/core/watcher/index.d.mts +107 -0
  135. package/dist/core/watcher/index.mjs +141 -0
  136. package/dist/define.d.mts +294 -0
  137. package/dist/define.mjs +325 -0
  138. package/dist/index.d.mts +6 -0
  139. package/dist/index.mjs +6 -0
  140. package/dist/nitro/adapter.d.mts +29 -0
  141. package/dist/nitro/adapter.mjs +93 -0
  142. package/dist/{utils/apollo.d.ts → nitro/apollo.d.mts} +3 -3
  143. package/dist/nitro/apollo.mjs +59 -0
  144. package/dist/nitro/codegen.d.mts +18 -0
  145. package/dist/nitro/codegen.mjs +173 -0
  146. package/dist/nitro/config.d.mts +50 -0
  147. package/dist/nitro/config.mjs +57 -0
  148. package/dist/nitro/index.d.mts +45 -0
  149. package/dist/nitro/index.mjs +65 -0
  150. package/dist/{utils/path-resolver.d.ts → nitro/paths.d.mts} +8 -25
  151. package/dist/{utils/path-resolver.js → nitro/paths.mjs} +14 -49
  152. package/dist/nitro/rollup.d.mts +6 -0
  153. package/dist/nitro/rollup.mjs +53 -0
  154. package/dist/nitro/routes/apollo-sandbox-script.d.mts +6 -0
  155. package/dist/nitro/routes/apollo-sandbox-script.mjs +14 -0
  156. package/dist/nitro/routes/apollo-server-ws.d.mts +15 -0
  157. package/dist/nitro/routes/apollo-server-ws.mjs +53 -0
  158. package/dist/nitro/routes/apollo-server.d.mts +6 -0
  159. package/dist/nitro/routes/apollo-server.mjs +71 -0
  160. package/dist/{routes/debug.d.ts → nitro/routes/debug.d.mts} +12 -19
  161. package/dist/nitro/routes/debug.mjs +102 -0
  162. package/dist/nitro/routes/graphql-yoga-ws.d.mts +12 -0
  163. package/dist/nitro/routes/graphql-yoga-ws.mjs +53 -0
  164. package/dist/nitro/routes/graphql-yoga.d.mts +12 -0
  165. package/dist/nitro/routes/graphql-yoga.mjs +41 -0
  166. package/dist/nitro/routes/health.d.mts +10 -0
  167. package/dist/{routes/health.js → nitro/routes/health.mjs} +4 -3
  168. package/dist/nitro/setup/extend-loader.d.mts +16 -0
  169. package/dist/nitro/setup/extend-loader.mjs +82 -0
  170. package/dist/nitro/setup/file-watcher.d.mts +18 -0
  171. package/dist/nitro/setup/file-watcher.mjs +63 -0
  172. package/dist/nitro/setup/logging.d.mts +16 -0
  173. package/dist/nitro/setup/logging.mjs +66 -0
  174. package/dist/nitro/setup/rollup-integration.d.mts +24 -0
  175. package/dist/nitro/setup/rollup-integration.mjs +63 -0
  176. package/dist/nitro/setup/routes.d.mts +13 -0
  177. package/dist/nitro/setup/routes.mjs +71 -0
  178. package/dist/nitro/setup/scanner.d.mts +59 -0
  179. package/dist/nitro/setup/scanner.mjs +120 -0
  180. package/dist/nitro/setup/ts-config.d.mts +10 -0
  181. package/dist/nitro/setup/ts-config.mjs +69 -0
  182. package/dist/nitro/setup.d.mts +11 -0
  183. package/dist/nitro/setup.mjs +191 -0
  184. package/dist/nitro/types.d.mts +549 -0
  185. package/dist/nitro/types.mjs +1 -0
  186. package/dist/nitro/virtual/generators.d.mts +38 -0
  187. package/dist/nitro/virtual/generators.mjs +192 -0
  188. package/dist/nitro/virtual/stubs.d.mts +21 -0
  189. package/dist/nitro/virtual/stubs.mjs +32 -0
  190. package/dist/{ecosystem/nuxt.d.ts → nuxt.d.mts} +1 -1
  191. package/dist/nuxt.mjs +112 -0
  192. package/dist/{graphql/server.d.ts → stubs/index.d.mts} +5 -1
  193. package/dist/stubs/index.mjs +1 -0
  194. package/dist/subscribe/index.d.mts +78 -0
  195. package/dist/subscribe/index.mjs +206 -0
  196. package/native/index.d.ts +20 -0
  197. package/native/index.js +585 -0
  198. package/package.json +201 -111
  199. package/dist/ecosystem/nuxt.js +0 -67
  200. package/dist/graphql/index.d.ts +0 -5
  201. package/dist/index.d.ts +0 -8
  202. package/dist/index.js +0 -318
  203. package/dist/rollup.js +0 -277
  204. package/dist/routes/apollo-server.d.ts +0 -6
  205. package/dist/routes/apollo-server.js +0 -89
  206. package/dist/routes/debug.js +0 -449
  207. package/dist/routes/graphql-yoga.d.ts +0 -6
  208. package/dist/routes/graphql-yoga.js +0 -91
  209. package/dist/routes/health.d.ts +0 -10
  210. package/dist/types/index.d.ts +0 -246
  211. package/dist/types/standard-schema.d.ts +0 -59
  212. package/dist/utils/apollo.js +0 -61
  213. package/dist/utils/client-codegen.d.ts +0 -38
  214. package/dist/utils/client-codegen.js +0 -290
  215. package/dist/utils/define.js +0 -57
  216. package/dist/utils/file-generator.d.ts +0 -37
  217. package/dist/utils/file-generator.js +0 -72
  218. package/dist/utils/index.d.ts +0 -39
  219. package/dist/utils/index.js +0 -278
  220. package/dist/utils/server-codegen.d.ts +0 -7
  221. package/dist/utils/server-codegen.js +0 -136
  222. package/dist/utils/type-generation.d.ts +0 -7
  223. package/dist/utils/type-generation.js +0 -360
  224. package/dist/virtual/debug-info.d.ts +0 -9
  225. package/dist/virtual/debug-info.js +0 -26
  226. package/dist/virtual/graphql-config.d.ts +0 -9
  227. package/dist/virtual/graphql-config.js +0 -10
  228. package/dist/virtual/module-config.d.ts +0 -9
  229. package/dist/virtual/module-config.js +0 -10
  230. package/dist/virtual/server-directives.d.ts +0 -11
  231. package/dist/virtual/server-directives.js +0 -10
  232. package/dist/virtual/server-resolvers.d.ts +0 -11
  233. package/dist/virtual/server-resolvers.js +0 -10
  234. package/dist/virtual/server-schemas.d.ts +0 -11
  235. package/dist/virtual/server-schemas.js +0 -10
  236. package/dist/vite.d.ts +0 -25
  237. package/dist/vite.js +0 -40
  238. /package/dist/{graphql/index.js → core/server/types.mjs} +0 -0
  239. /package/dist/{graphql/server.js → core/types/adapter.mjs} +0 -0
@@ -0,0 +1,42 @@
1
+ import { ClientCodegenConfig, ClientCodegenInput, ClientCodegenResult, ExternalServiceCodegenConfig } from "../types/codegen.mjs";
2
+ import { loadGraphQLDocuments } from "./document-loader.mjs";
3
+ import { GraphQLLoadSchemaOptions, GraphQLTypeDefPointer, downloadAndSaveSchema, graphQLLoadSchemaSync, loadExternalSchema } from "./schema-loader.mjs";
4
+ import { Source } from "@graphql-tools/utils";
5
+ import { GraphQLSchema } from "graphql";
6
+
7
+ //#region src/core/codegen/client.d.ts
8
+ /**
9
+ * Default client codegen configuration
10
+ */
11
+ declare const DEFAULT_CLIENT_CODEGEN_CONFIG: ClientCodegenConfig;
12
+ /**
13
+ * Generate client-side GraphQL types
14
+ * Pure function that generates TypeScript types from a GraphQL schema and documents
15
+ */
16
+ declare function generateClientTypesCore(input: ClientCodegenInput): Promise<ClientCodegenResult | false>;
17
+ /**
18
+ * Generate client types for external GraphQL service
19
+ */
20
+ declare function generateExternalClientTypesCore(service: ExternalServiceCodegenConfig, schema: GraphQLSchema, documents: Source[], virtualTypesPath?: string): Promise<ClientCodegenResult | false>;
21
+ /**
22
+ * Subscription info extracted from GraphQL documents
23
+ */
24
+ interface SubscriptionInfo {
25
+ /** Original operation name from GraphQL document (used for method names) */
26
+ name: string;
27
+ /** PascalCase version for type references (matches GraphQL codegen output) */
28
+ typeName: string;
29
+ fieldName: string;
30
+ hasVariables: boolean;
31
+ }
32
+ /**
33
+ * Extract subscription operations from GraphQL documents
34
+ */
35
+ declare function extractSubscriptions(docs: Source[]): SubscriptionInfo[];
36
+ /**
37
+ * Generate subscription builder code (Drizzle-style API) + Vue Composables
38
+ * Returns empty string if subscriptions are not enabled or no subscription operations found
39
+ */
40
+ declare function generateSubscriptionBuilder(docs: Source[], subscriptionsEnabled: boolean): string;
41
+ //#endregion
42
+ export { DEFAULT_CLIENT_CODEGEN_CONFIG, type GraphQLLoadSchemaOptions, type GraphQLTypeDefPointer, SubscriptionInfo, downloadAndSaveSchema, extractSubscriptions, generateClientTypesCore, generateExternalClientTypesCore, generateSubscriptionBuilder, graphQLLoadSchemaSync, loadExternalSchema, loadGraphQLDocuments };
@@ -0,0 +1,553 @@
1
+ import { DEFAULT_GRAPHQL_SCALARS } from "../constants.mjs";
2
+ import { pluginContent } from "./plugin.mjs";
3
+ import { loadGraphQLDocuments } from "./document-loader.mjs";
4
+ import { downloadAndSaveSchema, graphQLLoadSchemaSync, loadExternalSchema } from "./schema-loader.mjs";
5
+ import { defu as defu$1 } from "defu";
6
+ import consola from "consola";
7
+ import { codegen } from "@graphql-codegen/core";
8
+ import { preset } from "@graphql-codegen/import-types-preset";
9
+ import { plugin } from "@graphql-codegen/typed-document-node";
10
+ import { plugin as plugin$1 } from "@graphql-codegen/typescript";
11
+ import { plugin as plugin$2 } from "@graphql-codegen/typescript-generic-sdk";
12
+ import { plugin as plugin$3 } from "@graphql-codegen/typescript-operations";
13
+ import { printSchemaWithDirectives } from "@graphql-tools/utils";
14
+ import { Kind, parse } from "graphql";
15
+
16
+ //#region src/core/codegen/client.ts
17
+ /**
18
+ * Default client codegen configuration
19
+ */
20
+ const DEFAULT_CLIENT_CODEGEN_CONFIG = {
21
+ emitLegacyCommonJSImports: false,
22
+ useTypeImports: true,
23
+ enumsAsTypes: true,
24
+ strictScalars: true,
25
+ maybeValue: "T | null | undefined",
26
+ inputMaybeValue: "T | undefined",
27
+ documentMode: "string",
28
+ pureMagicComment: true,
29
+ dedupeOperationSuffix: true,
30
+ rawRequest: true,
31
+ scalars: DEFAULT_GRAPHQL_SCALARS
32
+ };
33
+ /**
34
+ * Generate generic SDK content for schema-only generation
35
+ */
36
+ function generateGenericSdkContent() {
37
+ return `// THIS FILE IS GENERATED, DO NOT EDIT!
38
+ /* eslint-disable eslint-comments/no-unlimited-disable */
39
+ /* tslint:disable */
40
+ /* eslint-disable */
41
+ /* prettier-ignore */
42
+
43
+ import type { GraphQLResolveInfo } from 'graphql'
44
+ export type RequireFields<T, K extends keyof T> = Omit<T, K> & { [P in K]-?: NonNullable<T[P]> }
45
+
46
+ export interface Requester<C = {}, E = unknown> {
47
+ <R, V>(doc: string, vars?: V, options?: C): Promise<R> | AsyncIterable<R>
48
+ }
49
+
50
+ export type Sdk = {
51
+ request: <R, V = Record<string, any>>(document: string, variables?: V) => Promise<R>
52
+ }
53
+
54
+ export function getSdk(requester: Requester): Sdk {
55
+ return {
56
+ request: <R, V = Record<string, any>>(document: string, variables?: V): Promise<R> => {
57
+ return requester<R, V>(document, variables)
58
+ }
59
+ }
60
+ }
61
+ `;
62
+ }
63
+ /**
64
+ * Generate client-side GraphQL types
65
+ * Pure function that generates TypeScript types from a GraphQL schema and documents
66
+ */
67
+ async function generateClientTypesCore(input) {
68
+ const { schema, schemaString, documents, config = {}, sdkConfig = {}, outputPath, serviceName, virtualTypesPath } = input;
69
+ if (documents.length === 0 && !serviceName) return false;
70
+ const schemaSDL = schemaString || (schema ? printSchemaWithDirectives(schema) : null);
71
+ if (!schemaSDL) return false;
72
+ const mergedConfig = defu$1(DEFAULT_CLIENT_CODEGEN_CONFIG, config);
73
+ const mergedSdkConfig = defu$1(mergedConfig, sdkConfig);
74
+ try {
75
+ if (documents.length === 0) return {
76
+ types: await codegen({
77
+ filename: outputPath || "client-types.generated.ts",
78
+ schema: parse(schemaSDL),
79
+ documents: [],
80
+ config: mergedConfig,
81
+ plugins: [{ pluginContent: {} }, { typescript: {} }],
82
+ pluginMap: {
83
+ pluginContent: { plugin: pluginContent },
84
+ typescript: { plugin: plugin$1 }
85
+ }
86
+ }),
87
+ sdk: generateGenericSdkContent()
88
+ };
89
+ const enableTypedDocumentNode = config.typedDocumentNode === true;
90
+ const plugins = [
91
+ { pluginContent: {} },
92
+ { typescript: {} },
93
+ { typescriptOperations: {} }
94
+ ];
95
+ const pluginMap = {
96
+ pluginContent: { plugin: pluginContent },
97
+ typescript: { plugin: plugin$1 },
98
+ typescriptOperations: { plugin: plugin$3 }
99
+ };
100
+ if (enableTypedDocumentNode) {
101
+ plugins.push({ typedDocumentNode: {} });
102
+ pluginMap.typedDocumentNode = { plugin };
103
+ }
104
+ const output = await codegen({
105
+ filename: outputPath || "client-types.generated.ts",
106
+ schema: parse(schemaSDL),
107
+ documents: [...documents],
108
+ config: mergedConfig,
109
+ plugins,
110
+ pluginMap
111
+ });
112
+ const typesPath = virtualTypesPath || (serviceName ? `#graphql/client/${serviceName}` : "#graphql/client");
113
+ const sdkOutput = await preset.buildGeneratesSection({
114
+ baseOutputDir: outputPath || "client-types.generated.ts",
115
+ schema: parse(schemaSDL),
116
+ documents: [...documents],
117
+ config: mergedSdkConfig,
118
+ presetConfig: { typesPath },
119
+ plugins: [{ pluginContent: {} }, { typescriptGenericSdk: {} }],
120
+ pluginMap: {
121
+ pluginContent: { plugin: pluginContent },
122
+ typescriptGenericSdk: { plugin: plugin$2 }
123
+ }
124
+ });
125
+ return {
126
+ types: output,
127
+ sdk: (await Promise.all(sdkOutput.map(async (config) => {
128
+ return {
129
+ file: config.filename,
130
+ content: await codegen(config)
131
+ };
132
+ })))[0]?.content || ""
133
+ };
134
+ } catch (error) {
135
+ consola.error("[nitro-graphql] Client type generation failed:", error.message);
136
+ return false;
137
+ }
138
+ }
139
+ /**
140
+ * Generate client types for external GraphQL service
141
+ */
142
+ async function generateExternalClientTypesCore(service, schema, documents, virtualTypesPath) {
143
+ return generateClientTypesCore({
144
+ schema,
145
+ documents,
146
+ config: service.codegen?.client || {},
147
+ sdkConfig: service.codegen?.clientSDK || {},
148
+ serviceName: service.name,
149
+ virtualTypesPath
150
+ });
151
+ }
152
+ /**
153
+ * Convert first character to uppercase (PascalCase)
154
+ */
155
+ function toPascalCase(str) {
156
+ return str.charAt(0).toUpperCase() + str.slice(1);
157
+ }
158
+ /**
159
+ * Extract subscription operations from GraphQL documents
160
+ */
161
+ function extractSubscriptions(docs) {
162
+ const subscriptions = [];
163
+ for (const doc of docs) {
164
+ if (!doc.document) continue;
165
+ for (const def of doc.document.definitions) if (def.kind === Kind.OPERATION_DEFINITION && def.operation === "subscription") {
166
+ const operationDef = def;
167
+ const name = operationDef.name?.value;
168
+ if (!name) continue;
169
+ const firstSelection = operationDef.selectionSet.selections[0];
170
+ if (firstSelection.kind !== Kind.FIELD) continue;
171
+ const fieldName = firstSelection.name.value;
172
+ const hasVariables = (operationDef.variableDefinitions?.length || 0) > 0;
173
+ subscriptions.push({
174
+ name,
175
+ typeName: toPascalCase(name),
176
+ fieldName,
177
+ hasVariables
178
+ });
179
+ }
180
+ }
181
+ return subscriptions;
182
+ }
183
+ /**
184
+ * Generate subscription builder code (Drizzle-style API) + Vue Composables
185
+ * Returns empty string if subscriptions are not enabled or no subscription operations found
186
+ */
187
+ function generateSubscriptionBuilder(docs, subscriptionsEnabled) {
188
+ if (!subscriptionsEnabled) return "";
189
+ const subscriptions = extractSubscriptions(docs);
190
+ if (subscriptions.length === 0) return "";
191
+ let output = `
192
+ // === Subscription Imports ===
193
+ import { ref, onUnmounted, computed } from 'vue'
194
+ import type { Ref } from 'vue'
195
+ import type {
196
+ ConnectionState,
197
+ SubscriptionHandle,
198
+ SubscriptionSession,
199
+ SubscriptionTransport,
200
+ TransportOptions,
201
+ } from 'nitro-graphql/subscribe'
202
+ import { subscriptionClient } from './subscribe'
203
+
204
+ // === Subscription Types ===
205
+ export type { ConnectionState, SubscriptionHandle, SubscriptionSession, SubscriptionTransport, TransportOptions }
206
+
207
+ // Forward declaration for UseSubscriptionSessionReturn (defined below)
208
+ export interface UseSubscriptionSessionReturn {
209
+ /** The underlying session object */
210
+ session: SubscriptionSession
211
+ /** Subscribe using the shared session (updates reactive refs) */
212
+ subscribe: <TData = unknown>(
213
+ query: string,
214
+ variables: unknown,
215
+ onData?: (data: TData) => void,
216
+ onError?: (error: Error) => void,
217
+ ) => SubscriptionHandle
218
+ /** Close all subscriptions and the connection */
219
+ close: () => void
220
+ /** Is the session connected (reactive) */
221
+ isConnected: Ref<boolean>
222
+ /** Current connection state (reactive) */
223
+ state: Ref<ConnectionState>
224
+ /** Number of active subscriptions (reactive) */
225
+ subscriptionCount: Ref<number>
226
+ }
227
+
228
+ export interface UseSubscriptionOptions<T> {
229
+ /** Auto-start subscription on mount (default: false) */
230
+ immediate?: boolean
231
+ /** Callback when subscription starts */
232
+ onStart?: () => void
233
+ /** Callback when subscription stops */
234
+ onStop?: () => void
235
+ /** Callback when data is received */
236
+ onData?: (data: T) => void
237
+ /** Callback when error occurs */
238
+ onError?: (error: Error) => void
239
+ /** Callback when WebSocket connects */
240
+ onConnected?: () => void
241
+ /** Callback when WebSocket reconnects */
242
+ onReconnected?: () => void
243
+ /** Callback when WebSocket disconnects */
244
+ onDisconnected?: () => void
245
+ /** Callback when connection state changes */
246
+ onStateChange?: (state: ConnectionState) => void
247
+ /** Use existing session for multiplexing (pass result from useSubscriptionSession) */
248
+ session?: UseSubscriptionSessionReturn
249
+ /** Transport type: 'websocket' (default), 'sse', or 'auto' (WS first, SSE fallback) */
250
+ transport?: SubscriptionTransport
251
+ }
252
+
253
+ export interface UseSubscriptionReturn<T> {
254
+ /** Reactive subscription data */
255
+ data: Ref<T | null>
256
+ /** Reactive error state */
257
+ error: Ref<Error | null>
258
+ /** Is subscription active */
259
+ isActive: Ref<boolean>
260
+ /** Connection state */
261
+ state: Ref<ConnectionState>
262
+ /** Active transport type ('websocket' | 'sse') */
263
+ transport: Ref<'websocket' | 'sse'>
264
+ /** Start subscription */
265
+ start: () => void
266
+ /** Stop subscription */
267
+ stop: () => void
268
+ /** Restart subscription */
269
+ restart: () => void
270
+ }
271
+
272
+ // === Subscription Builder (Drizzle-style API) ===
273
+ interface SubscriptionBuilder<TData> {
274
+ onData(fn: (data: TData) => void): SubscriptionBuilder<TData>
275
+ onError(fn: (error: Error) => void): SubscriptionBuilder<TData>
276
+ start(): SubscriptionHandle
277
+ subscribe(fn: (data: TData) => void): SubscriptionHandle
278
+ }
279
+
280
+ function createSubscriptionBuilder<TData>(query: string, variables: unknown): SubscriptionBuilder<TData> {
281
+ let onDataFn: ((data: TData) => void) | undefined
282
+ let onErrorFn: ((error: Error) => void) | undefined
283
+
284
+ const builder: SubscriptionBuilder<TData> = {
285
+ onData(fn: (data: TData) => void) {
286
+ onDataFn = fn
287
+ return builder
288
+ },
289
+ onError(fn: (error: Error) => void) {
290
+ onErrorFn = fn
291
+ return builder
292
+ },
293
+ start(): SubscriptionHandle {
294
+ return subscriptionClient.subscribe(query, variables, onDataFn, onErrorFn)
295
+ },
296
+ subscribe(fn: (data: TData) => void): SubscriptionHandle {
297
+ return subscriptionClient.subscribe(query, variables, fn, undefined)
298
+ },
299
+ }
300
+
301
+ return builder
302
+ }
303
+
304
+ export const subscription = {
305
+ `;
306
+ for (const sub of subscriptions) if (sub.hasVariables) output += ` ${sub.typeName}(variables: Types.${sub.typeName}SubscriptionVariables): SubscriptionBuilder<Types.${sub.typeName}Subscription['${sub.fieldName}']> {
307
+ return createSubscriptionBuilder<Types.${sub.typeName}Subscription['${sub.fieldName}']>(${sub.typeName}Document, variables)
308
+ },
309
+ `;
310
+ else output += ` ${sub.typeName}(): SubscriptionBuilder<Types.${sub.typeName}Subscription['${sub.fieldName}']> {
311
+ return createSubscriptionBuilder<Types.${sub.typeName}Subscription['${sub.fieldName}']>(${sub.typeName}Document, undefined)
312
+ },
313
+ `;
314
+ output += `}
315
+
316
+ // === Framework-Agnostic Session (for non-Vue usage) ===
317
+ /**
318
+ * Create a multiplexed subscription session (framework-agnostic)
319
+ * All subscriptions share a single WebSocket connection.
320
+ *
321
+ * @example
322
+ * // Vanilla JS / Node.js / React / etc.
323
+ * const session = createSubscriptionSession()
324
+ * const sub1 = session.subscribe(query1, vars1, onData1)
325
+ * const sub2 = session.subscribe(query2, vars2, onData2)
326
+ * // Both use the same WebSocket connection
327
+ * sub1.unsubscribe()
328
+ * session.close() // Close all
329
+ *
330
+ * @returns SubscriptionSession - Framework-agnostic session object
331
+ */
332
+ export function createSubscriptionSession(): SubscriptionSession {
333
+ return subscriptionClient.createSession()
334
+ }
335
+
336
+ // === Vue Composable: useSubscriptionSession (Multiplexing) ===
337
+ export interface UseSubscriptionSessionReturn {
338
+ /** The underlying session object */
339
+ session: SubscriptionSession
340
+ /** Subscribe using the shared session */
341
+ subscribe: <TData = unknown>(
342
+ query: string,
343
+ variables: unknown,
344
+ onData?: (data: TData) => void,
345
+ onError?: (error: Error) => void,
346
+ ) => SubscriptionHandle
347
+ /** Close all subscriptions and the connection */
348
+ close: () => void
349
+ /** Is the session connected (reactive) */
350
+ isConnected: Ref<boolean>
351
+ /** Current connection state (reactive) */
352
+ state: Ref<ConnectionState>
353
+ /** Number of active subscriptions (reactive) */
354
+ subscriptionCount: Ref<number>
355
+ }
356
+
357
+ /**
358
+ * Vue composable for multiplexed subscription session
359
+ * Provides reactive state and automatic cleanup on unmount.
360
+ *
361
+ * @example
362
+ * // Vue 3 component
363
+ * const session = useSubscriptionSession()
364
+ * const { data } = useCountdown({ from: 10 }, { session })
365
+ * // Session auto-closes on component unmount
366
+ *
367
+ * @returns UseSubscriptionSessionReturn - Vue-reactive session wrapper
368
+ */
369
+ export function useSubscriptionSession(): UseSubscriptionSessionReturn {
370
+ const session = subscriptionClient.createSession()
371
+
372
+ // Use refs for reactivity (session getters are not reactive)
373
+ const isConnected = ref(session.isConnected)
374
+ const state = ref<ConnectionState>(session.state)
375
+ const subscriptionCount = ref(session.subscriptionCount)
376
+
377
+ // Update refs when session state changes
378
+ function updateRefs() {
379
+ isConnected.value = session.isConnected
380
+ state.value = session.state
381
+ subscriptionCount.value = session.subscriptionCount
382
+ }
383
+
384
+ // Subscribe to session state changes for automatic reactivity
385
+ const unsubscribeStateChange = session.onStateChange(() => {
386
+ updateRefs()
387
+ })
388
+
389
+ function subscribe<TData = unknown>(
390
+ query: string,
391
+ variables: unknown,
392
+ onData?: (data: TData) => void,
393
+ onError?: (error: Error) => void,
394
+ ): SubscriptionHandle {
395
+ return session.subscribe(query, variables, onData as (data: unknown) => void, onError)
396
+ }
397
+
398
+ function close() {
399
+ session.close()
400
+ }
401
+
402
+ onUnmounted(() => {
403
+ unsubscribeStateChange()
404
+ close()
405
+ })
406
+
407
+ return {
408
+ session,
409
+ subscribe,
410
+ close,
411
+ isConnected,
412
+ state,
413
+ subscriptionCount,
414
+ }
415
+ }
416
+
417
+ // === Vue Composables ===
418
+ function createUseSubscription<TData, TVariables = undefined>(
419
+ query: string,
420
+ getVariables: () => TVariables,
421
+ ): (options?: UseSubscriptionOptions<TData>) => UseSubscriptionReturn<TData> {
422
+ return (options: UseSubscriptionOptions<TData> = {}): UseSubscriptionReturn<TData> => {
423
+ const data = ref<TData | null>(null) as Ref<TData | null>
424
+ const error = ref<Error | null>(null)
425
+ const isActive = ref(false)
426
+ const state = ref<ConnectionState>('idle')
427
+ const transport = ref<'websocket' | 'sse'>('websocket')
428
+ let handle: SubscriptionHandle | null = null
429
+
430
+ // Resolve transport options
431
+ const transportOptions: TransportOptions = {
432
+ transport: options.transport,
433
+ }
434
+
435
+ function start() {
436
+ stop()
437
+ isActive.value = true
438
+ error.value = null
439
+ options.onStart?.()
440
+
441
+ const variables = getVariables()
442
+
443
+ if (options.session) {
444
+ // Use existing session for multiplexing (WebSocket only)
445
+ handle = options.session.subscribe<TData>(
446
+ query,
447
+ variables,
448
+ (d: TData) => {
449
+ data.value = d
450
+ options.onData?.(d)
451
+ },
452
+ (e: Error) => {
453
+ error.value = e
454
+ options.onError?.(e)
455
+ },
456
+ )
457
+ transport.value = 'websocket'
458
+ } else {
459
+ // Create dedicated connection with transport selection
460
+ handle = subscriptionClient.subscribe<TData>(
461
+ query,
462
+ variables,
463
+ (d: TData) => {
464
+ data.value = d
465
+ options.onData?.(d)
466
+ },
467
+ (e: Error) => {
468
+ error.value = e
469
+ options.onError?.(e)
470
+ },
471
+ transportOptions,
472
+ )
473
+ // Update transport ref from handle
474
+ transport.value = handle.transport
475
+ }
476
+ }
477
+
478
+ function stop() {
479
+ if (handle) {
480
+ handle.unsubscribe()
481
+ handle = null
482
+ isActive.value = false
483
+ options.onStop?.()
484
+ }
485
+ }
486
+
487
+ function restart() {
488
+ stop()
489
+ start()
490
+ }
491
+
492
+ if (options.immediate) {
493
+ start()
494
+ }
495
+
496
+ onUnmounted(stop)
497
+
498
+ return { data, error, isActive, state, transport, start, stop, restart }
499
+ }
500
+ }
501
+
502
+ // === Subscription Return Types ===
503
+ `;
504
+ for (const sub of subscriptions) {
505
+ const typeName = `Types.${sub.typeName}Subscription['${sub.fieldName}']`;
506
+ output += `/** Return type for use${sub.typeName} composable */
507
+ export type Use${sub.typeName}Return = UseSubscriptionReturn<${typeName}>
508
+ `;
509
+ }
510
+ output += `
511
+ // === Vue Composables ===
512
+ `;
513
+ for (const sub of subscriptions) {
514
+ const typeName = `Types.${sub.typeName}Subscription['${sub.fieldName}']`;
515
+ const varsType = `Types.${sub.typeName}SubscriptionVariables`;
516
+ if (sub.hasVariables) output += `/**
517
+ * Vue composable for ${sub.typeName} subscription
518
+ * @param variables - Subscription variables
519
+ * @param options - Subscription options (immediate, onData, onError, session, etc.)
520
+ * @returns Reactive subscription state: { data, error, isActive, state, start, stop, restart }
521
+ */
522
+ export function use${sub.typeName}(
523
+ variables: ${varsType},
524
+ options?: UseSubscriptionOptions<${typeName}>,
525
+ ): Use${sub.typeName}Return {
526
+ return createUseSubscription<${typeName}, ${varsType}>(
527
+ ${sub.typeName}Document,
528
+ () => variables,
529
+ )(options)
530
+ }
531
+
532
+ `;
533
+ else output += `/**
534
+ * Vue composable for ${sub.typeName} subscription
535
+ * @param options - Subscription options (immediate, onData, onError, session, etc.)
536
+ * @returns Reactive subscription state: { data, error, isActive, state, start, stop, restart }
537
+ */
538
+ export function use${sub.typeName}(
539
+ options?: UseSubscriptionOptions<${typeName}>,
540
+ ): Use${sub.typeName}Return {
541
+ return createUseSubscription<${typeName}, undefined>(
542
+ ${sub.typeName}Document,
543
+ () => undefined,
544
+ )(options)
545
+ }
546
+
547
+ `;
548
+ }
549
+ return output;
550
+ }
551
+
552
+ //#endregion
553
+ export { DEFAULT_CLIENT_CODEGEN_CONFIG, downloadAndSaveSchema, extractSubscriptions, generateClientTypesCore, generateExternalClientTypesCore, generateSubscriptionBuilder, graphQLLoadSchemaSync, loadExternalSchema, loadGraphQLDocuments };
@@ -0,0 +1,9 @@
1
+ import { Source } from "@graphql-tools/utils";
2
+
3
+ //#region src/core/codegen/document-loader.d.ts
4
+ /**
5
+ * Load GraphQL documents from files
6
+ */
7
+ declare function loadGraphQLDocuments(patterns: string | string[]): Promise<Source[]>;
8
+ //#endregion
9
+ export { loadGraphQLDocuments };
@@ -0,0 +1,18 @@
1
+ import { GraphQLFileLoader } from "@graphql-tools/graphql-file-loader";
2
+ import { loadDocuments } from "@graphql-tools/load";
3
+
4
+ //#region src/core/codegen/document-loader.ts
5
+ /**
6
+ * Load GraphQL documents from files
7
+ */
8
+ async function loadGraphQLDocuments(patterns) {
9
+ try {
10
+ return await loadDocuments(patterns, { loaders: [new GraphQLFileLoader()] });
11
+ } catch (e) {
12
+ if ((e.message || "").includes("Unable to find any GraphQL type definitions for the following pointers:")) return [];
13
+ throw e;
14
+ }
15
+ }
16
+
17
+ //#endregion
18
+ export { loadGraphQLDocuments };
@@ -0,0 +1,8 @@
1
+ import { loadGraphQLDocuments } from "./document-loader.mjs";
2
+ import { GraphQLLoadSchemaOptions, GraphQLTypeDefPointer, downloadAndSaveSchema, graphQLLoadSchemaSync, loadExternalSchema } from "./schema-loader.mjs";
3
+ import { DEFAULT_CLIENT_CODEGEN_CONFIG, SubscriptionInfo, extractSubscriptions, generateClientTypesCore, generateExternalClientTypesCore, generateSubscriptionBuilder } from "./client.mjs";
4
+ import { GENERATED_FILE_HEADER, pluginContent } from "./plugin.mjs";
5
+ import { generateResolverModule, generateRuntimeIndex, generateSchemaModule } from "./runtime.mjs";
6
+ import { DEFAULT_SERVER_CODEGEN_CONFIG, generateServerTypesCore, generateTypes } from "./server.mjs";
7
+ import { validateNoDuplicateTypes, validateSchemaFiles } from "./validation.mjs";
8
+ export { DEFAULT_CLIENT_CODEGEN_CONFIG, DEFAULT_SERVER_CODEGEN_CONFIG, GENERATED_FILE_HEADER, type GraphQLLoadSchemaOptions, type GraphQLTypeDefPointer, type SubscriptionInfo, downloadAndSaveSchema, extractSubscriptions, generateClientTypesCore, generateExternalClientTypesCore, generateResolverModule, generateRuntimeIndex, generateSchemaModule, generateServerTypesCore, generateSubscriptionBuilder, generateTypes, graphQLLoadSchemaSync, loadExternalSchema, loadGraphQLDocuments, pluginContent, validateNoDuplicateTypes, validateSchemaFiles };
@@ -0,0 +1,9 @@
1
+ import { GENERATED_FILE_HEADER, pluginContent } from "./plugin.mjs";
2
+ import { loadGraphQLDocuments } from "./document-loader.mjs";
3
+ import { downloadAndSaveSchema, graphQLLoadSchemaSync, loadExternalSchema } from "./schema-loader.mjs";
4
+ import { DEFAULT_CLIENT_CODEGEN_CONFIG, extractSubscriptions, generateClientTypesCore, generateExternalClientTypesCore, generateSubscriptionBuilder } from "./client.mjs";
5
+ import { generateResolverModule, generateRuntimeIndex, generateSchemaModule } from "./runtime.mjs";
6
+ import { DEFAULT_SERVER_CODEGEN_CONFIG, generateServerTypesCore, generateTypes } from "./server.mjs";
7
+ import { validateNoDuplicateTypes, validateSchemaFiles } from "./validation.mjs";
8
+
9
+ export { DEFAULT_CLIENT_CODEGEN_CONFIG, DEFAULT_SERVER_CODEGEN_CONFIG, GENERATED_FILE_HEADER, downloadAndSaveSchema, extractSubscriptions, generateClientTypesCore, generateExternalClientTypesCore, generateResolverModule, generateRuntimeIndex, generateSchemaModule, generateServerTypesCore, generateSubscriptionBuilder, generateTypes, graphQLLoadSchemaSync, loadExternalSchema, loadGraphQLDocuments, pluginContent, validateNoDuplicateTypes, validateSchemaFiles };
@@ -0,0 +1,19 @@
1
+ import { Source } from "@graphql-tools/utils";
2
+ import { GraphQLSchema } from "graphql";
3
+
4
+ //#region src/core/codegen/plugin.d.ts
5
+ /**
6
+ * Plugin to add prepend comments to generated files
7
+ * Used by both server and client codegen
8
+ */
9
+ declare function pluginContent(_schema: GraphQLSchema, _documents: Source[], _config: Record<string, unknown> | undefined, _info: Record<string, unknown> | undefined): {
10
+ prepend: string[];
11
+ content: string;
12
+ };
13
+ /**
14
+ * Generate the prepend header for generated files
15
+ * Can be used when creating files manually without codegen
16
+ */
17
+ declare const GENERATED_FILE_HEADER = "// THIS FILE IS GENERATED, DO NOT EDIT!\n/* eslint-disable eslint-comments/no-unlimited-disable */\n/* tslint:disable */\n/* eslint-disable */\n/* prettier-ignore */\n";
18
+ //#endregion
19
+ export { GENERATED_FILE_HEADER, pluginContent };
@@ -0,0 +1,30 @@
1
+ //#region src/core/codegen/plugin.ts
2
+ /**
3
+ * Plugin to add prepend comments to generated files
4
+ * Used by both server and client codegen
5
+ */
6
+ function pluginContent(_schema, _documents, _config, _info) {
7
+ return {
8
+ prepend: [
9
+ "// THIS FILE IS GENERATED, DO NOT EDIT!",
10
+ "/* eslint-disable eslint-comments/no-unlimited-disable */",
11
+ "/* tslint:disable */",
12
+ "/* eslint-disable */",
13
+ "/* prettier-ignore */"
14
+ ],
15
+ content: ""
16
+ };
17
+ }
18
+ /**
19
+ * Generate the prepend header for generated files
20
+ * Can be used when creating files manually without codegen
21
+ */
22
+ const GENERATED_FILE_HEADER = `// THIS FILE IS GENERATED, DO NOT EDIT!
23
+ /* eslint-disable eslint-comments/no-unlimited-disable */
24
+ /* tslint:disable */
25
+ /* eslint-disable */
26
+ /* prettier-ignore */
27
+ `;
28
+
29
+ //#endregion
30
+ export { GENERATED_FILE_HEADER, pluginContent };