nitro-graphql 2.0.0-beta.31 → 2.0.0-beta.33

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 (86) hide show
  1. package/dist/codegen/client-types.d.mts +13 -0
  2. package/dist/codegen/client-types.mjs +131 -0
  3. package/dist/codegen/external-types.d.mts +12 -0
  4. package/dist/codegen/external-types.mjs +88 -0
  5. package/dist/codegen/index.d.mts +18 -0
  6. package/dist/codegen/index.mjs +24 -0
  7. package/dist/codegen/server-types.d.mts +13 -0
  8. package/dist/codegen/server-types.mjs +64 -0
  9. package/dist/codegen/validation.d.mts +13 -0
  10. package/dist/codegen/validation.mjs +96 -0
  11. package/dist/config/defaults.mjs +36 -0
  12. package/dist/constants/scalars.mjs +27 -0
  13. package/dist/constants.mjs +106 -0
  14. package/dist/ecosystem/nuxt.mjs +3 -3
  15. package/dist/rollup.d.mts +2 -8
  16. package/dist/rollup.mjs +24 -199
  17. package/dist/routes/apollo-server.d.mts +2 -2
  18. package/dist/routes/apollo-server.mjs +7 -51
  19. package/dist/routes/debug-template.d.mts +15 -0
  20. package/dist/routes/debug-template.mjs +385 -0
  21. package/dist/routes/debug.d.mts +2 -2
  22. package/dist/routes/debug.mjs +1 -344
  23. package/dist/routes/graphql-yoga.d.mts +2 -2
  24. package/dist/routes/graphql-yoga.mjs +7 -51
  25. package/dist/routes/health.d.mts +2 -2
  26. package/dist/setup/file-watcher.mjs +84 -0
  27. package/dist/setup/graphql-scanner.mjs +25 -0
  28. package/dist/setup/rollup-integration.mjs +90 -0
  29. package/dist/setup/scaffold-generator.mjs +109 -0
  30. package/dist/setup/ts-config.mjs +69 -0
  31. package/dist/setup.d.mts +2 -2
  32. package/dist/setup.mjs +147 -303
  33. package/dist/types/index.d.mts +2 -2
  34. package/dist/utils/client-codegen.d.mts +1 -1
  35. package/dist/utils/client-codegen.mjs +5 -28
  36. package/dist/utils/codegen-plugin.d.mts +20 -0
  37. package/dist/utils/codegen-plugin.mjs +30 -0
  38. package/dist/utils/directive-parser.d.mts +2 -1
  39. package/dist/utils/directive-parser.mjs +4 -2
  40. package/dist/utils/federation.d.mts +29 -0
  41. package/dist/utils/federation.mjs +40 -0
  42. package/dist/utils/file-generator.mjs +1 -1
  43. package/dist/utils/file-writer.d.mts +35 -0
  44. package/dist/utils/file-writer.mjs +32 -0
  45. package/dist/utils/imports.d.mts +15 -0
  46. package/dist/utils/imports.mjs +25 -0
  47. package/dist/utils/index.d.mts +11 -38
  48. package/dist/utils/index.mjs +10 -287
  49. package/dist/utils/layers.d.mts +22 -0
  50. package/dist/utils/layers.mjs +28 -0
  51. package/dist/utils/ofetch-templates.d.mts +30 -0
  52. package/dist/utils/ofetch-templates.mjs +135 -0
  53. package/dist/utils/path-resolver.d.mts +2 -2
  54. package/dist/utils/path-resolver.mjs +2 -2
  55. package/dist/utils/scanning/common.d.mts +23 -0
  56. package/dist/utils/scanning/common.mjs +39 -0
  57. package/dist/utils/scanning/directives.d.mts +11 -0
  58. package/dist/utils/scanning/directives.mjs +43 -0
  59. package/dist/utils/scanning/documents.d.mts +15 -0
  60. package/dist/utils/scanning/documents.mjs +46 -0
  61. package/dist/utils/scanning/index.d.mts +6 -0
  62. package/dist/utils/scanning/index.mjs +7 -0
  63. package/dist/utils/scanning/resolvers.d.mts +11 -0
  64. package/dist/utils/scanning/resolvers.mjs +100 -0
  65. package/dist/utils/scanning/schemas.d.mts +15 -0
  66. package/dist/utils/scanning/schemas.mjs +29 -0
  67. package/dist/utils/schema-builder.d.mts +48 -0
  68. package/dist/utils/schema-builder.mjs +51 -0
  69. package/dist/utils/server-codegen.mjs +4 -27
  70. package/dist/utils/type-generation.d.mts +6 -12
  71. package/dist/utils/type-generation.mjs +6 -419
  72. package/dist/utils/validation.d.mts +11 -0
  73. package/dist/utils/validation.mjs +34 -0
  74. package/dist/virtual/generators/config.d.mts +22 -0
  75. package/dist/virtual/generators/config.mjs +36 -0
  76. package/dist/virtual/generators/debug.d.mts +14 -0
  77. package/dist/virtual/generators/debug.mjs +53 -0
  78. package/dist/virtual/generators/directives.d.mts +14 -0
  79. package/dist/virtual/generators/directives.mjs +52 -0
  80. package/dist/virtual/generators/index.d.mts +6 -0
  81. package/dist/virtual/generators/index.mjs +7 -0
  82. package/dist/virtual/generators/resolvers.d.mts +14 -0
  83. package/dist/virtual/generators/resolvers.mjs +55 -0
  84. package/dist/virtual/generators/schemas.d.mts +14 -0
  85. package/dist/virtual/generators/schemas.mjs +43 -0
  86. package/package.json +75 -57
package/dist/rollup.d.mts CHANGED
@@ -1,12 +1,6 @@
1
1
  import { Nitro } from "nitro/types";
2
2
 
3
3
  //#region src/rollup.d.ts
4
- declare function rollupConfig(app: Nitro): Promise<void>;
5
- declare function virtualSchemas(app: Nitro): void;
6
- declare function virtualResolvers(app: Nitro): void;
7
- declare function virtualDirectives(app: Nitro): void;
8
- declare function getGraphQLConfig(app: Nitro): void;
9
- declare function virtualModuleConfig(app: Nitro): void;
10
- declare function virtualDebugInfo(app: Nitro): void;
4
+ declare function rollupConfig(nitro: Nitro): Promise<void>;
11
5
  //#endregion
12
- export { getGraphQLConfig, rollupConfig, virtualDebugInfo, virtualDirectives, virtualModuleConfig, virtualResolvers, virtualSchemas };
6
+ export { rollupConfig };
package/dist/rollup.mjs CHANGED
@@ -1,29 +1,33 @@
1
- import { getImportId, scanGraphql } from "./utils/index.mjs";
2
- import { clientTypeGeneration, serverTypeGeneration } from "./utils/type-generation.mjs";
1
+ import { generateServerTypes } from "./codegen/server-types.mjs";
2
+ import { generateClientTypes } from "./codegen/index.mjs";
3
+ import { scanGraphql } from "./utils/scanning/schemas.mjs";
4
+ import { virtualGraphQLConfig, virtualModuleConfig } from "./virtual/generators/config.mjs";
5
+ import { virtualDebugInfo } from "./virtual/generators/debug.mjs";
6
+ import { virtualDirectives } from "./virtual/generators/directives.mjs";
7
+ import { virtualResolvers } from "./virtual/generators/resolvers.mjs";
8
+ import { virtualSchemas } from "./virtual/generators/schemas.mjs";
3
9
  import { readFile } from "node:fs/promises";
4
10
  import { fileURLToPath } from "node:url";
5
- import { resolve } from "pathe";
6
11
  import { parse } from "graphql";
7
- import { genImport } from "knitwork";
8
12
 
9
13
  //#region src/rollup.ts
10
- async function rollupConfig(app) {
11
- virtualSchemas(app);
12
- virtualResolvers(app);
13
- virtualDirectives(app);
14
- getGraphQLConfig(app);
15
- virtualModuleConfig(app);
16
- virtualDebugInfo(app);
17
- app.hooks.hook("rollup:before", (nitro, rollupConfig$1) => {
14
+ async function rollupConfig(nitro) {
15
+ virtualSchemas(nitro);
16
+ virtualResolvers(nitro);
17
+ virtualDirectives(nitro);
18
+ virtualGraphQLConfig(nitro);
19
+ virtualModuleConfig(nitro);
20
+ virtualDebugInfo(nitro);
21
+ nitro.hooks.hook("rollup:before", (_, rollupConfig$1) => {
18
22
  rollupConfig$1.plugins = rollupConfig$1.plugins || [];
19
- const { include = /\.(?:graphql|gql)$/i, exclude, validate = false } = app.options.graphql?.loader || {};
23
+ const { include = /\.(?:graphql|gql)$/i, exclude, validate = false } = nitro.options.graphql?.loader || {};
20
24
  if (Array.isArray(rollupConfig$1.plugins)) {
21
25
  rollupConfig$1.plugins.push({
22
26
  name: "nitro-graphql:virtual",
23
27
  resolveId: {
24
28
  order: "pre",
25
29
  filter: { id: /^#nitro-graphql\// },
26
- async handler(id, parent, options) {
30
+ async handler(id, parent, _options) {
27
31
  if (id.startsWith("#nitro-graphql/")) return `\0virtual:${id}`;
28
32
  if (parent?.startsWith("\0virtual:#nitro-graphql")) {
29
33
  const runtimeDir = fileURLToPath(new URL("routes", import.meta.url));
@@ -41,7 +45,7 @@ async function rollupConfig(app) {
41
45
  async handler(id) {
42
46
  if (id.startsWith("\0virtual:#nitro-graphql/")) {
43
47
  const moduleName = id.slice(9);
44
- const generator = app.options.virtual?.[moduleName];
48
+ const generator = nitro.options.virtual?.[moduleName];
45
49
  if (typeof generator === "function") try {
46
50
  return {
47
51
  code: await generator(),
@@ -81,7 +85,7 @@ async function rollupConfig(app) {
81
85
  }
82
86
  }
83
87
  });
84
- if (app.options.dev) rollupConfig$1.plugins.push({
88
+ if (nitro.options.dev) rollupConfig$1.plugins.push({
85
89
  name: "nitro-graphql-watcher",
86
90
  buildStart: {
87
91
  order: "pre",
@@ -93,190 +97,11 @@ async function rollupConfig(app) {
93
97
  });
94
98
  }
95
99
  });
96
- app.hooks.hook("dev:reload", async () => {
97
- await serverTypeGeneration(app, { silent: true });
98
- await clientTypeGeneration(app, { silent: true });
100
+ nitro.hooks.hook("dev:reload", async () => {
101
+ await generateServerTypes(nitro, { silent: true });
102
+ await generateClientTypes(nitro, { silent: true });
99
103
  });
100
104
  }
101
- function virtualSchemas(app) {
102
- const getSchemas = () => [...app.scanSchemas, ...app.options.graphql?.typedefs ?? []];
103
- app.options.virtual ??= {};
104
- app.options.virtual["#nitro-graphql/server-schemas"] = () => {
105
- try {
106
- const imports = getSchemas();
107
- if (imports.length === 0) {
108
- if (app.options.dev) app.logger.warn("[nitro-graphql] No schemas found. Virtual module will export empty array.");
109
- return "export const schemas = []";
110
- }
111
- const importStatements = imports.map((handler) => `import ${getImportId(handler)} from '${handler}';`);
112
- const schemaArray = imports.map((h) => `{ def: ${getImportId(h)} }`);
113
- return `
114
- ${importStatements.join("\n")}
115
-
116
- export const schemas = [
117
- ${schemaArray.join(",\n")}
118
- ];
119
- `;
120
- } catch (error) {
121
- app.logger.error("[nitro-graphql] Failed to generate virtual schema module:", error);
122
- return "export const schemas = []";
123
- }
124
- };
125
- }
126
- function virtualResolvers(app) {
127
- const getResolvers = () => [...app.scanResolvers];
128
- app.options.virtual ??= {};
129
- app.options.virtual["#nitro-graphql/server-resolvers"] = () => {
130
- try {
131
- const imports = getResolvers();
132
- if (imports.length === 0) {
133
- if (app.options.dev) app.logger.warn("[nitro-graphql] No resolvers found. Virtual module will export empty array.");
134
- return "export const resolvers = []";
135
- }
136
- const importsContent = [];
137
- const invalidImports = [];
138
- for (const { specifier, imports: importList, options } of imports) try {
139
- if (!importList || importList.length === 0) {
140
- invalidImports.push(`${specifier}: No exports found`);
141
- continue;
142
- }
143
- const importCode = genImport(specifier, importList, options);
144
- importsContent.push(importCode);
145
- } catch (error) {
146
- const message = error instanceof Error ? error.message : String(error);
147
- invalidImports.push(`${specifier}: ${message}`);
148
- if (app.options.dev) app.logger.error(`[nitro-graphql] Failed to generate import for ${specifier}:`, error);
149
- }
150
- if (invalidImports.length > 0 && app.options.dev) {
151
- app.logger.warn("[nitro-graphql] Some resolver imports could not be generated:");
152
- for (const msg of invalidImports) app.logger.warn(` - ${msg}`);
153
- }
154
- const data = imports.map(({ imports: importList }) => importList.map((i) => `{ resolver: ${i.as} }`).join(",\n")).filter(Boolean).join(",\n");
155
- return [
156
- ...importsContent,
157
- "",
158
- "export const resolvers = [",
159
- data,
160
- "]",
161
- ""
162
- ].join("\n");
163
- } catch (error) {
164
- app.logger.error("[nitro-graphql] Failed to generate virtual resolver module:", error);
165
- return "export const resolvers = []";
166
- }
167
- };
168
- }
169
- function virtualDirectives(app) {
170
- const getDirectives = () => app.scanDirectives || [];
171
- app.options.virtual ??= {};
172
- app.options.virtual["#nitro-graphql/server-directives"] = () => {
173
- try {
174
- const imports = getDirectives();
175
- if (imports.length === 0) return "export const directives = []";
176
- const importsContent = [];
177
- const invalidImports = [];
178
- for (const { specifier, imports: importList, options } of imports) try {
179
- if (!importList || importList.length === 0) {
180
- invalidImports.push(`${specifier}: No exports found`);
181
- continue;
182
- }
183
- const importCode = genImport(specifier, importList, options);
184
- importsContent.push(importCode);
185
- } catch (error) {
186
- const message = error instanceof Error ? error.message : String(error);
187
- invalidImports.push(`${specifier}: ${message}`);
188
- if (app.options.dev) app.logger.error(`[nitro-graphql] Failed to generate import for directive ${specifier}:`, error);
189
- }
190
- if (invalidImports.length > 0 && app.options.dev) {
191
- app.logger.warn("[nitro-graphql] Some directive imports could not be generated:");
192
- for (const msg of invalidImports) app.logger.warn(` - ${msg}`);
193
- }
194
- const data = imports.map(({ imports: importList }) => importList.map((i) => `{ directive: ${i.as} }`).join(",\n")).filter(Boolean).join(",\n");
195
- return [
196
- ...importsContent,
197
- "",
198
- "export const directives = [",
199
- data,
200
- "]",
201
- ""
202
- ].join("\n");
203
- } catch (error) {
204
- app.logger.error("[nitro-graphql] Failed to generate virtual directive module:", error);
205
- return "export const directives = []";
206
- }
207
- };
208
- }
209
- function getGraphQLConfig(app) {
210
- const configPath = resolve(app.graphql.serverDir, "config.ts");
211
- app.options.virtual ??= {};
212
- app.options.virtual["#nitro-graphql/graphql-config"] = () => {
213
- return `import config from '${configPath}'
214
- const importedConfig = config
215
- export { importedConfig }
216
- `;
217
- };
218
- }
219
- function virtualModuleConfig(app) {
220
- app.options.virtual ??= {};
221
- app.options.virtual["#nitro-graphql/module-config"] = () => {
222
- const moduleConfig = app.options.graphql || {};
223
- return `export const moduleConfig = ${JSON.stringify(moduleConfig, null, 2)};`;
224
- };
225
- }
226
- function virtualDebugInfo(app) {
227
- app.options.virtual ??= {};
228
- app.options.virtual["#nitro-graphql/debug-info"] = () => {
229
- const virtualModuleCodes = {};
230
- try {
231
- const schemasGenerator = app.options.virtual["#nitro-graphql/server-schemas"];
232
- if (schemasGenerator && typeof schemasGenerator === "function") virtualModuleCodes["server-schemas"] = schemasGenerator();
233
- } catch (error) {
234
- virtualModuleCodes["server-schemas"] = `// Error generating: ${error instanceof Error ? error.message : String(error)}`;
235
- }
236
- try {
237
- const resolversGenerator = app.options.virtual["#nitro-graphql/server-resolvers"];
238
- if (resolversGenerator && typeof resolversGenerator === "function") virtualModuleCodes["server-resolvers"] = resolversGenerator();
239
- } catch (error) {
240
- virtualModuleCodes["server-resolvers"] = `// Error generating: ${error instanceof Error ? error.message : String(error)}`;
241
- }
242
- try {
243
- const directivesGenerator = app.options.virtual["#nitro-graphql/server-directives"];
244
- if (directivesGenerator && typeof directivesGenerator === "function") virtualModuleCodes["server-directives"] = directivesGenerator();
245
- } catch (error) {
246
- virtualModuleCodes["server-directives"] = `// Error generating: ${error instanceof Error ? error.message : String(error)}`;
247
- }
248
- try {
249
- const moduleConfigGenerator = app.options.virtual["#nitro-graphql/module-config"];
250
- if (moduleConfigGenerator && typeof moduleConfigGenerator === "function") virtualModuleCodes["module-config"] = moduleConfigGenerator();
251
- } catch (error) {
252
- virtualModuleCodes["module-config"] = `// Error generating: ${error instanceof Error ? error.message : String(error)}`;
253
- }
254
- try {
255
- const graphqlConfigGenerator = app.options.virtual["#nitro-graphql/graphql-config"];
256
- if (graphqlConfigGenerator && typeof graphqlConfigGenerator === "function") virtualModuleCodes["graphql-config"] = graphqlConfigGenerator();
257
- } catch (error) {
258
- virtualModuleCodes["graphql-config"] = `// Error generating: ${error instanceof Error ? error.message : String(error)}`;
259
- }
260
- const debugInfo = {
261
- isDev: app.options.dev,
262
- framework: app.options.framework.name,
263
- graphqlFramework: app.options.graphql?.framework,
264
- federation: app.options.graphql?.federation,
265
- scanned: {
266
- schemas: app.scanSchemas?.length || 0,
267
- schemaFiles: app.scanSchemas || [],
268
- resolvers: app.scanResolvers?.length || 0,
269
- resolverFiles: app.scanResolvers || [],
270
- directives: app.scanDirectives?.length || 0,
271
- directiveFiles: app.scanDirectives || [],
272
- documents: app.scanDocuments?.length || 0,
273
- documentFiles: app.scanDocuments || []
274
- },
275
- virtualModules: virtualModuleCodes
276
- };
277
- return `export const debugInfo = ${JSON.stringify(debugInfo, null, 2)};`;
278
- };
279
- }
280
105
 
281
106
  //#endregion
282
- export { getGraphQLConfig, rollupConfig, virtualDebugInfo, virtualDirectives, virtualModuleConfig, virtualResolvers, virtualSchemas };
107
+ export { rollupConfig };
@@ -1,6 +1,6 @@
1
- import * as nitro_deps_h31 from "nitro/deps/h3";
1
+ import * as nitro_deps_h30 from "nitro/deps/h3";
2
2
 
3
3
  //#region src/routes/apollo-server.d.ts
4
- declare const _default: nitro_deps_h31.EventHandlerWithFetch<nitro_deps_h31.EventHandlerRequest, Promise<any>>;
4
+ declare const _default: nitro_deps_h30.EventHandlerWithFetch<nitro_deps_h30.EventHandlerRequest, Promise<any>>;
5
5
  //#endregion
6
6
  export { _default as default };
@@ -1,7 +1,5 @@
1
+ import { createMergedSchema } from "../utils/schema-builder.mjs";
1
2
  import defu from "defu";
2
- import { consola as consola$1 } from "consola";
3
- import { parse } from "graphql";
4
- import { mergeResolvers, mergeTypeDefs } from "@graphql-tools/merge";
5
3
  import { importedConfig } from "#nitro-graphql/graphql-config";
6
4
  import { moduleConfig } from "#nitro-graphql/module-config";
7
5
  import { directives } from "#nitro-graphql/server-directives";
@@ -9,63 +7,21 @@ import { resolvers } from "#nitro-graphql/server-resolvers";
9
7
  import { schemas } from "#nitro-graphql/server-schemas";
10
8
  import { ApolloServer } from "@apollo/server";
11
9
  import { ApolloServerPluginLandingPageLocalDefault } from "@apollo/server/plugin/landingPage/default";
12
- import { makeExecutableSchema } from "@graphql-tools/schema";
13
10
  import { startServerAndCreateH3Handler } from "nitro-graphql/utils/apollo";
14
11
  import { defineEventHandler } from "nitro/h3";
15
12
 
16
13
  //#region src/routes/apollo-server.ts
17
- let buildSubgraphSchema = null;
18
- async function loadFederationSupport() {
19
- if (buildSubgraphSchema !== null) return buildSubgraphSchema;
20
- try {
21
- buildSubgraphSchema = (await import("@apollo/subgraph")).buildSubgraphSchema;
22
- } catch {
23
- buildSubgraphSchema = false;
24
- }
25
- return buildSubgraphSchema;
26
- }
27
- async function createMergedSchema() {
28
- try {
29
- const typeDefs = mergeTypeDefs([schemas.map((schema$1) => schema$1.def).join("\n\n")], {
30
- throwOnConflict: true,
31
- commentDescriptions: true,
32
- sort: true
33
- });
34
- const mergedResolvers = mergeResolvers(resolvers.map((r) => r.resolver));
35
- const federationEnabled = moduleConfig.federation?.enabled;
36
- let schema;
37
- if (federationEnabled) {
38
- const buildSubgraph = await loadFederationSupport();
39
- if (buildSubgraph) schema = buildSubgraph({
40
- typeDefs: typeof typeDefs === "string" ? parse(typeDefs) : typeDefs,
41
- resolvers: mergedResolvers
42
- });
43
- else {
44
- console.warn("Federation enabled but @apollo/subgraph not available, falling back to regular schema");
45
- schema = makeExecutableSchema({
46
- typeDefs,
47
- resolvers: mergedResolvers
48
- });
49
- }
50
- } else schema = makeExecutableSchema({
51
- typeDefs,
52
- resolvers: mergedResolvers
53
- });
54
- if (directives && directives.length > 0) {
55
- for (const { directive } of directives) if (directive.transformer) schema = directive.transformer(schema);
56
- }
57
- return schema;
58
- } catch (error) {
59
- consola$1.error("Schema merge error:", error);
60
- throw error;
61
- }
62
- }
63
14
  let apolloServer = null;
64
15
  let serverStarted = false;
65
16
  async function createApolloServer() {
66
17
  if (!apolloServer) {
67
18
  apolloServer = new ApolloServer(defu({
68
- schema: await createMergedSchema(),
19
+ schema: await createMergedSchema({
20
+ schemas,
21
+ resolvers,
22
+ directives,
23
+ moduleConfig
24
+ }),
69
25
  introspection: true,
70
26
  plugins: [ApolloServerPluginLandingPageLocalDefault({ embed: true })]
71
27
  }, importedConfig));
@@ -0,0 +1,15 @@
1
+ //#region src/routes/debug-template.d.ts
2
+ /**
3
+ * Debug dashboard HTML template
4
+ * Extracted from debug.ts to reduce file complexity
5
+ */
6
+ /**
7
+ * Escape HTML special characters
8
+ */
9
+ declare function escapeHtml(text: string): string;
10
+ /**
11
+ * Generate the HTML dashboard for the debug endpoint
12
+ */
13
+ declare function generateHtmlDashboard(debugInfo: any): string;
14
+ //#endregion
15
+ export { escapeHtml, generateHtmlDashboard };