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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (204) hide show
  1. package/dist/cli/commands/generate.d.mts +26 -0
  2. package/dist/cli/commands/generate.mjs +196 -0
  3. package/dist/cli/commands/index.d.mts +4 -0
  4. package/dist/cli/commands/index.mjs +5 -0
  5. package/dist/cli/commands/init.d.mts +12 -0
  6. package/dist/cli/commands/init.mjs +100 -0
  7. package/dist/cli/commands/validate.d.mts +10 -0
  8. package/dist/cli/commands/validate.mjs +69 -0
  9. package/dist/cli/config.d.mts +75 -0
  10. package/dist/cli/config.mjs +20 -0
  11. package/dist/cli/index.d.mts +24 -0
  12. package/dist/cli/index.mjs +219 -0
  13. package/dist/core/codegen/client.d.mts +23 -0
  14. package/dist/core/codegen/client.mjs +150 -0
  15. package/dist/core/codegen/document-loader.d.mts +10 -0
  16. package/dist/core/codegen/document-loader.mjs +18 -0
  17. package/dist/core/codegen/index.d.mts +8 -0
  18. package/dist/core/codegen/index.mjs +9 -0
  19. package/dist/{utils/codegen-plugin.d.mts → core/codegen/plugin.d.mts} +2 -2
  20. package/dist/{utils/codegen-plugin.mjs → core/codegen/plugin.mjs} +1 -1
  21. package/dist/core/codegen/runtime.d.mts +20 -0
  22. package/dist/core/codegen/runtime.mjs +60 -0
  23. package/dist/core/codegen/schema-loader.d.mts +28 -0
  24. package/dist/core/codegen/schema-loader.mjs +128 -0
  25. package/dist/core/codegen/server.d.mts +28 -0
  26. package/dist/core/codegen/server.mjs +143 -0
  27. package/dist/{codegen → core/codegen}/validation.d.mts +1 -1
  28. package/dist/{codegen → core/codegen}/validation.mjs +1 -1
  29. package/dist/core/config.d.mts +50 -0
  30. package/dist/core/config.mjs +82 -0
  31. package/dist/core/constants.d.mts +188 -0
  32. package/dist/core/constants.mjs +210 -0
  33. package/dist/core/index.d.mts +32 -0
  34. package/dist/core/index.mjs +26 -0
  35. package/dist/core/scanning/ast-scanner.d.mts +23 -0
  36. package/dist/core/scanning/ast-scanner.mjs +103 -0
  37. package/dist/core/scanning/common.d.mts +37 -0
  38. package/dist/core/scanning/common.mjs +60 -0
  39. package/dist/core/scanning/directives.d.mts +10 -0
  40. package/dist/core/scanning/directives.mjs +29 -0
  41. package/dist/core/scanning/documents.d.mts +21 -0
  42. package/dist/core/scanning/documents.mjs +43 -0
  43. package/dist/core/scanning/index.d.mts +7 -0
  44. package/dist/core/scanning/index.mjs +8 -0
  45. package/dist/core/scanning/resolvers.d.mts +10 -0
  46. package/dist/core/scanning/resolvers.mjs +58 -0
  47. package/dist/core/scanning/schemas.d.mts +14 -0
  48. package/dist/core/scanning/schemas.mjs +64 -0
  49. package/dist/{utils/schema-builder.d.mts → core/schema/builder.d.mts} +7 -2
  50. package/dist/{utils/schema-builder.mjs → core/schema/builder.mjs} +22 -3
  51. package/dist/{utils → core/schema}/federation.d.mts +10 -5
  52. package/dist/{utils → core/schema}/federation.mjs +1 -1
  53. package/dist/core/schema/index.d.mts +3 -0
  54. package/dist/core/schema/index.mjs +4 -0
  55. package/dist/core/types/adapter.d.mts +58 -0
  56. package/dist/core/types/codegen.d.mts +133 -0
  57. package/dist/core/types/config.d.mts +212 -0
  58. package/dist/{types → core/types}/define.d.mts +3 -7
  59. package/dist/core/types/index.d.mts +5 -0
  60. package/dist/core/types/scanning.d.mts +69 -0
  61. package/dist/core/types/scanning.mjs +1 -0
  62. package/dist/{utils → core/utils}/directive-parser.d.mts +21 -5
  63. package/dist/{utils → core/utils}/directive-parser.mjs +25 -36
  64. package/dist/{utils → core/utils}/errors.d.mts +8 -4
  65. package/dist/{utils → core/utils}/errors.mjs +8 -4
  66. package/dist/core/utils/file-io.d.mts +24 -0
  67. package/dist/core/utils/file-io.mjs +47 -0
  68. package/dist/{utils → core/utils}/imports.d.mts +1 -1
  69. package/dist/{utils → core/utils}/imports.mjs +1 -1
  70. package/dist/core/utils/index.d.mts +7 -0
  71. package/dist/core/utils/index.mjs +8 -0
  72. package/dist/core/utils/logger.d.mts +19 -0
  73. package/dist/core/utils/logger.mjs +38 -0
  74. package/dist/{utils → core/utils}/ofetch-templates.d.mts +1 -1
  75. package/dist/{utils → core/utils}/ofetch-templates.mjs +1 -1
  76. package/dist/core/validation/external-services.d.mts +11 -0
  77. package/dist/{utils/validation.mjs → core/validation/external-services.mjs} +3 -3
  78. package/dist/core/validation/index.d.mts +2 -0
  79. package/dist/core/validation/index.mjs +3 -0
  80. package/dist/define.d.mts +1 -3
  81. package/dist/index.d.mts +6 -43
  82. package/dist/index.mjs +5 -62
  83. package/dist/nitro/adapter.d.mts +30 -0
  84. package/dist/nitro/adapter.mjs +97 -0
  85. package/dist/{utils → nitro}/apollo.d.mts +1 -1
  86. package/dist/{utils → nitro}/apollo.mjs +1 -1
  87. package/dist/nitro/codegen.d.mts +19 -0
  88. package/dist/nitro/codegen.mjs +141 -0
  89. package/dist/nitro/config.d.mts +52 -0
  90. package/dist/nitro/config.mjs +58 -0
  91. package/dist/nitro/index.d.mts +46 -0
  92. package/dist/nitro/index.mjs +65 -0
  93. package/dist/{utils/path-resolver.d.mts → nitro/paths.d.mts} +3 -19
  94. package/dist/{utils/path-resolver.mjs → nitro/paths.mjs} +2 -36
  95. package/dist/{rollup.d.mts → nitro/rollup.d.mts} +1 -1
  96. package/dist/{rollup.mjs → nitro/rollup.mjs} +11 -23
  97. package/dist/{routes → nitro/routes}/apollo-server.d.mts +1 -1
  98. package/dist/nitro/routes/apollo-server.mjs +71 -0
  99. package/dist/{routes → nitro/routes}/debug-template.d.mts +1 -1
  100. package/dist/{routes → nitro/routes}/debug-template.mjs +1 -1
  101. package/dist/{routes → nitro/routes}/debug.d.mts +10 -16
  102. package/dist/{routes → nitro/routes}/debug.mjs +2 -2
  103. package/dist/nitro/routes/graphql-yoga.d.mts +6 -0
  104. package/dist/{routes → nitro/routes}/graphql-yoga.mjs +21 -10
  105. package/dist/nitro/routes/health.d.mts +10 -0
  106. package/dist/{routes → nitro/routes}/health.mjs +1 -1
  107. package/dist/nitro/setup/file-watcher.d.mts +16 -0
  108. package/dist/{setup → nitro/setup}/file-watcher.mjs +14 -18
  109. package/dist/nitro/setup/logging.d.mts +17 -0
  110. package/dist/nitro/setup/logging.mjs +66 -0
  111. package/dist/nitro/setup/rollup-integration.d.mts +16 -0
  112. package/dist/{setup → nitro/setup}/rollup-integration.mjs +2 -2
  113. package/dist/nitro/setup/routes.d.mts +10 -0
  114. package/dist/nitro/setup/routes.mjs +35 -0
  115. package/dist/nitro/setup/ts-config.d.mts +11 -0
  116. package/dist/{setup → nitro/setup}/ts-config.mjs +3 -3
  117. package/dist/{setup.d.mts → nitro/setup.d.mts} +3 -2
  118. package/dist/{setup.mjs → nitro/setup.mjs} +73 -62
  119. package/dist/nitro/types.d.mts +378 -0
  120. package/dist/nitro/types.mjs +1 -0
  121. package/dist/nitro/virtual/generators.d.mts +31 -0
  122. package/dist/nitro/virtual/generators.mjs +193 -0
  123. package/dist/nitro/virtual/stubs.d.mts +20 -0
  124. package/dist/nitro/virtual/stubs.mjs +31 -0
  125. package/dist/{ecosystem/nuxt.d.mts → nuxt.d.mts} +1 -1
  126. package/dist/{ecosystem/nuxt.mjs → nuxt.mjs} +2 -2
  127. package/dist/{graphql/server.d.mts → stubs/index.d.mts} +5 -1
  128. package/dist/stubs/index.mjs +1 -0
  129. package/package.json +45 -43
  130. package/dist/codegen/client-types.d.mts +0 -13
  131. package/dist/codegen/client-types.mjs +0 -131
  132. package/dist/codegen/external-types.d.mts +0 -12
  133. package/dist/codegen/external-types.mjs +0 -88
  134. package/dist/codegen/index.d.mts +0 -18
  135. package/dist/codegen/index.mjs +0 -24
  136. package/dist/codegen/server-types.d.mts +0 -13
  137. package/dist/codegen/server-types.mjs +0 -64
  138. package/dist/config/defaults.mjs +0 -36
  139. package/dist/constants/scalars.mjs +0 -27
  140. package/dist/constants.mjs +0 -106
  141. package/dist/graphql/index.d.mts +0 -5
  142. package/dist/routes/apollo-server.mjs +0 -45
  143. package/dist/routes/graphql-yoga.d.mts +0 -6
  144. package/dist/routes/health.d.mts +0 -10
  145. package/dist/setup/graphql-scanner.mjs +0 -25
  146. package/dist/setup/scaffold-generator.mjs +0 -109
  147. package/dist/types/index.d.mts +0 -246
  148. package/dist/types/standard-schema.d.mts +0 -59
  149. package/dist/utils/client-codegen.d.mts +0 -41
  150. package/dist/utils/client-codegen.mjs +0 -267
  151. package/dist/utils/file-generator.d.mts +0 -37
  152. package/dist/utils/file-generator.mjs +0 -72
  153. package/dist/utils/file-writer.d.mts +0 -35
  154. package/dist/utils/file-writer.mjs +0 -32
  155. package/dist/utils/index.d.mts +0 -13
  156. package/dist/utils/index.mjs +0 -13
  157. package/dist/utils/layers.d.mts +0 -22
  158. package/dist/utils/layers.mjs +0 -28
  159. package/dist/utils/scanning/common.d.mts +0 -23
  160. package/dist/utils/scanning/common.mjs +0 -39
  161. package/dist/utils/scanning/directives.d.mts +0 -11
  162. package/dist/utils/scanning/directives.mjs +0 -43
  163. package/dist/utils/scanning/documents.d.mts +0 -15
  164. package/dist/utils/scanning/documents.mjs +0 -46
  165. package/dist/utils/scanning/index.d.mts +0 -6
  166. package/dist/utils/scanning/index.mjs +0 -7
  167. package/dist/utils/scanning/resolvers.d.mts +0 -11
  168. package/dist/utils/scanning/resolvers.mjs +0 -100
  169. package/dist/utils/scanning/schemas.d.mts +0 -15
  170. package/dist/utils/scanning/schemas.mjs +0 -29
  171. package/dist/utils/server-codegen.d.mts +0 -7
  172. package/dist/utils/server-codegen.mjs +0 -113
  173. package/dist/utils/type-generation.d.mts +0 -6
  174. package/dist/utils/type-generation.mjs +0 -7
  175. package/dist/utils/validation.d.mts +0 -11
  176. package/dist/virtual/debug-info.d.mts +0 -9
  177. package/dist/virtual/debug-info.mjs +0 -26
  178. package/dist/virtual/generators/config.d.mts +0 -22
  179. package/dist/virtual/generators/config.mjs +0 -36
  180. package/dist/virtual/generators/debug.d.mts +0 -14
  181. package/dist/virtual/generators/debug.mjs +0 -53
  182. package/dist/virtual/generators/directives.d.mts +0 -14
  183. package/dist/virtual/generators/directives.mjs +0 -52
  184. package/dist/virtual/generators/index.d.mts +0 -6
  185. package/dist/virtual/generators/index.mjs +0 -7
  186. package/dist/virtual/generators/resolvers.d.mts +0 -14
  187. package/dist/virtual/generators/resolvers.mjs +0 -55
  188. package/dist/virtual/generators/schemas.d.mts +0 -14
  189. package/dist/virtual/generators/schemas.mjs +0 -43
  190. package/dist/virtual/graphql-config.d.mts +0 -9
  191. package/dist/virtual/graphql-config.mjs +0 -10
  192. package/dist/virtual/module-config.d.mts +0 -9
  193. package/dist/virtual/module-config.mjs +0 -10
  194. package/dist/virtual/server-directives.d.mts +0 -11
  195. package/dist/virtual/server-directives.mjs +0 -10
  196. package/dist/virtual/server-resolvers.d.mts +0 -11
  197. package/dist/virtual/server-resolvers.mjs +0 -10
  198. package/dist/virtual/server-schemas.d.mts +0 -11
  199. package/dist/virtual/server-schemas.mjs +0 -10
  200. /package/dist/{graphql/index.mjs → core/types/adapter.mjs} +0 -0
  201. /package/dist/{graphql/server.mjs → core/types/codegen.mjs} +0 -0
  202. /package/dist/{types/define.mjs → core/types/config.mjs} +0 -0
  203. /package/dist/{types/index.mjs → core/types/define.mjs} +0 -0
  204. /package/dist/{types/standard-schema.mjs → core/types/index.mjs} +0 -0
@@ -0,0 +1,193 @@
1
+ import { getImportId } from "../../core/utils/imports.mjs";
2
+ import { isAbsolute, resolve } from "pathe";
3
+ import { genImport } from "knitwork";
4
+
5
+ //#region src/nitro/virtual/generators.ts
6
+ function normalizeExtendConfig(extend) {
7
+ if (!extend || !Array.isArray(extend) || extend.length === 0) return null;
8
+ const resolvers = [];
9
+ const schemas = [];
10
+ for (const source of extend) if (typeof source === "string") {
11
+ resolvers.push(`${source}/resolvers`);
12
+ schemas.push(`${source}/schema`);
13
+ } else if (source && typeof source === "object") {
14
+ const obj = source;
15
+ if (obj.resolvers) {
16
+ const r = Array.isArray(obj.resolvers) ? obj.resolvers : [obj.resolvers];
17
+ resolvers.push(...r);
18
+ }
19
+ if (obj.schemas) {
20
+ const s = Array.isArray(obj.schemas) ? obj.schemas : [obj.schemas];
21
+ schemas.push(...s);
22
+ }
23
+ }
24
+ if (resolvers.length === 0 && schemas.length === 0) return null;
25
+ return {
26
+ resolvers,
27
+ schemas
28
+ };
29
+ }
30
+ /**
31
+ * Resolve extend path to absolute path
32
+ * Supports: relative paths, absolute paths, package names
33
+ */
34
+ function resolveExtendPath(nitro, inputPath) {
35
+ if (inputPath.startsWith("@") || !inputPath.startsWith(".") && !inputPath.startsWith("/")) return inputPath;
36
+ if (isAbsolute(inputPath)) return inputPath;
37
+ return resolve(nitro.options.rootDir, inputPath);
38
+ }
39
+ function generateImportModule(items, exportName, wrapperKey) {
40
+ if (!items.length) return `export const ${exportName} = []`;
41
+ const imports = items.flatMap(({ specifier, imports: list, options }) => list?.length ? [genImport(specifier, list, options)] : []);
42
+ const data = items.flatMap(({ imports: list }) => list.map((i) => `{ ${wrapperKey}: ${i.as || i.name} }`));
43
+ return `${imports.join("\n")}\n\nexport const ${exportName} = [\n${data.join(",\n")}\n]`;
44
+ }
45
+ function safeGenerateModuleCode(nitro, moduleName) {
46
+ try {
47
+ const generator = nitro.options.virtual?.[moduleName];
48
+ if (generator && typeof generator === "function") return generator();
49
+ return "// Module not found";
50
+ } catch (error) {
51
+ return `// Error: ${error instanceof Error ? error.message : String(error)}`;
52
+ }
53
+ }
54
+ const serverSchemas = {
55
+ id: "#nitro-graphql/server-schemas",
56
+ getCode: (nitro) => {
57
+ const ext = normalizeExtendConfig(nitro.options.graphql?.extend);
58
+ const skipLocalScan = nitro.options.graphql?.skipLocalScan === true;
59
+ if (ext && ext.schemas.length > 0) {
60
+ const schemaPaths = ext.schemas.map((p) => resolveExtendPath(nitro, p));
61
+ const scannedSchemas = [...nitro.scanSchemas, ...nitro.options.graphql?.typedefs ?? []];
62
+ if (!skipLocalScan && scannedSchemas.length > 0) {
63
+ const extImports = schemaPaths.map((p, i) => `import { schemaString as extSchema${i} } from '${p}'`);
64
+ const scannedImports = scannedSchemas.map((s) => `import ${getImportId(s)} from '${s}';`);
65
+ const extDefs = schemaPaths.map((_, i) => `{ def: extSchema${i} }`);
66
+ const scannedDefs = scannedSchemas.map((s) => `{ def: ${getImportId(s)} }`);
67
+ return `${extImports.join("\n")}
68
+ ${scannedImports.join("\n")}
69
+
70
+ export const schemas = [
71
+ ${[...extDefs, ...scannedDefs].join(",\n")}
72
+ ]`;
73
+ }
74
+ if (schemaPaths.length === 1) return `import { schemaString, typeDefs } from '${schemaPaths[0]}'
75
+ export { schemaString, typeDefs }
76
+ export const schemas = [{ def: schemaString }]`;
77
+ const imports = schemaPaths.map((p, i) => `import { schemaString as schema${i} } from '${p}'`);
78
+ const schemaVars = schemaPaths.map((_, i) => `schema${i}`);
79
+ const mergeCode = `export const schemaString = [${schemaVars.join(", ")}].join('\\n\\n')
80
+ import { parse } from 'graphql'
81
+ export const typeDefs = parse(schemaString)
82
+ export const schemas = [${schemaVars.map((v) => `{ def: ${v} }`).join(", ")}]`;
83
+ return `${imports.join("\n")}\n\n${mergeCode}`;
84
+ }
85
+ const schemas = [...nitro.scanSchemas, ...nitro.options.graphql?.typedefs ?? []];
86
+ if (!schemas.length) {
87
+ if (nitro.options.dev) nitro.logger.warn("[nitro-graphql] No schemas found. Virtual module will export empty array.");
88
+ return "export const schemas = []";
89
+ }
90
+ const importStatements = schemas.map((s) => `import ${getImportId(s)} from '${s}';`);
91
+ const schemaArray = schemas.map((s) => `{ def: ${getImportId(s)} }`);
92
+ return `${importStatements.join("\n")}\n\nexport const schemas = [\n${schemaArray.join(",\n")}\n];`;
93
+ }
94
+ };
95
+ const serverResolvers = {
96
+ id: "#nitro-graphql/server-resolvers",
97
+ getCode: (nitro) => {
98
+ const ext = normalizeExtendConfig(nitro.options.graphql?.extend);
99
+ const skipLocalScan = nitro.options.graphql?.skipLocalScan === true;
100
+ if (ext && ext.resolvers.length > 0) {
101
+ const resolverPaths = ext.resolvers.map((p) => resolveExtendPath(nitro, p));
102
+ const imports$1 = resolverPaths.map((p, i) => `import { resolvers as resolvers${i} } from '${p}'`);
103
+ if (!skipLocalScan && nitro.scanResolvers.length > 0) {
104
+ const scannedCode = generateImportModule(nitro.scanResolvers, "scannedResolvers", "resolver");
105
+ const spreadAll$1 = [...resolverPaths.map((_, i) => `...resolvers${i}`), "...scannedResolvers"];
106
+ return `${imports$1.join("\n")}
107
+ ${scannedCode}
108
+
109
+ export const resolvers = [${spreadAll$1.join(", ")}]`;
110
+ }
111
+ if (resolverPaths.length === 1) return `export { resolvers } from '${resolverPaths[0]}'`;
112
+ const spreadAll = resolverPaths.map((_, i) => `...resolvers${i}`);
113
+ return `${imports$1.join("\n")}
114
+
115
+ export const resolvers = [${spreadAll.join(", ")}]`;
116
+ }
117
+ const imports = [...nitro.scanResolvers];
118
+ if (!imports.length) {
119
+ if (nitro.options.dev) nitro.logger.warn("[nitro-graphql] No resolvers found. Virtual module will export empty array.");
120
+ return "export const resolvers = []";
121
+ }
122
+ return generateImportModule(imports, "resolvers", "resolver");
123
+ }
124
+ };
125
+ const serverDirectives = {
126
+ id: "#nitro-graphql/server-directives",
127
+ getCode: (nitro) => {
128
+ const imports = nitro.scanDirectives || [];
129
+ if (!imports.length) return "export const directives = []";
130
+ return generateImportModule(imports, "directives", "directive");
131
+ }
132
+ };
133
+ const graphqlConfig = {
134
+ id: "#nitro-graphql/graphql-config",
135
+ getCode: (nitro) => {
136
+ return `import config from '${resolve(nitro.graphql.serverDir, "config.ts")}'
137
+ const importedConfig = config
138
+ export { importedConfig }
139
+ `;
140
+ }
141
+ };
142
+ const moduleConfig = {
143
+ id: "#nitro-graphql/module-config",
144
+ getCode: (nitro) => {
145
+ const config = nitro.options.graphql || {};
146
+ return `export const moduleConfig = ${JSON.stringify(config, null, 2)};`;
147
+ }
148
+ };
149
+ const debugInfo = {
150
+ id: "#nitro-graphql/debug-info",
151
+ getCode: (nitro) => {
152
+ const virtualModuleCodes = {
153
+ "server-schemas": safeGenerateModuleCode(nitro, "#nitro-graphql/server-schemas"),
154
+ "server-resolvers": safeGenerateModuleCode(nitro, "#nitro-graphql/server-resolvers"),
155
+ "server-directives": safeGenerateModuleCode(nitro, "#nitro-graphql/server-directives"),
156
+ "module-config": safeGenerateModuleCode(nitro, "#nitro-graphql/module-config"),
157
+ "graphql-config": safeGenerateModuleCode(nitro, "#nitro-graphql/graphql-config")
158
+ };
159
+ const info = {
160
+ isDev: nitro.options.dev,
161
+ framework: nitro.options.framework.name,
162
+ graphqlFramework: nitro.options.graphql?.framework,
163
+ federation: nitro.options.graphql?.federation,
164
+ scanned: {
165
+ schemas: nitro.scanSchemas?.length || 0,
166
+ schemaFiles: nitro.scanSchemas || [],
167
+ resolvers: nitro.scanResolvers?.length || 0,
168
+ resolverFiles: nitro.scanResolvers || [],
169
+ directives: nitro.scanDirectives?.length || 0,
170
+ directiveFiles: nitro.scanDirectives || [],
171
+ documents: nitro.scanDocuments?.length || 0,
172
+ documentFiles: nitro.scanDocuments || []
173
+ },
174
+ virtualModules: virtualModuleCodes
175
+ };
176
+ return `export const debugInfo = ${JSON.stringify(info, null, 2)};`;
177
+ }
178
+ };
179
+ const allModules = [
180
+ serverSchemas,
181
+ serverResolvers,
182
+ serverDirectives,
183
+ graphqlConfig,
184
+ moduleConfig,
185
+ debugInfo
186
+ ];
187
+ function registerAllVirtualModules(nitro) {
188
+ nitro.options.virtual ??= {};
189
+ for (const mod of allModules) nitro.options.virtual[mod.id] = () => mod.getCode(nitro);
190
+ }
191
+
192
+ //#endregion
193
+ export { debugInfo, graphqlConfig, moduleConfig, registerAllVirtualModules, serverDirectives, serverResolvers, serverSchemas };
@@ -0,0 +1,20 @@
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
+ //#endregion
20
+ export { debugInfo, directives, importedConfig, moduleConfig, resolvers, schemas };
@@ -0,0 +1,31 @@
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
+
30
+ //#endregion
31
+ export { debugInfo, directives, importedConfig, moduleConfig, 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
@@ -1,9 +1,9 @@
1
- import { getDefaultPaths, getTypesConfig, resolveFilePath } from "../utils/path-resolver.mjs";
1
+ import { getDefaultPaths, getTypesConfig, resolveFilePath } from "./nitro/paths.mjs";
2
2
  import { dirname, join, relative, resolve } from "pathe";
3
3
  import { existsSync, mkdirSync, writeFileSync } from "node:fs";
4
4
  import { defineNuxtModule, getLayerDirectories } from "@nuxt/kit";
5
5
 
6
- //#region src/ecosystem/nuxt.ts
6
+ //#region src/nuxt.ts
7
7
  var nuxt_default = defineNuxtModule({
8
8
  meta: {
9
9
  name: "nitro-graphql-nuxt",
@@ -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 { };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nitro-graphql",
3
3
  "type": "module",
4
- "version": "2.0.0-beta.36",
4
+ "version": "2.0.0-beta.38",
5
5
  "description": "GraphQL integration for Nitro",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -11,32 +11,32 @@
11
11
  "sideEffects": false,
12
12
  "imports": {
13
13
  "#graphql/server": {
14
- "types": "./dist/graphql/server.d.mts",
15
- "import": "./dist/graphql/server.mjs"
14
+ "types": "./dist/stubs/index.d.mts",
15
+ "import": "./dist/stubs/index.mjs"
16
16
  },
17
17
  "#nitro-graphql/graphql-config": {
18
- "types": "./dist/virtual/graphql-config.d.mts",
19
- "import": "./dist/virtual/graphql-config.mjs"
18
+ "types": "./dist/nitro/virtual/stubs.d.mts",
19
+ "import": "./dist/nitro/virtual/stubs.mjs"
20
20
  },
21
21
  "#nitro-graphql/server-schemas": {
22
- "types": "./dist/virtual/server-schemas.d.mts",
23
- "import": "./dist/virtual/server-schemas.mjs"
22
+ "types": "./dist/nitro/virtual/stubs.d.mts",
23
+ "import": "./dist/nitro/virtual/stubs.mjs"
24
24
  },
25
25
  "#nitro-graphql/server-resolvers": {
26
- "types": "./dist/virtual/server-resolvers.d.mts",
27
- "import": "./dist/virtual/server-resolvers.mjs"
26
+ "types": "./dist/nitro/virtual/stubs.d.mts",
27
+ "import": "./dist/nitro/virtual/stubs.mjs"
28
28
  },
29
29
  "#nitro-graphql/server-directives": {
30
- "types": "./dist/virtual/server-directives.d.mts",
31
- "import": "./dist/virtual/server-directives.mjs"
30
+ "types": "./dist/nitro/virtual/stubs.d.mts",
31
+ "import": "./dist/nitro/virtual/stubs.mjs"
32
32
  },
33
33
  "#nitro-graphql/module-config": {
34
- "types": "./dist/virtual/module-config.d.mts",
35
- "import": "./dist/virtual/module-config.mjs"
34
+ "types": "./dist/nitro/virtual/stubs.d.mts",
35
+ "import": "./dist/nitro/virtual/stubs.mjs"
36
36
  },
37
37
  "#nitro-graphql/debug-info": {
38
- "types": "./dist/virtual/debug-info.d.mts",
39
- "import": "./dist/virtual/debug-info.mjs"
38
+ "types": "./dist/nitro/virtual/stubs.d.mts",
39
+ "import": "./dist/nitro/virtual/stubs.mjs"
40
40
  }
41
41
  },
42
42
  "exports": {
@@ -44,33 +44,32 @@
44
44
  "types": "./dist/index.d.mts",
45
45
  "import": "./dist/index.mjs"
46
46
  },
47
- "./utils": {
48
- "types": "./dist/utils/index.d.mts",
49
- "import": "./dist/utils/index.mjs"
47
+ "./core": {
48
+ "types": "./dist/core/index.d.mts",
49
+ "import": "./dist/core/index.mjs"
50
+ },
51
+ "./cli": {
52
+ "types": "./dist/cli/index.d.mts",
53
+ "import": "./dist/cli/index.mjs"
50
54
  },
51
55
  "./define": {
52
56
  "types": "./dist/define.d.mts",
53
57
  "import": "./dist/define.mjs"
54
58
  },
55
- "./utils/apollo": {
56
- "types": "./dist/utils/apollo.d.mts",
57
- "import": "./dist/utils/apollo.mjs"
59
+ "./apollo": {
60
+ "types": "./dist/nitro/apollo.d.mts",
61
+ "import": "./dist/nitro/apollo.mjs"
58
62
  },
59
63
  "./nuxt": {
60
- "types": "./dist/ecosystem/nuxt.d.mts",
61
- "import": "./dist/ecosystem/nuxt.mjs"
62
- },
63
- "./vite": {
64
- "types": "./dist/vite.d.mts",
65
- "import": "./dist/vite.mjs"
66
- },
67
- "./types": {
68
- "types": "./dist/types/index.d.mts",
69
- "import": "./dist/types/index.mjs"
64
+ "types": "./dist/nuxt.d.mts",
65
+ "import": "./dist/nuxt.mjs"
70
66
  }
71
67
  },
72
68
  "module": "./dist/index.mjs",
73
69
  "types": "./dist/index.d.mts",
70
+ "bin": {
71
+ "nitro-graphql": "./dist/cli/index.mjs"
72
+ },
74
73
  "files": [
75
74
  "dist"
76
75
  ],
@@ -88,10 +87,11 @@
88
87
  "@apollo/subgraph": "^2.12.2",
89
88
  "@graphql-codegen/core": "^5.0.0",
90
89
  "@graphql-codegen/import-types-preset": "^3.0.1",
91
- "@graphql-codegen/typescript": "^5.0.6",
90
+ "@graphql-codegen/typed-document-node": "^6.1.5",
91
+ "@graphql-codegen/typescript": "^5.0.7",
92
92
  "@graphql-codegen/typescript-generic-sdk": "^4.0.2",
93
- "@graphql-codegen/typescript-operations": "^5.0.6",
94
- "@graphql-codegen/typescript-resolvers": "^5.1.4",
93
+ "@graphql-codegen/typescript-operations": "^5.0.7",
94
+ "@graphql-codegen/typescript-resolvers": "^5.1.5",
95
95
  "@graphql-tools/graphql-file-loader": "^8.1.8",
96
96
  "@graphql-tools/load": "^8.1.7",
97
97
  "@graphql-tools/load-files": "^7.0.1",
@@ -100,35 +100,36 @@
100
100
  "@graphql-tools/url-loader": "^9.0.5",
101
101
  "@graphql-tools/utils": "^10.11.0",
102
102
  "chokidar": "^5.0.0",
103
+ "citty": "^0.1.6",
103
104
  "consola": "^3.4.2",
104
105
  "defu": "^6.1.4",
105
106
  "graphql-config": "^5.1.5",
106
107
  "graphql-scalars": "^1.25.0",
107
108
  "knitwork": "^1.3.0",
108
109
  "ohash": "^2.0.11",
109
- "oxc-parser": "^0.102.0",
110
+ "oxc-parser": "^0.106.0",
110
111
  "pathe": "^2.0.3",
111
112
  "tinyglobby": "^0.2.15"
112
113
  },
113
114
  "devDependencies": {
114
- "@antfu/eslint-config": "^6.7.1",
115
+ "@antfu/eslint-config": "^6.7.3",
115
116
  "@nuxt/kit": "^4.2.2",
116
117
  "@nuxt/schema": "^4.2.2",
117
- "@types/node": "^24.10.4",
118
+ "@types/node": "^25.0.3",
118
119
  "@vitejs/devtools": "^0.0.0-alpha.16",
119
- "@vitest/ui": "^4.0.15",
120
+ "@vitest/ui": "^4.0.16",
120
121
  "bumpp": "^10.3.2",
121
122
  "changelogen": "^0.6.2",
122
123
  "crossws": "^0.4.1",
123
124
  "eslint": "^9.39.2",
124
125
  "graphql": "16.12.0",
125
126
  "graphql-yoga": "5.16.2",
126
- "nitro": "npm:nitro-nightly@latest",
127
- "tsdown": "^0.17.4",
127
+ "nitro": "3.0.1-alpha.1",
128
+ "tsdown": "^0.18.4",
128
129
  "typescript": "^5.9.3",
129
- "vite": "8.0.0-beta.0",
130
- "vitepress-plugin-llms": "^1.9.3",
131
- "vitest": "^4.0.15"
130
+ "vite": "8.0.0-beta.5",
131
+ "vitepress-plugin-llms": "^1.10.0",
132
+ "vitest": "^4.0.16"
132
133
  },
133
134
  "resolutions": {
134
135
  "nitro-graphql": "link:."
@@ -144,6 +145,7 @@
144
145
  "docs:dev": "cd .docs && pnpm install && pnpm update:metadata && pnpm dev",
145
146
  "docs:build": "cd .docs && pnpm install && pnpm update:metadata && pnpm build",
146
147
  "docs:preview": "cd .docs && pnpm preview",
148
+ "cli": "node ./dist/cli/index.mjs",
147
149
  "lint": "eslint .",
148
150
  "lint:fix": "eslint . --fix",
149
151
  "test": "vitest",
@@ -1,13 +0,0 @@
1
- import { Nitro } from "nitro/types";
2
-
3
- //#region src/codegen/client-types.d.ts
4
-
5
- /**
6
- * Generate main client types (for the default service)
7
- */
8
- declare function generateMainClientTypes(nitro: Nitro, options?: {
9
- silent?: boolean;
10
- isInitial?: boolean;
11
- }): Promise<void>;
12
- //#endregion
13
- export { generateMainClientTypes };
@@ -1,131 +0,0 @@
1
- import { FILE_INDEX_TS, LOG_TAG, SERVICE_DEFAULT } from "../constants.mjs";
2
- import { generateClientTypes, loadGraphQLDocuments } from "../utils/client-codegen.mjs";
3
- import { loadFederationSupport } from "../utils/federation.mjs";
4
- import { writeFileIfNotExists } from "../utils/file-generator.mjs";
5
- import { generateOfetchTemplate } from "../utils/ofetch-templates.mjs";
6
- import { getClientUtilsConfig, getDefaultPaths, getSdkConfig, getTypesConfig, resolveFilePath, shouldGenerateClientUtils } from "../utils/path-resolver.mjs";
7
- import consola from "consola";
8
- import { dirname, join, resolve } from "pathe";
9
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
10
- import { buildSchema, parse } from "graphql";
11
-
12
- //#region src/codegen/client-types.ts
13
- const logger = consola.withTag(LOG_TAG);
14
- /**
15
- * Check for old structure files and warn user about manual migration
16
- */
17
- function warnLegacyGraphQLStructure(clientDir) {
18
- const oldOfetchPath = resolve(clientDir, "ofetch.ts");
19
- const oldSdkPath = resolve(clientDir, "sdk.ts");
20
- if (existsSync(oldOfetchPath) || existsSync(oldSdkPath)) {
21
- const foundFiles = [];
22
- if (existsSync(oldOfetchPath)) foundFiles.push("app/graphql/ofetch.ts");
23
- if (existsSync(oldSdkPath)) foundFiles.push("app/graphql/sdk.ts");
24
- consola.error(`⚠️ OLD GRAPHQL STRUCTURE DETECTED!
25
-
26
- 📁 Found old files in app/graphql/ directory that need to be moved:
27
- • ${foundFiles.join("\n • ")}
28
-
29
- 🔄 Please manually move these files to the new structure:
30
- • app/graphql/ofetch.ts → app/graphql/default/ofetch.ts
31
- • app/graphql/sdk.ts → app/graphql/default/sdk.ts
32
-
33
- 📝 Also update your app/graphql/index.ts to include:
34
- export * from './default/ofetch'
35
-
36
- 💡 After moving, update your imports to use:
37
- import { $sdk } from "#graphql/client"
38
-
39
- 🚫 The old files will cause import conflicts until moved!`);
40
- }
41
- }
42
- /**
43
- * Generate main client types (for the default service)
44
- */
45
- async function generateMainClientTypes(nitro, options = {}) {
46
- warnLegacyGraphQLStructure(nitro.graphql.clientDir);
47
- const docs = nitro.scanDocuments;
48
- const loadedDocs = await loadGraphQLDocuments(docs);
49
- const schemaFilePath = join(nitro.graphql.buildDir, "schema.graphql");
50
- if (!existsSync(schemaFilePath)) {
51
- if (!options.silent) consola.info("Schema file not ready yet for client type generation. Server types need to be generated first.");
52
- return;
53
- }
54
- const graphqlString = readFileSync(schemaFilePath, "utf-8");
55
- const federationEnabled = nitro.options.graphql?.federation?.enabled === true;
56
- let schema;
57
- if (federationEnabled) {
58
- const buildSubgraph = await loadFederationSupport();
59
- if (!buildSubgraph) throw new Error("Federation is enabled but @apollo/subgraph is not installed. Run: pnpm add @apollo/subgraph");
60
- schema = buildSubgraph([{ typeDefs: parse(graphqlString) }]);
61
- } else schema = buildSchema(graphqlString);
62
- const types = await generateClientTypes(schema, loadedDocs, nitro.options.graphql?.codegen?.client ?? {}, nitro.options.graphql?.codegen?.clientSDK ?? {}, void 0, void 0, void 0, options);
63
- if (types === false) return;
64
- const placeholders = getDefaultPaths(nitro);
65
- const typesConfig = getTypesConfig(nitro);
66
- const sdkConfig = getSdkConfig(nitro);
67
- const clientTypesPath = resolveFilePath(typesConfig.client, typesConfig.enabled, true, "{typesDir}/nitro-graphql-client.d.ts", placeholders);
68
- if (clientTypesPath) {
69
- mkdirSync(dirname(clientTypesPath), { recursive: true });
70
- writeFileSync(clientTypesPath, types.types, "utf-8");
71
- if (!options.silent) logger.success(`Generated client types at: ${clientTypesPath}`);
72
- }
73
- const sdkPath = resolveFilePath(sdkConfig.main, sdkConfig.enabled, true, "{clientGraphql}/default/sdk.ts", placeholders);
74
- if (sdkPath) {
75
- mkdirSync(dirname(sdkPath), { recursive: true });
76
- writeFileSync(sdkPath, types.sdk, "utf-8");
77
- if (!options.silent) logger.success(`Generated SDK at: ${sdkPath}`);
78
- }
79
- generateNuxtOfetchClient(nitro, nitro.graphql.clientDir, SERVICE_DEFAULT);
80
- const externalServices = nitro.options.graphql?.externalServices || [];
81
- if (externalServices.length > 0) generateGraphQLIndexFile(nitro, nitro.graphql.clientDir, externalServices);
82
- }
83
- /**
84
- * Generate GraphQL index file that exports all services
85
- */
86
- function generateGraphQLIndexFile(nitro, clientDir, externalServices = []) {
87
- if (!shouldGenerateClientUtils(nitro)) return;
88
- const placeholders = getDefaultPaths(nitro);
89
- const clientUtilsConfig = getClientUtilsConfig(nitro);
90
- const indexPath = resolveFilePath(clientUtilsConfig.index, clientUtilsConfig.enabled, true, `{clientGraphql}/${FILE_INDEX_TS}`, placeholders);
91
- if (!indexPath) return;
92
- if (!existsSync(indexPath)) {
93
- let indexContent = `// This file is auto-generated once by nitro-graphql for quick start
94
- // You can modify this file according to your needs
95
- //
96
- // Export your main GraphQL service (auto-generated)
97
- export * from './default/ofetch'
98
-
99
- // Export external GraphQL services (auto-generated for existing services)
100
- // When you add new external services, don't forget to add their exports here:
101
- // export * from './yourServiceName/ofetch'
102
- `;
103
- for (const service of externalServices) indexContent += `export * from './${service.name}/ofetch'\n`;
104
- writeFileIfNotExists(indexPath, indexContent, `client ${FILE_INDEX_TS}`);
105
- }
106
- }
107
- /**
108
- * Generate ofetch client wrapper for Nuxt/Nitro
109
- */
110
- function generateNuxtOfetchClient(nitro, clientDir, serviceName = SERVICE_DEFAULT) {
111
- if (!shouldGenerateClientUtils(nitro)) return;
112
- const placeholders = {
113
- ...getDefaultPaths(nitro),
114
- serviceName
115
- };
116
- const clientUtilsConfig = getClientUtilsConfig(nitro);
117
- const ofetchPath = resolveFilePath(clientUtilsConfig.ofetch, clientUtilsConfig.enabled, true, "{clientGraphql}/{serviceName}/ofetch.ts", placeholders);
118
- if (!ofetchPath) return;
119
- const serviceDir = dirname(ofetchPath);
120
- if (!existsSync(serviceDir)) mkdirSync(serviceDir, { recursive: true });
121
- if (existsSync(ofetchPath)) return;
122
- writeFileIfNotExists(ofetchPath, generateOfetchTemplate({
123
- serviceName,
124
- isNuxt: nitro.options.framework?.name === "nuxt",
125
- endpoint: "/api/graphql",
126
- isExternal: false
127
- }), `${serviceName} ofetch.ts`);
128
- }
129
-
130
- //#endregion
131
- export { generateMainClientTypes };
@@ -1,12 +0,0 @@
1
- import { Nitro } from "nitro/types";
2
-
3
- //#region src/codegen/external-types.d.ts
4
-
5
- /**
6
- * Generate types for all external GraphQL services
7
- */
8
- declare function generateExternalServicesTypes(nitro: Nitro, options?: {
9
- silent?: boolean;
10
- }): Promise<void>;
11
- //#endregion
12
- export { generateExternalServicesTypes };