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

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