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,192 @@
1
+ import { resolve } from "pathe";
2
+ import { existsSync, readFileSync } from "node:fs";
3
+ import { genImport } from "knitwork";
4
+
5
+ //#region src/nitro/virtual/generators.ts
6
+ function generateImportModule(items, exportName, wrapperKey) {
7
+ if (!items.length) return `export const ${exportName} = []`;
8
+ const imports = items.flatMap(({ specifier, imports: list, options }) => list?.length ? [genImport(specifier, list, options)] : []);
9
+ const data = items.flatMap(({ imports: list }) => list.map((i) => `{ ${wrapperKey}: ${i.as || i.name} }`));
10
+ return `${imports.join("\n")}\n\nexport const ${exportName} = [\n${data.join(",\n")}\n]`;
11
+ }
12
+ function safeGenerateModuleCode(nitro, moduleName) {
13
+ try {
14
+ const generator = nitro.options.virtual?.[moduleName];
15
+ if (generator && typeof generator === "function") return generator();
16
+ return "// Module not found";
17
+ } catch (error) {
18
+ return `// Error: ${error instanceof Error ? error.message : String(error)}`;
19
+ }
20
+ }
21
+ const serverSchemas = {
22
+ id: "#nitro-graphql/server-schemas",
23
+ getCode: (nitro) => {
24
+ const schemas = [...nitro.scanSchemas, ...nitro.options.graphql?.typedefs ?? []];
25
+ const directiveSchemas = nitro.graphql.directiveSchemas;
26
+ if (!schemas.length && !directiveSchemas) {
27
+ if (nitro.options.dev) nitro.logger.warn(`[nitro-graphql] No schemas found. Using demo schema. Add .graphql files to ${nitro.graphql.serverDir}`);
28
+ return `export const schemas = [
29
+ { def: \`type Query {
30
+ hello: String!
31
+ }
32
+ \` }
33
+ ]`;
34
+ }
35
+ const schemaArray = schemas.map((schemaPath) => {
36
+ try {
37
+ const content = readFileSync(schemaPath, "utf-8");
38
+ return `{ def: ${JSON.stringify(content)} }`;
39
+ } catch {
40
+ return `{ def: '' }`;
41
+ }
42
+ });
43
+ if (directiveSchemas) schemaArray.push(`{ def: ${JSON.stringify(directiveSchemas)} }`);
44
+ return `export const schemas = [\n${schemaArray.join(",\n")}\n];`;
45
+ }
46
+ };
47
+ const serverResolvers = {
48
+ id: "#nitro-graphql/server-resolvers",
49
+ getCode: (nitro) => {
50
+ const imports = [...nitro.scanResolvers];
51
+ if (!imports.length) {
52
+ if (nitro.options.dev) nitro.logger.warn(`[nitro-graphql] No resolvers found. Using demo resolver. Add .resolver.ts files to ${nitro.graphql.serverDir}`);
53
+ return `export const resolvers = [
54
+ { resolver: { Query: { hello: () => 'Hello from nitro-graphql!' } } }
55
+ ]`;
56
+ }
57
+ return generateImportModule(imports, "resolvers", "resolver");
58
+ }
59
+ };
60
+ const serverDirectives = {
61
+ id: "#nitro-graphql/server-directives",
62
+ getCode: (nitro) => {
63
+ const imports = nitro.scanDirectives || [];
64
+ if (!imports.length) return "export const directives = []";
65
+ return generateImportModule(imports, "directives", "directive");
66
+ }
67
+ };
68
+ const graphqlConfig = {
69
+ id: "#nitro-graphql/graphql-config",
70
+ getCode: (nitro) => {
71
+ const localConfigPath = resolve(nitro.graphql.serverDir, "config.ts");
72
+ const extendConfigs = nitro.graphql.extendConfigs || [];
73
+ const hasLocalConfig = existsSync(localConfigPath);
74
+ if (!hasLocalConfig && extendConfigs.length === 0) return `const importedConfig = {}
75
+ export { importedConfig }
76
+ `;
77
+ const imports = ["import { defu } from 'defu'"];
78
+ const configNames = [];
79
+ extendConfigs.forEach((configPath, index) => {
80
+ const configName = `extendConfig${index}`;
81
+ imports.push(`import ${configName} from '${configPath}'`);
82
+ configNames.push(configName);
83
+ });
84
+ if (hasLocalConfig) {
85
+ imports.push(`import localConfig from '${localConfigPath}'`);
86
+ configNames.push("localConfig");
87
+ }
88
+ const mergeArgs = configNames.reverse().join(", ");
89
+ return `${imports.join("\n")}
90
+
91
+ const importedConfig = defu(${mergeArgs})
92
+ export { importedConfig }
93
+ `;
94
+ }
95
+ };
96
+ const moduleConfig = {
97
+ id: "#nitro-graphql/module-config",
98
+ getCode: (nitro) => {
99
+ const config = nitro.options.graphql || {};
100
+ return `export const moduleConfig = ${JSON.stringify(config, null, 2)};`;
101
+ }
102
+ };
103
+ const validationSchemas = {
104
+ id: "#nitro-graphql/validation-schemas",
105
+ getCode: (nitro) => {
106
+ const localSchemaPath = resolve(nitro.graphql.serverDir, "schema.ts");
107
+ const extendSchemas = nitro.graphql.extendSchemas || [];
108
+ const hasLocalSchema = existsSync(localSchemaPath);
109
+ if (!hasLocalSchema && extendSchemas.length === 0) return `const mergedSchemas = {}
110
+ export default mergedSchemas
111
+ `;
112
+ const imports = [];
113
+ const schemaNames = [];
114
+ extendSchemas.forEach((schemaPath, index) => {
115
+ const schemaName = `extendSchema${index}`;
116
+ imports.push(`import ${schemaName} from '${schemaPath}'`);
117
+ schemaNames.push(schemaName);
118
+ });
119
+ if (hasLocalSchema) {
120
+ imports.push(`import localSchema from '${localSchemaPath}'`);
121
+ schemaNames.push("localSchema");
122
+ }
123
+ const mergeExpression = schemaNames.length === 1 ? schemaNames[0] : `{ ${schemaNames.map((name) => `...${name}`).join(", ")} }`;
124
+ return `${imports.join("\n")}
125
+
126
+ const mergedSchemas = ${mergeExpression}
127
+ export default mergedSchemas
128
+ `;
129
+ }
130
+ };
131
+ const pubsub = {
132
+ id: "#nitro-graphql/pubsub",
133
+ getCode: (nitro) => {
134
+ const subscriptions = nitro.options.graphql?.subscriptions;
135
+ const pubsubConfig = subscriptions?.pubsub;
136
+ if (!subscriptions?.enabled) return `export const pubsub = null`;
137
+ if (pubsubConfig?.customPath) return `import customPubSub from '${pubsubConfig.customPath}'
138
+ export const pubsub = customPubSub
139
+ `;
140
+ return `import { createPubSub } from 'nitro-graphql/pubsub'
141
+ export const pubsub = createPubSub()
142
+ `;
143
+ }
144
+ };
145
+ const debugInfo = {
146
+ id: "#nitro-graphql/debug-info",
147
+ getCode: (nitro) => {
148
+ const virtualModuleCodes = {
149
+ "server-schemas": safeGenerateModuleCode(nitro, "#nitro-graphql/server-schemas"),
150
+ "server-resolvers": safeGenerateModuleCode(nitro, "#nitro-graphql/server-resolvers"),
151
+ "server-directives": safeGenerateModuleCode(nitro, "#nitro-graphql/server-directives"),
152
+ "module-config": safeGenerateModuleCode(nitro, "#nitro-graphql/module-config"),
153
+ "graphql-config": safeGenerateModuleCode(nitro, "#nitro-graphql/graphql-config"),
154
+ "pubsub": safeGenerateModuleCode(nitro, "#nitro-graphql/pubsub")
155
+ };
156
+ const info = {
157
+ isDev: nitro.options.dev,
158
+ framework: nitro.options.framework.name,
159
+ graphqlFramework: nitro.options.graphql?.framework,
160
+ federation: nitro.options.graphql?.federation,
161
+ scanned: {
162
+ schemas: nitro.scanSchemas?.length || 0,
163
+ schemaFiles: nitro.scanSchemas || [],
164
+ resolvers: nitro.scanResolvers?.length || 0,
165
+ resolverFiles: nitro.scanResolvers || [],
166
+ directives: nitro.scanDirectives?.length || 0,
167
+ directiveFiles: nitro.scanDirectives || [],
168
+ documents: nitro.scanDocuments?.length || 0,
169
+ documentFiles: nitro.scanDocuments || []
170
+ },
171
+ virtualModules: virtualModuleCodes
172
+ };
173
+ return `export const debugInfo = ${JSON.stringify(info, null, 2)};`;
174
+ }
175
+ };
176
+ const allModules = [
177
+ serverSchemas,
178
+ serverResolvers,
179
+ serverDirectives,
180
+ graphqlConfig,
181
+ moduleConfig,
182
+ validationSchemas,
183
+ pubsub,
184
+ debugInfo
185
+ ];
186
+ function registerAllVirtualModules(nitro) {
187
+ nitro.options.virtual ??= {};
188
+ for (const mod of allModules) nitro.options.virtual[mod.id] = () => mod.getCode(nitro);
189
+ }
190
+
191
+ //#endregion
192
+ export { debugInfo, graphqlConfig, moduleConfig, pubsub, registerAllVirtualModules, serverDirectives, serverResolvers, serverSchemas, validationSchemas };
@@ -0,0 +1,21 @@
1
+ //#region src/nitro/virtual/stubs.d.ts
2
+ /**
3
+ * Virtual module stubs for #nitro-graphql/*
4
+ * Used during build to prevent import resolution errors.
5
+ * At runtime, Nitro overrides these with actual virtual modules.
6
+ */
7
+ declare const schemas: Array<{
8
+ def: string;
9
+ }>;
10
+ declare const resolvers: Array<{
11
+ resolver: any;
12
+ }>;
13
+ declare const directives: Array<{
14
+ directive: any;
15
+ }>;
16
+ declare const moduleConfig: {};
17
+ declare const importedConfig: {};
18
+ declare const debugInfo: Record<string, any>;
19
+ declare const pubsub: any;
20
+ //#endregion
21
+ export { debugInfo, directives, importedConfig, moduleConfig, pubsub, resolvers, schemas };
@@ -0,0 +1,32 @@
1
+ //#region src/nitro/virtual/stubs.ts
2
+ /**
3
+ * Virtual module stubs for #nitro-graphql/*
4
+ * Used during build to prevent import resolution errors.
5
+ * At runtime, Nitro overrides these with actual virtual modules.
6
+ */
7
+ const schemas = [];
8
+ const resolvers = [];
9
+ const directives = [];
10
+ const moduleConfig = {};
11
+ const importedConfig = {};
12
+ const debugInfo = {
13
+ isDev: false,
14
+ framework: "",
15
+ graphqlFramework: "",
16
+ federation: {},
17
+ scanned: {
18
+ schemas: 0,
19
+ schemaFiles: [],
20
+ resolvers: 0,
21
+ resolverFiles: [],
22
+ directives: 0,
23
+ directiveFiles: [],
24
+ documents: 0,
25
+ documentFiles: []
26
+ },
27
+ virtualModules: {}
28
+ };
29
+ const pubsub = null;
30
+
31
+ //#endregion
32
+ export { debugInfo, directives, importedConfig, moduleConfig, pubsub, resolvers, schemas };
@@ -1,6 +1,6 @@
1
1
  import * as _nuxt_schema0 from "@nuxt/schema";
2
2
 
3
- //#region src/ecosystem/nuxt.d.ts
3
+ //#region src/nuxt.d.ts
4
4
  interface ModuleOptions {}
5
5
  declare const _default: _nuxt_schema0.NuxtModule<ModuleOptions, ModuleOptions, false>;
6
6
  //#endregion
package/dist/nuxt.mjs ADDED
@@ -0,0 +1,112 @@
1
+ import { getDefaultPaths, getTypesConfig, resolveFilePath } from "./nitro/paths.mjs";
2
+ import { dirname, join, relative, resolve } from "pathe";
3
+ import { existsSync, mkdirSync, writeFileSync } from "node:fs";
4
+ import { defineNuxtModule, getLayerDirectories } from "@nuxt/kit";
5
+
6
+ //#region src/nuxt.ts
7
+ var nuxt_default = defineNuxtModule({
8
+ meta: {
9
+ name: "nitro-graphql-nuxt",
10
+ configKey: "nitro-graphql-nuxt",
11
+ compatibility: { nuxt: ">=3.16.0" }
12
+ },
13
+ setup: async (_options, nuxt) => {
14
+ nuxt.hooks.hook("prepare:types", (options) => {
15
+ const mockNitro = { options: {
16
+ rootDir: nuxt.options.rootDir,
17
+ buildDir: nuxt.options.buildDir,
18
+ framework: { name: "nuxt" },
19
+ graphql: nuxt.options.nitro?.graphql
20
+ } };
21
+ const placeholders = getDefaultPaths(mockNitro);
22
+ const typesConfig = getTypesConfig(mockNitro);
23
+ const tsconfigDir = dirname(join(nuxt.options.buildDir, "tsconfig.json"));
24
+ const relativeWithDot = (from, to) => {
25
+ const rel = relative(from, to);
26
+ return rel.startsWith(".") ? rel : `./${rel}`;
27
+ };
28
+ const clientTypesPath = resolveFilePath(typesConfig.client, typesConfig.enabled, true, "{typesDir}/nitro-graphql-client.d.ts", placeholders);
29
+ if (clientTypesPath) {
30
+ const relativePath = relativeWithDot(tsconfigDir, clientTypesPath);
31
+ options.references.push({ path: relativePath });
32
+ options.tsConfig ??= {};
33
+ options.tsConfig.compilerOptions ??= {};
34
+ options.tsConfig.compilerOptions.paths ??= {};
35
+ options.tsConfig.compilerOptions.paths["#graphql/client"] = [relativePath];
36
+ options.tsConfig.include = options.tsConfig.include || [];
37
+ options.tsConfig.include.push(relativePath);
38
+ }
39
+ const externalServices = nuxt.options.nitro?.graphql?.externalServices || [];
40
+ for (const service of externalServices) {
41
+ const servicePlaceholders = {
42
+ ...placeholders,
43
+ serviceName: service.name
44
+ };
45
+ const externalTypesPath = resolveFilePath(service.paths?.types ?? typesConfig.external, typesConfig.enabled, true, "{typesDir}/nitro-graphql-client-{serviceName}.d.ts", servicePlaceholders);
46
+ if (externalTypesPath) {
47
+ const relativePath = relativeWithDot(tsconfigDir, externalTypesPath);
48
+ options.references.push({ path: relativePath });
49
+ if (options.tsConfig.compilerOptions) options.tsConfig.compilerOptions.paths[`#graphql/client/${service.name}`] = [relativePath];
50
+ if (options.tsConfig.include) options.tsConfig.include.push(relativePath);
51
+ }
52
+ }
53
+ });
54
+ nuxt.options.alias = nuxt.options.alias || {};
55
+ const mockNitro = { options: {
56
+ rootDir: nuxt.options.rootDir,
57
+ buildDir: nuxt.options.buildDir,
58
+ framework: { name: "nuxt" },
59
+ graphql: nuxt.options.nitro?.graphql
60
+ } };
61
+ const placeholders = getDefaultPaths(mockNitro);
62
+ const typesConfig = getTypesConfig(mockNitro);
63
+ const clientTypesPath = resolveFilePath(typesConfig.client, typesConfig.enabled, true, "{typesDir}/nitro-graphql-client.d.ts", placeholders);
64
+ if (clientTypesPath) nuxt.options.alias["#graphql/client"] = clientTypesPath;
65
+ const externalServices = nuxt.options.nitro?.graphql?.externalServices || [];
66
+ for (const service of externalServices) {
67
+ const servicePlaceholders = {
68
+ ...placeholders,
69
+ serviceName: service.name
70
+ };
71
+ const externalTypesPath = resolveFilePath(service.paths?.types ?? typesConfig.external, typesConfig.enabled, true, "{typesDir}/nitro-graphql-client-{serviceName}.d.ts", servicePlaceholders);
72
+ if (externalTypesPath) nuxt.options.alias[`#graphql/client/${service.name}`] = externalTypesPath;
73
+ }
74
+ nuxt.hook("imports:dirs", (dirs) => {
75
+ const graphqlServerPath = nuxt.options.nitro?.graphql?.serverDir || resolve(nuxt.options.srcDir, "graphql");
76
+ dirs.push(graphqlServerPath);
77
+ });
78
+ nuxt.hook("nitro:config", async (nitroConfig) => {
79
+ const clientDir = join(nuxt.options.buildDir, "graphql");
80
+ const layerExtends = (await getLayerDirectories(nuxt)).filter((layer) => layer.root !== `${nuxt.options.rootDir}/`).map((layer) => {
81
+ const serverDir = layer.server?.replace(/\/$/, "");
82
+ const appDir = layer.app?.replace(/\/$/, "");
83
+ if (!serverDir && !appDir) return null;
84
+ return {
85
+ serverDir: serverDir ? join(serverDir, "graphql") : void 0,
86
+ clientDir: appDir ? join(appDir, "graphql") : void 0
87
+ };
88
+ }).filter(Boolean);
89
+ if (!nitroConfig.graphql) nitroConfig.graphql = {};
90
+ nitroConfig.graphql.extend = [...nitroConfig.graphql?.extend || [], ...layerExtends];
91
+ if (!existsSync(resolve(nuxt.options.rootDir, "app/graphql"))) {
92
+ const defaultDir = join(clientDir, "default");
93
+ if (!existsSync(defaultDir)) mkdirSync(defaultDir, { recursive: true });
94
+ const sampleQueryFile = join(defaultDir, "queries.graphql");
95
+ if (!existsSync(sampleQueryFile)) writeFileSync(sampleQueryFile, `# Example GraphQL queries
96
+ # Add your GraphQL queries here
97
+
98
+ # query GetUser($id: ID!) {
99
+ # user(id: $id) {
100
+ # id
101
+ # name
102
+ # email
103
+ # }
104
+ # }
105
+ `, "utf-8");
106
+ }
107
+ });
108
+ }
109
+ });
110
+
111
+ //#endregion
112
+ export { nuxt_default as default };
@@ -1,4 +1,8 @@
1
- //#region src/graphql/server.d.ts
1
+ //#region src/stubs/index.d.ts
2
+ /**
3
+ * Runtime type stubs for GraphQL types
4
+ * These interfaces are replaced by generated types at build time
5
+ */
2
6
  interface StandardSchemaV1 extends Record<string, any> {}
3
7
  interface ResolversTypes extends Record<string, any> {}
4
8
  interface Resolvers extends Record<string, any> {}
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,78 @@
1
+ //#region src/subscribe/index.d.ts
2
+ /**
3
+ * GraphQL Subscription Client
4
+ * Lightweight wrapper around graphql-ws and graphql-sse
5
+ *
6
+ * @example WebSocket (default - uses graphql-ws)
7
+ * ```typescript
8
+ * import { createSubscriptionClient } from 'nitro-graphql/subscribe'
9
+ *
10
+ * const client = createSubscriptionClient({ wsEndpoint: '/api/graphql/ws' })
11
+ *
12
+ * // Simple subscription
13
+ * const handle = client.subscribe(
14
+ * 'subscription { countdown(from: 10) }',
15
+ * {},
16
+ * (data) => console.log(data),
17
+ * (error) => console.error(error)
18
+ * )
19
+ *
20
+ * // Unsubscribe
21
+ * handle.unsubscribe()
22
+ * ```
23
+ *
24
+ * @example SSE Transport (uses graphql-sse)
25
+ * ```typescript
26
+ * client.subscribe(query, vars, onData, onError, { transport: 'sse' })
27
+ * ```
28
+ *
29
+ * @example Auto Transport (WebSocket first, SSE fallback)
30
+ * ```typescript
31
+ * client.subscribe(query, vars, onData, onError, { transport: 'auto' })
32
+ * ```
33
+ *
34
+ * @module nitro-graphql/subscribe
35
+ */
36
+ type ConnectionState = 'idle' | 'connecting' | 'connected' | 'reconnecting' | 'disconnected' | 'error';
37
+ type SubscriptionTransport = 'websocket' | 'sse' | 'auto';
38
+ interface TransportOptions {
39
+ /** Transport type: 'websocket' (default), 'sse', or 'auto' (WS first, SSE fallback) */
40
+ transport?: SubscriptionTransport;
41
+ }
42
+ interface SubscriptionHandle {
43
+ unsubscribe: () => void;
44
+ readonly transport: 'websocket' | 'sse';
45
+ }
46
+ interface SubscriptionSession {
47
+ subscribe: <TData = unknown, TVariables = Record<string, unknown>>(query: string, variables?: TVariables, onData?: (data: TData) => void, onError?: (error: Error) => void) => SubscriptionHandle;
48
+ readonly isConnected: boolean;
49
+ readonly state: ConnectionState;
50
+ readonly subscriptionCount: number;
51
+ close: () => void;
52
+ onStateChange: (callback: StateChangeCallback) => () => void;
53
+ }
54
+ type StateChangeCallback = (state: ConnectionState, subscriptionCount: number) => void;
55
+ interface SubscriptionClientConfig {
56
+ /** WebSocket endpoint (default: '/api/graphql/ws') */
57
+ wsEndpoint?: string;
58
+ /** SSE endpoint for SSE transport (default: '/api/graphql') */
59
+ sseEndpoint?: string;
60
+ /** Connection parameters for WebSocket handshake */
61
+ connectionParams?: Record<string, unknown> | (() => Record<string, unknown> | Promise<Record<string, unknown>>);
62
+ /** Headers for SSE requests */
63
+ sseHeaders?: Record<string, string> | (() => Record<string, string> | Promise<Record<string, string>>);
64
+ /** Connection timeout in ms (default: 10000) */
65
+ connectionTimeoutMs?: number;
66
+ /** Maximum retry attempts (default: 5) */
67
+ maxRetries?: number;
68
+ /** Keep-alive ping interval in ms (default: 25000) */
69
+ keepAlive?: number;
70
+ }
71
+ interface SubscriptionClient {
72
+ subscribe: <TData = unknown, TVariables = Record<string, unknown>>(query: string, variables?: TVariables, onData?: (data: TData) => void, onError?: (error: Error) => void, transportOptions?: TransportOptions) => SubscriptionHandle;
73
+ createSession: () => SubscriptionSession;
74
+ dispose: () => void;
75
+ }
76
+ declare function createSubscriptionClient(config?: SubscriptionClientConfig): SubscriptionClient;
77
+ //#endregion
78
+ export { ConnectionState, StateChangeCallback, SubscriptionClient, SubscriptionClientConfig, SubscriptionHandle, SubscriptionSession, SubscriptionTransport, TransportOptions, createSubscriptionClient };
@@ -0,0 +1,206 @@
1
+ import { createClient } from "graphql-sse";
2
+ import { createClient as createClient$1 } from "graphql-ws";
3
+
4
+ //#region src/subscribe/index.ts
5
+ function toWebSocketUrl(httpUrl) {
6
+ if (httpUrl.startsWith("/")) return `${typeof window !== "undefined" && window.location.protocol === "https:" ? "wss:" : "ws:"}//${typeof window !== "undefined" ? window.location.host : "localhost"}${httpUrl}`;
7
+ return httpUrl.replace(/^http/, "ws");
8
+ }
9
+ function toHttpUrl(url) {
10
+ if (url.startsWith("/")) return `${typeof window !== "undefined" ? window.location.protocol : "http:"}//${typeof window !== "undefined" ? window.location.host : "localhost"}${url}`;
11
+ return url;
12
+ }
13
+ function extractDataValue(data) {
14
+ if (!data) return void 0;
15
+ return Object.values(data)[0];
16
+ }
17
+ function createSseSubscriptionInternal(client, query, variables, onData, onError) {
18
+ return {
19
+ unsubscribe: client.subscribe({
20
+ query,
21
+ variables
22
+ }, {
23
+ next: (result) => {
24
+ if (result.errors?.length) onError?.(new Error(result.errors[0]?.message || "GraphQL Error"));
25
+ else if (result.data) {
26
+ const value = extractDataValue(result.data);
27
+ if (value !== void 0) onData?.(value);
28
+ }
29
+ },
30
+ error: (err) => {
31
+ onError?.(err instanceof Error ? err : new Error(String(err)));
32
+ },
33
+ complete: () => {}
34
+ }),
35
+ transport: "sse"
36
+ };
37
+ }
38
+ function createWsSubscriptionInternal(client, query, variables, onData, onError) {
39
+ return {
40
+ unsubscribe: client.subscribe({
41
+ query,
42
+ variables
43
+ }, {
44
+ next: (result) => {
45
+ if (result.errors?.length) onError?.(new Error(result.errors[0]?.message || "GraphQL Error"));
46
+ else if (result.data) {
47
+ const value = extractDataValue(result.data);
48
+ if (value !== void 0) onData?.(value);
49
+ }
50
+ },
51
+ error: (err) => {
52
+ onError?.(err instanceof Error ? err : new Error(String(err)));
53
+ },
54
+ complete: () => {}
55
+ }),
56
+ transport: "websocket"
57
+ };
58
+ }
59
+ function createAutoSubscription(wsClient, sseClient, query, variables, onData, onError, timeoutMs = 5e3) {
60
+ let activeHandle = null;
61
+ let fallbackTimeout = null;
62
+ let wsConnected = false;
63
+ const wsUnsubscribe = wsClient.subscribe({
64
+ query,
65
+ variables
66
+ }, {
67
+ next: (result) => {
68
+ wsConnected = true;
69
+ if (fallbackTimeout) {
70
+ clearTimeout(fallbackTimeout);
71
+ fallbackTimeout = null;
72
+ }
73
+ if (result.errors?.length) onError?.(new Error(result.errors[0]?.message || "GraphQL Error"));
74
+ else if (result.data) {
75
+ const value = extractDataValue(result.data);
76
+ if (value !== void 0) onData?.(value);
77
+ }
78
+ },
79
+ error: (err) => {
80
+ if (!wsConnected) activeHandle = createSseSubscriptionInternal(sseClient, query, variables, onData, onError);
81
+ else onError?.(err instanceof Error ? err : new Error(String(err)));
82
+ },
83
+ complete: () => {}
84
+ });
85
+ fallbackTimeout = setTimeout(() => {
86
+ if (!wsConnected) {
87
+ wsUnsubscribe();
88
+ activeHandle = createSseSubscriptionInternal(sseClient, query, variables, onData, onError);
89
+ }
90
+ }, timeoutMs);
91
+ return {
92
+ unsubscribe: () => {
93
+ if (fallbackTimeout) clearTimeout(fallbackTimeout);
94
+ if (activeHandle) activeHandle.unsubscribe();
95
+ else wsUnsubscribe();
96
+ },
97
+ get transport() {
98
+ return activeHandle?.transport ?? "websocket";
99
+ }
100
+ };
101
+ }
102
+ function createSessionInternal(client) {
103
+ const subscriptions = /* @__PURE__ */ new Map();
104
+ const stateListeners = /* @__PURE__ */ new Set();
105
+ let idCounter = 0;
106
+ let state = "idle";
107
+ function setState(newState) {
108
+ state = newState;
109
+ notifyListeners();
110
+ }
111
+ function notifyListeners() {
112
+ for (const listener of stateListeners) listener(state, subscriptions.size);
113
+ }
114
+ setState("connected");
115
+ return {
116
+ subscribe(query, variables, onData, onError) {
117
+ const id = String(++idCounter);
118
+ const unsubscribe = client.subscribe({
119
+ query,
120
+ variables
121
+ }, {
122
+ next: (result) => {
123
+ if (result.errors?.length) onError?.(new Error(result.errors[0]?.message || "GraphQL Error"));
124
+ else if (result.data) {
125
+ const value = extractDataValue(result.data);
126
+ if (value !== void 0) onData?.(value);
127
+ }
128
+ },
129
+ error: (err) => {
130
+ onError?.(err instanceof Error ? err : new Error(String(err)));
131
+ subscriptions.delete(id);
132
+ notifyListeners();
133
+ },
134
+ complete: () => {
135
+ subscriptions.delete(id);
136
+ notifyListeners();
137
+ }
138
+ });
139
+ subscriptions.set(id, unsubscribe);
140
+ notifyListeners();
141
+ return {
142
+ unsubscribe: () => {
143
+ unsubscribe();
144
+ subscriptions.delete(id);
145
+ notifyListeners();
146
+ },
147
+ transport: "websocket"
148
+ };
149
+ },
150
+ get isConnected() {
151
+ return state === "connected";
152
+ },
153
+ get state() {
154
+ return state;
155
+ },
156
+ get subscriptionCount() {
157
+ return subscriptions.size;
158
+ },
159
+ close() {
160
+ for (const unsubscribe of subscriptions.values()) unsubscribe();
161
+ subscriptions.clear();
162
+ setState("disconnected");
163
+ },
164
+ onStateChange(callback) {
165
+ stateListeners.add(callback);
166
+ return () => stateListeners.delete(callback);
167
+ }
168
+ };
169
+ }
170
+ function createSubscriptionClient(config = {}) {
171
+ const wsEndpoint = config.wsEndpoint ?? "/api/graphql/ws";
172
+ const sseEndpoint = config.sseEndpoint ?? "/api/graphql";
173
+ const connectionTimeoutMs = config.connectionTimeoutMs ?? 1e4;
174
+ const maxRetries = config.maxRetries ?? 5;
175
+ const keepAlive = config.keepAlive ?? 25e3;
176
+ const wsClient = createClient$1({
177
+ url: toWebSocketUrl(wsEndpoint),
178
+ retryAttempts: maxRetries,
179
+ keepAlive,
180
+ connectionAckWaitTimeout: connectionTimeoutMs,
181
+ connectionParams: config.connectionParams
182
+ });
183
+ const sseClient = createClient({
184
+ url: toHttpUrl(sseEndpoint),
185
+ retryAttempts: maxRetries,
186
+ headers: config.sseHeaders
187
+ });
188
+ return {
189
+ subscribe(query, variables, onData, onError, transportOptions) {
190
+ const transport = transportOptions?.transport ?? "websocket";
191
+ if (transport === "sse") return createSseSubscriptionInternal(sseClient, query, variables, onData, onError);
192
+ if (transport === "auto") return createAutoSubscription(wsClient, sseClient, query, variables, onData, onError, connectionTimeoutMs);
193
+ return createWsSubscriptionInternal(wsClient, query, variables, onData, onError);
194
+ },
195
+ createSession() {
196
+ return createSessionInternal(wsClient);
197
+ },
198
+ dispose() {
199
+ wsClient.dispose();
200
+ sseClient.dispose();
201
+ }
202
+ };
203
+ }
204
+
205
+ //#endregion
206
+ export { createSubscriptionClient };
@@ -0,0 +1,20 @@
1
+ /* auto-generated by NAPI-RS */
2
+ /* eslint-disable */
3
+ /**
4
+ * Validate GraphQL schema files
5
+ * Returns validation result with errors if any
6
+ */
7
+ export declare function validateSchemas(filePaths: Array<string>): ValidationResult
8
+
9
+ /** Validate GraphQL schema from string content (simple version) */
10
+ export declare function validateSchemaString(content: string): ValidationResult
11
+
12
+ /** Validate GraphQL schema from string content with file paths */
13
+ export declare function validateSchemaStringWithPaths(contents: Array<string>, paths: Array<string>): ValidationResult
14
+
15
+ /** Validation result from GraphQL schema linting */
16
+ export interface ValidationResult {
17
+ valid: boolean
18
+ errors: Array<string>
19
+ fileCount: number
20
+ }