nitro-graphql 2.0.0-beta.32 → 2.0.0-beta.34

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 (71) hide show
  1. package/dist/codegen/client-types.mjs +9 -54
  2. package/dist/codegen/external-types.mjs +7 -48
  3. package/dist/codegen/index.d.mts +4 -11
  4. package/dist/codegen/index.mjs +1 -15
  5. package/dist/codegen/server-types.mjs +2 -14
  6. package/dist/constants/scalars.mjs +27 -0
  7. package/dist/constants.mjs +16 -1
  8. package/dist/rollup.d.mts +1 -7
  9. package/dist/rollup.mjs +12 -187
  10. package/dist/routes/apollo-server.d.mts +2 -2
  11. package/dist/routes/apollo-server.mjs +7 -51
  12. package/dist/routes/debug-template.d.mts +15 -0
  13. package/dist/routes/debug-template.mjs +385 -0
  14. package/dist/routes/debug.d.mts +2 -2
  15. package/dist/routes/debug.mjs +1 -344
  16. package/dist/routes/graphql-yoga.d.mts +2 -2
  17. package/dist/routes/graphql-yoga.mjs +7 -51
  18. package/dist/routes/health.d.mts +2 -2
  19. package/dist/setup/file-watcher.mjs +9 -5
  20. package/dist/setup/graphql-scanner.mjs +25 -0
  21. package/dist/setup/scaffold-generator.mjs +1 -1
  22. package/dist/setup/ts-config.mjs +1 -1
  23. package/dist/setup.mjs +38 -47
  24. package/dist/types/index.d.mts +1 -1
  25. package/dist/utils/client-codegen.mjs +4 -30
  26. package/dist/utils/codegen-plugin.d.mts +20 -0
  27. package/dist/utils/codegen-plugin.mjs +30 -0
  28. package/dist/utils/federation.d.mts +29 -0
  29. package/dist/utils/federation.mjs +40 -0
  30. package/dist/utils/file-writer.d.mts +35 -0
  31. package/dist/utils/file-writer.mjs +32 -0
  32. package/dist/utils/imports.d.mts +15 -0
  33. package/dist/utils/imports.mjs +25 -0
  34. package/dist/utils/index.d.mts +11 -38
  35. package/dist/utils/index.mjs +10 -287
  36. package/dist/utils/layers.d.mts +22 -0
  37. package/dist/utils/layers.mjs +28 -0
  38. package/dist/utils/ofetch-templates.d.mts +30 -0
  39. package/dist/utils/ofetch-templates.mjs +135 -0
  40. package/dist/utils/scanning/common.d.mts +23 -0
  41. package/dist/utils/scanning/common.mjs +39 -0
  42. package/dist/utils/scanning/directives.d.mts +11 -0
  43. package/dist/utils/scanning/directives.mjs +43 -0
  44. package/dist/utils/scanning/documents.d.mts +15 -0
  45. package/dist/utils/scanning/documents.mjs +46 -0
  46. package/dist/utils/scanning/index.d.mts +6 -0
  47. package/dist/utils/scanning/index.mjs +7 -0
  48. package/dist/utils/scanning/resolvers.d.mts +11 -0
  49. package/dist/utils/scanning/resolvers.mjs +100 -0
  50. package/dist/utils/scanning/schemas.d.mts +15 -0
  51. package/dist/utils/scanning/schemas.mjs +29 -0
  52. package/dist/utils/schema-builder.d.mts +48 -0
  53. package/dist/utils/schema-builder.mjs +51 -0
  54. package/dist/utils/server-codegen.mjs +3 -29
  55. package/dist/utils/type-generation.d.mts +2 -2
  56. package/dist/utils/type-generation.mjs +2 -2
  57. package/dist/utils/validation.d.mts +11 -0
  58. package/dist/utils/validation.mjs +34 -0
  59. package/dist/virtual/generators/config.d.mts +22 -0
  60. package/dist/virtual/generators/config.mjs +36 -0
  61. package/dist/virtual/generators/debug.d.mts +14 -0
  62. package/dist/virtual/generators/debug.mjs +53 -0
  63. package/dist/virtual/generators/directives.d.mts +14 -0
  64. package/dist/virtual/generators/directives.mjs +52 -0
  65. package/dist/virtual/generators/index.d.mts +6 -0
  66. package/dist/virtual/generators/index.mjs +7 -0
  67. package/dist/virtual/generators/resolvers.d.mts +14 -0
  68. package/dist/virtual/generators/resolvers.mjs +55 -0
  69. package/dist/virtual/generators/schemas.d.mts +14 -0
  70. package/dist/virtual/generators/schemas.mjs +43 -0
  71. package/package.json +22 -18
@@ -0,0 +1,51 @@
1
+ import { loadFederationSupport, warnFederationUnavailable } from "./federation.mjs";
2
+ import { consola as consola$1 } from "consola";
3
+ import { parse } from "graphql";
4
+ import { mergeResolvers, mergeTypeDefs } from "@graphql-tools/merge";
5
+ import { makeExecutableSchema } from "@graphql-tools/schema";
6
+
7
+ //#region src/utils/schema-builder.ts
8
+ /**
9
+ * Create a merged GraphQL schema from schemas, resolvers, and directives
10
+ * Supports Apollo Federation when enabled
11
+ */
12
+ async function createMergedSchema(options) {
13
+ const { schemas, resolvers, directives, moduleConfig } = options;
14
+ try {
15
+ const typeDefs = mergeTypeDefs([schemas.map((schema$1) => schema$1.def).join("\n\n")], {
16
+ throwOnConflict: true,
17
+ commentDescriptions: true,
18
+ sort: true
19
+ });
20
+ const mergedResolvers = mergeResolvers(resolvers.map((r) => r.resolver));
21
+ const federationEnabled = moduleConfig.federation?.enabled;
22
+ let schema;
23
+ if (federationEnabled) {
24
+ const buildSubgraph = await loadFederationSupport();
25
+ if (buildSubgraph) schema = buildSubgraph({
26
+ typeDefs: typeof typeDefs === "string" ? parse(typeDefs) : typeDefs,
27
+ resolvers: mergedResolvers
28
+ });
29
+ else {
30
+ warnFederationUnavailable();
31
+ schema = makeExecutableSchema({
32
+ typeDefs,
33
+ resolvers: mergedResolvers
34
+ });
35
+ }
36
+ } else schema = makeExecutableSchema({
37
+ typeDefs,
38
+ resolvers: mergedResolvers
39
+ });
40
+ if (directives && directives.length > 0) {
41
+ for (const { directive } of directives) if (directive.transformer) schema = directive.transformer(schema);
42
+ }
43
+ return schema;
44
+ } catch (error) {
45
+ consola$1.error("Schema merge error:", error);
46
+ throw error;
47
+ }
48
+ }
49
+
50
+ //#endregion
51
+ export { createMergedSchema };
@@ -1,43 +1,17 @@
1
+ import { DEFAULT_GRAPHQL_SCALARS } from "../constants/scalars.mjs";
2
+ import { pluginContent } from "./codegen-plugin.mjs";
1
3
  import { defu as defu$1 } from "defu";
2
4
  import consola from "consola";
3
5
  import { parse } from "graphql";
4
6
  import { codegen } from "@graphql-codegen/core";
5
7
  import * as typescriptPlugin from "@graphql-codegen/typescript";
6
8
  import { printSchemaWithDirectives } from "@graphql-tools/utils";
7
- import { CurrencyResolver, DateTimeISOResolver, DateTimeResolver, JSONObjectResolver, JSONResolver, NonEmptyStringResolver, UUIDResolver } from "graphql-scalars";
8
9
  import * as typescriptResolversPlugin from "@graphql-codegen/typescript-resolvers";
9
10
 
10
11
  //#region src/utils/server-codegen.ts
11
- /**
12
- * Plugin to add prepend comments to generated files
13
- */
14
- function pluginContent(_schema, _documents, _config, _info) {
15
- return {
16
- prepend: [
17
- "// THIS FILE IS GENERATED, DO NOT EDIT!",
18
- "/* eslint-disable eslint-comments/no-unlimited-disable */",
19
- "/* tslint:disable */",
20
- "/* eslint-disable */",
21
- "/* prettier-ignore */"
22
- ],
23
- content: ""
24
- };
25
- }
26
12
  async function generateTypes(selectFremework, schema, config = {}, outputPath) {
27
13
  const mergedConfig = defu$1({
28
- scalars: {
29
- DateTime: DateTimeResolver.extensions.codegenScalarType,
30
- DateTimeISO: DateTimeISOResolver.extensions.codegenScalarType,
31
- UUID: UUIDResolver.extensions.codegenScalarType,
32
- JSON: JSONResolver.extensions.codegenScalarType,
33
- JSONObject: JSONObjectResolver.extensions.codegenScalarType,
34
- NonEmptyString: NonEmptyStringResolver.extensions.codegenScalarType,
35
- Currency: CurrencyResolver.extensions.codegenScalarType,
36
- File: {
37
- input: "File",
38
- output: "File"
39
- }
40
- },
14
+ scalars: DEFAULT_GRAPHQL_SCALARS,
41
15
  defaultScalarType: "unknown",
42
16
  defaultMapper: `ResolverReturnType<{T}>`,
43
17
  contextType: "nitro/h3#H3Event",
@@ -2,5 +2,5 @@ import { generateMainClientTypes } from "../codegen/client-types.mjs";
2
2
  import { generateExternalServicesTypes } from "../codegen/external-types.mjs";
3
3
  import { generateServerTypes } from "../codegen/server-types.mjs";
4
4
  import { validateNoDuplicateTypes } from "../codegen/validation.mjs";
5
- import { clientTypeGeneration, serverTypeGeneration } from "../codegen/index.mjs";
6
- export { clientTypeGeneration, generateExternalServicesTypes, generateMainClientTypes, generateServerTypes, serverTypeGeneration, validateNoDuplicateTypes };
5
+ import { generateClientTypes } from "../codegen/index.mjs";
6
+ export { generateClientTypes, generateExternalServicesTypes, generateMainClientTypes, generateServerTypes, validateNoDuplicateTypes };
@@ -2,6 +2,6 @@ import { generateMainClientTypes } from "../codegen/client-types.mjs";
2
2
  import { generateExternalServicesTypes } from "../codegen/external-types.mjs";
3
3
  import { validateNoDuplicateTypes } from "../codegen/validation.mjs";
4
4
  import { generateServerTypes } from "../codegen/server-types.mjs";
5
- import { clientTypeGeneration, serverTypeGeneration } from "../codegen/index.mjs";
5
+ import { generateClientTypes } from "../codegen/index.mjs";
6
6
 
7
- export { clientTypeGeneration, generateExternalServicesTypes, generateMainClientTypes, generateServerTypes, serverTypeGeneration, validateNoDuplicateTypes };
7
+ export { generateClientTypes, generateExternalServicesTypes, generateMainClientTypes, generateServerTypes, validateNoDuplicateTypes };
@@ -0,0 +1,11 @@
1
+ //#region src/utils/validation.d.ts
2
+ /**
3
+ * Validation utilities
4
+ * Configuration validation helpers
5
+ */
6
+ /**
7
+ * Validate external GraphQL service configuration
8
+ */
9
+ declare function validateExternalServices(services: unknown[]): string[];
10
+ //#endregion
11
+ export { validateExternalServices };
@@ -0,0 +1,34 @@
1
+ //#region src/utils/validation.ts
2
+ /**
3
+ * Validation utilities
4
+ * Configuration validation helpers
5
+ */
6
+ /**
7
+ * Validate external GraphQL service configuration
8
+ */
9
+ function validateExternalServices(services) {
10
+ const errors = [];
11
+ const serviceNames = /* @__PURE__ */ new Set();
12
+ for (const [index, service] of services.entries()) {
13
+ const prefix = `externalServices[${index}]`;
14
+ if (!service || typeof service !== "object") {
15
+ errors.push(`${prefix} must be an object`);
16
+ continue;
17
+ }
18
+ if (!("name" in service) || typeof service.name !== "string") errors.push(`${prefix}.name is required and must be a string`);
19
+ else if (serviceNames.has(service.name)) errors.push(`${prefix}.name "${service.name}" must be unique`);
20
+ else serviceNames.add(service.name);
21
+ if (!("schema" in service) || !service.schema) errors.push(`${prefix}.schema is required`);
22
+ if (!("endpoint" in service) || typeof service.endpoint !== "string") errors.push(`${prefix}.endpoint is required and must be a string`);
23
+ else try {
24
+ new URL(service.endpoint);
25
+ } catch {
26
+ errors.push(`${prefix}.endpoint "${service.endpoint}" must be a valid URL`);
27
+ }
28
+ if ("name" in service && service.name && typeof service.name === "string" && !/^[a-z]\w*$/i.test(service.name)) errors.push(`${prefix}.name "${service.name}" must be a valid identifier (letters, numbers, underscore, starting with letter)`);
29
+ }
30
+ return errors;
31
+ }
32
+
33
+ //#endregion
34
+ export { validateExternalServices };
@@ -0,0 +1,22 @@
1
+ import { Nitro } from "nitro/types";
2
+
3
+ //#region src/virtual/generators/config.d.ts
4
+
5
+ /**
6
+ * Generate virtual module code for GraphQL config (from server/graphql/config.ts)
7
+ */
8
+ declare function generateGraphQLConfigModule(nitro: Nitro): string;
9
+ /**
10
+ * Register the GraphQL config virtual module with Nitro
11
+ */
12
+ declare function virtualGraphQLConfig(nitro: Nitro): void;
13
+ /**
14
+ * Generate virtual module code for module config (serialized graphql options)
15
+ */
16
+ declare function generateModuleConfigModule(nitro: Nitro): string;
17
+ /**
18
+ * Register the module config virtual module with Nitro
19
+ */
20
+ declare function virtualModuleConfig(nitro: Nitro): void;
21
+ //#endregion
22
+ export { generateGraphQLConfigModule, generateModuleConfigModule, virtualGraphQLConfig, virtualModuleConfig };
@@ -0,0 +1,36 @@
1
+ import { resolve } from "pathe";
2
+
3
+ //#region src/virtual/generators/config.ts
4
+ /**
5
+ * Generate virtual module code for GraphQL config (from server/graphql/config.ts)
6
+ */
7
+ function generateGraphQLConfigModule(nitro) {
8
+ return `import config from '${resolve(nitro.graphql.serverDir, "config.ts")}'
9
+ const importedConfig = config
10
+ export { importedConfig }
11
+ `;
12
+ }
13
+ /**
14
+ * Register the GraphQL config virtual module with Nitro
15
+ */
16
+ function virtualGraphQLConfig(nitro) {
17
+ nitro.options.virtual ??= {};
18
+ nitro.options.virtual["#nitro-graphql/graphql-config"] = () => generateGraphQLConfigModule(nitro);
19
+ }
20
+ /**
21
+ * Generate virtual module code for module config (serialized graphql options)
22
+ */
23
+ function generateModuleConfigModule(nitro) {
24
+ const moduleConfig = nitro.options.graphql || {};
25
+ return `export const moduleConfig = ${JSON.stringify(moduleConfig, null, 2)};`;
26
+ }
27
+ /**
28
+ * Register the module config virtual module with Nitro
29
+ */
30
+ function virtualModuleConfig(nitro) {
31
+ nitro.options.virtual ??= {};
32
+ nitro.options.virtual["#nitro-graphql/module-config"] = () => generateModuleConfigModule(nitro);
33
+ }
34
+
35
+ //#endregion
36
+ export { generateGraphQLConfigModule, generateModuleConfigModule, virtualGraphQLConfig, virtualModuleConfig };
@@ -0,0 +1,14 @@
1
+ import { Nitro } from "nitro/types";
2
+
3
+ //#region src/virtual/generators/debug.d.ts
4
+
5
+ /**
6
+ * Generate virtual module code for debug info
7
+ */
8
+ declare function generateDebugInfoModule(nitro: Nitro): string;
9
+ /**
10
+ * Register the debug info virtual module with Nitro
11
+ */
12
+ declare function virtualDebugInfo(nitro: Nitro): void;
13
+ //#endregion
14
+ export { generateDebugInfoModule, virtualDebugInfo };
@@ -0,0 +1,53 @@
1
+ //#region src/virtual/generators/debug.ts
2
+ /**
3
+ * Safely call a virtual module generator and capture its output
4
+ */
5
+ function safeGenerateModuleCode(nitro, moduleName) {
6
+ try {
7
+ const generator = nitro.options.virtual?.[moduleName];
8
+ if (generator && typeof generator === "function") return generator();
9
+ return "// Module not found";
10
+ } catch (error) {
11
+ return `// Error generating: ${error instanceof Error ? error.message : String(error)}`;
12
+ }
13
+ }
14
+ /**
15
+ * Generate virtual module code for debug info
16
+ */
17
+ function generateDebugInfoModule(nitro) {
18
+ const virtualModuleCodes = {
19
+ "server-schemas": safeGenerateModuleCode(nitro, "#nitro-graphql/server-schemas"),
20
+ "server-resolvers": safeGenerateModuleCode(nitro, "#nitro-graphql/server-resolvers"),
21
+ "server-directives": safeGenerateModuleCode(nitro, "#nitro-graphql/server-directives"),
22
+ "module-config": safeGenerateModuleCode(nitro, "#nitro-graphql/module-config"),
23
+ "graphql-config": safeGenerateModuleCode(nitro, "#nitro-graphql/graphql-config")
24
+ };
25
+ const debugInfo = {
26
+ isDev: nitro.options.dev,
27
+ framework: nitro.options.framework.name,
28
+ graphqlFramework: nitro.options.graphql?.framework,
29
+ federation: nitro.options.graphql?.federation,
30
+ scanned: {
31
+ schemas: nitro.scanSchemas?.length || 0,
32
+ schemaFiles: nitro.scanSchemas || [],
33
+ resolvers: nitro.scanResolvers?.length || 0,
34
+ resolverFiles: nitro.scanResolvers || [],
35
+ directives: nitro.scanDirectives?.length || 0,
36
+ directiveFiles: nitro.scanDirectives || [],
37
+ documents: nitro.scanDocuments?.length || 0,
38
+ documentFiles: nitro.scanDocuments || []
39
+ },
40
+ virtualModules: virtualModuleCodes
41
+ };
42
+ return `export const debugInfo = ${JSON.stringify(debugInfo, null, 2)};`;
43
+ }
44
+ /**
45
+ * Register the debug info virtual module with Nitro
46
+ */
47
+ function virtualDebugInfo(nitro) {
48
+ nitro.options.virtual ??= {};
49
+ nitro.options.virtual["#nitro-graphql/debug-info"] = () => generateDebugInfoModule(nitro);
50
+ }
51
+
52
+ //#endregion
53
+ export { generateDebugInfoModule, virtualDebugInfo };
@@ -0,0 +1,14 @@
1
+ import { Nitro } from "nitro/types";
2
+
3
+ //#region src/virtual/generators/directives.d.ts
4
+
5
+ /**
6
+ * Generate virtual module code for server directives
7
+ */
8
+ declare function generateDirectivesModule(nitro: Nitro): string;
9
+ /**
10
+ * Register the directives virtual module with Nitro
11
+ */
12
+ declare function virtualDirectives(nitro: Nitro): void;
13
+ //#endregion
14
+ export { generateDirectivesModule, virtualDirectives };
@@ -0,0 +1,52 @@
1
+ import { genImport } from "knitwork";
2
+
3
+ //#region src/virtual/generators/directives.ts
4
+ /**
5
+ * Generate virtual module code for server directives
6
+ */
7
+ function generateDirectivesModule(nitro) {
8
+ try {
9
+ const imports = nitro.scanDirectives || [];
10
+ if (imports.length === 0) return "export const directives = []";
11
+ const importsContent = [];
12
+ const invalidImports = [];
13
+ for (const { specifier, imports: importList, options } of imports) try {
14
+ if (!importList || importList.length === 0) {
15
+ invalidImports.push(`${specifier}: No exports found`);
16
+ continue;
17
+ }
18
+ const importCode = genImport(specifier, importList, options);
19
+ importsContent.push(importCode);
20
+ } catch (error) {
21
+ const message = error instanceof Error ? error.message : String(error);
22
+ invalidImports.push(`${specifier}: ${message}`);
23
+ if (nitro.options.dev) nitro.logger.error(`[nitro-graphql] Failed to generate import for directive ${specifier}:`, error);
24
+ }
25
+ if (invalidImports.length > 0 && nitro.options.dev) {
26
+ nitro.logger.warn("[nitro-graphql] Some directive imports could not be generated:");
27
+ for (const msg of invalidImports) nitro.logger.warn(` - ${msg}`);
28
+ }
29
+ const data = imports.map(({ imports: importList }) => importList.map((i) => `{ directive: ${i.as} }`).join(",\n")).filter(Boolean).join(",\n");
30
+ return [
31
+ ...importsContent,
32
+ "",
33
+ "export const directives = [",
34
+ data,
35
+ "]",
36
+ ""
37
+ ].join("\n");
38
+ } catch (error) {
39
+ nitro.logger.error("[nitro-graphql] Failed to generate virtual directive module:", error);
40
+ return "export const directives = []";
41
+ }
42
+ }
43
+ /**
44
+ * Register the directives virtual module with Nitro
45
+ */
46
+ function virtualDirectives(nitro) {
47
+ nitro.options.virtual ??= {};
48
+ nitro.options.virtual["#nitro-graphql/server-directives"] = () => generateDirectivesModule(nitro);
49
+ }
50
+
51
+ //#endregion
52
+ export { generateDirectivesModule, virtualDirectives };
@@ -0,0 +1,6 @@
1
+ import { generateGraphQLConfigModule, generateModuleConfigModule, virtualGraphQLConfig, virtualModuleConfig } from "./config.mjs";
2
+ import { generateDebugInfoModule, virtualDebugInfo } from "./debug.mjs";
3
+ import { generateDirectivesModule, virtualDirectives } from "./directives.mjs";
4
+ import { generateResolversModule, virtualResolvers } from "./resolvers.mjs";
5
+ import { generateSchemasModule, virtualSchemas } from "./schemas.mjs";
6
+ export { generateDebugInfoModule, generateDirectivesModule, generateGraphQLConfigModule, generateModuleConfigModule, generateResolversModule, generateSchemasModule, virtualDebugInfo, virtualDirectives, virtualGraphQLConfig, virtualModuleConfig, virtualResolvers, virtualSchemas };
@@ -0,0 +1,7 @@
1
+ import { generateGraphQLConfigModule, generateModuleConfigModule, virtualGraphQLConfig, virtualModuleConfig } from "./config.mjs";
2
+ import { generateDebugInfoModule, virtualDebugInfo } from "./debug.mjs";
3
+ import { generateDirectivesModule, virtualDirectives } from "./directives.mjs";
4
+ import { generateResolversModule, virtualResolvers } from "./resolvers.mjs";
5
+ import { generateSchemasModule, virtualSchemas } from "./schemas.mjs";
6
+
7
+ export { generateDebugInfoModule, generateDirectivesModule, generateGraphQLConfigModule, generateModuleConfigModule, generateResolversModule, generateSchemasModule, virtualDebugInfo, virtualDirectives, virtualGraphQLConfig, virtualModuleConfig, virtualResolvers, virtualSchemas };
@@ -0,0 +1,14 @@
1
+ import { Nitro } from "nitro/types";
2
+
3
+ //#region src/virtual/generators/resolvers.d.ts
4
+
5
+ /**
6
+ * Generate virtual module code for server resolvers
7
+ */
8
+ declare function generateResolversModule(nitro: Nitro): string;
9
+ /**
10
+ * Register the resolvers virtual module with Nitro
11
+ */
12
+ declare function virtualResolvers(nitro: Nitro): void;
13
+ //#endregion
14
+ export { generateResolversModule, virtualResolvers };
@@ -0,0 +1,55 @@
1
+ import { genImport } from "knitwork";
2
+
3
+ //#region src/virtual/generators/resolvers.ts
4
+ /**
5
+ * Generate virtual module code for server resolvers
6
+ */
7
+ function generateResolversModule(nitro) {
8
+ try {
9
+ const imports = [...nitro.scanResolvers];
10
+ if (imports.length === 0) {
11
+ if (nitro.options.dev) nitro.logger.warn("[nitro-graphql] No resolvers found. Virtual module will export empty array.");
12
+ return "export const resolvers = []";
13
+ }
14
+ const importsContent = [];
15
+ const invalidImports = [];
16
+ for (const { specifier, imports: importList, options } of imports) try {
17
+ if (!importList || importList.length === 0) {
18
+ invalidImports.push(`${specifier}: No exports found`);
19
+ continue;
20
+ }
21
+ const importCode = genImport(specifier, importList, options);
22
+ importsContent.push(importCode);
23
+ } catch (error) {
24
+ const message = error instanceof Error ? error.message : String(error);
25
+ invalidImports.push(`${specifier}: ${message}`);
26
+ if (nitro.options.dev) nitro.logger.error(`[nitro-graphql] Failed to generate import for ${specifier}:`, error);
27
+ }
28
+ if (invalidImports.length > 0 && nitro.options.dev) {
29
+ nitro.logger.warn("[nitro-graphql] Some resolver imports could not be generated:");
30
+ for (const msg of invalidImports) nitro.logger.warn(` - ${msg}`);
31
+ }
32
+ const data = imports.map(({ imports: importList }) => importList.map((i) => `{ resolver: ${i.as} }`).join(",\n")).filter(Boolean).join(",\n");
33
+ return [
34
+ ...importsContent,
35
+ "",
36
+ "export const resolvers = [",
37
+ data,
38
+ "]",
39
+ ""
40
+ ].join("\n");
41
+ } catch (error) {
42
+ nitro.logger.error("[nitro-graphql] Failed to generate virtual resolver module:", error);
43
+ return "export const resolvers = []";
44
+ }
45
+ }
46
+ /**
47
+ * Register the resolvers virtual module with Nitro
48
+ */
49
+ function virtualResolvers(nitro) {
50
+ nitro.options.virtual ??= {};
51
+ nitro.options.virtual["#nitro-graphql/server-resolvers"] = () => generateResolversModule(nitro);
52
+ }
53
+
54
+ //#endregion
55
+ export { generateResolversModule, virtualResolvers };
@@ -0,0 +1,14 @@
1
+ import { Nitro } from "nitro/types";
2
+
3
+ //#region src/virtual/generators/schemas.d.ts
4
+
5
+ /**
6
+ * Generate virtual module code for server schemas
7
+ */
8
+ declare function generateSchemasModule(nitro: Nitro): string;
9
+ /**
10
+ * Register the schemas virtual module with Nitro
11
+ */
12
+ declare function virtualSchemas(nitro: Nitro): void;
13
+ //#endregion
14
+ export { generateSchemasModule, virtualSchemas };
@@ -0,0 +1,43 @@
1
+ import { getImportId } from "../../utils/imports.mjs";
2
+
3
+ //#region src/virtual/generators/schemas.ts
4
+ /**
5
+ * Get all schemas from scanned files and config
6
+ */
7
+ function getSchemas(nitro) {
8
+ return [...nitro.scanSchemas, ...nitro.options.graphql?.typedefs ?? []];
9
+ }
10
+ /**
11
+ * Generate virtual module code for server schemas
12
+ */
13
+ function generateSchemasModule(nitro) {
14
+ try {
15
+ const imports = getSchemas(nitro);
16
+ if (imports.length === 0) {
17
+ if (nitro.options.dev) nitro.logger.warn("[nitro-graphql] No schemas found. Virtual module will export empty array.");
18
+ return "export const schemas = []";
19
+ }
20
+ const importStatements = imports.map((handler) => `import ${getImportId(handler)} from '${handler}';`);
21
+ const schemaArray = imports.map((h) => `{ def: ${getImportId(h)} }`);
22
+ return `
23
+ ${importStatements.join("\n")}
24
+
25
+ export const schemas = [
26
+ ${schemaArray.join(",\n")}
27
+ ];
28
+ `;
29
+ } catch (error) {
30
+ nitro.logger.error("[nitro-graphql] Failed to generate virtual schema module:", error);
31
+ return "export const schemas = []";
32
+ }
33
+ }
34
+ /**
35
+ * Register the schemas virtual module with Nitro
36
+ */
37
+ function virtualSchemas(nitro) {
38
+ nitro.options.virtual ??= {};
39
+ nitro.options.virtual["#nitro-graphql/server-schemas"] = () => generateSchemasModule(nitro);
40
+ }
41
+
42
+ //#endregion
43
+ export { generateSchemasModule, virtualSchemas };
package/package.json CHANGED
@@ -1,9 +1,13 @@
1
1
  {
2
2
  "name": "nitro-graphql",
3
3
  "type": "module",
4
- "version": "2.0.0-beta.32",
4
+ "version": "2.0.0-beta.34",
5
5
  "description": "GraphQL integration for Nitro",
6
6
  "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/productdevbook/nitro-graphql"
10
+ },
7
11
  "sideEffects": false,
8
12
  "imports": {
9
13
  "#graphql/server": {
@@ -84,47 +88,47 @@
84
88
  "@apollo/subgraph": "^2.12.1",
85
89
  "@graphql-codegen/core": "^5.0.0",
86
90
  "@graphql-codegen/import-types-preset": "^3.0.1",
87
- "@graphql-codegen/typescript": "^5.0.4",
91
+ "@graphql-codegen/typescript": "^5.0.6",
88
92
  "@graphql-codegen/typescript-generic-sdk": "^4.0.2",
89
- "@graphql-codegen/typescript-operations": "^5.0.4",
90
- "@graphql-codegen/typescript-resolvers": "^5.1.2",
91
- "@graphql-tools/graphql-file-loader": "^8.1.6",
92
- "@graphql-tools/load": "^8.1.6",
93
+ "@graphql-codegen/typescript-operations": "^5.0.6",
94
+ "@graphql-codegen/typescript-resolvers": "^5.1.4",
95
+ "@graphql-tools/graphql-file-loader": "^8.1.8",
96
+ "@graphql-tools/load": "^8.1.7",
93
97
  "@graphql-tools/load-files": "^7.0.1",
94
- "@graphql-tools/merge": "^9.1.5",
95
- "@graphql-tools/schema": "^10.0.29",
96
- "@graphql-tools/url-loader": "^9.0.4",
97
- "@graphql-tools/utils": "^10.10.3",
98
- "chokidar": "^4.0.3",
98
+ "@graphql-tools/merge": "^9.1.6",
99
+ "@graphql-tools/schema": "^10.0.30",
100
+ "@graphql-tools/url-loader": "^9.0.5",
101
+ "@graphql-tools/utils": "^10.11.0",
102
+ "chokidar": "^5.0.0",
99
103
  "consola": "^3.4.2",
100
104
  "defu": "^6.1.4",
101
105
  "graphql-config": "^5.1.5",
102
106
  "graphql-scalars": "^1.25.0",
103
107
  "knitwork": "^1.3.0",
104
108
  "ohash": "^2.0.11",
105
- "oxc-parser": "^0.98.0",
109
+ "oxc-parser": "^0.101.0",
106
110
  "pathe": "^2.0.3",
107
111
  "tinyglobby": "^0.2.15"
108
112
  },
109
113
  "devDependencies": {
110
- "@antfu/eslint-config": "^6.2.0",
114
+ "@antfu/eslint-config": "^6.3.0",
111
115
  "@nuxt/kit": "^4.2.1",
112
116
  "@nuxt/schema": "^4.2.1",
113
117
  "@types/node": "^24.10.1",
114
118
  "@vitejs/devtools": "^0.0.0-alpha.16",
115
- "@vitest/ui": "^3.0.0",
116
- "bumpp": "^10.3.1",
119
+ "@vitest/ui": "^4.0.15",
120
+ "bumpp": "^10.3.2",
117
121
  "changelogen": "^0.6.2",
118
122
  "crossws": "^0.4.1",
119
123
  "eslint": "^9.39.1",
120
124
  "graphql": "16.12.0",
121
125
  "graphql-yoga": "5.16.2",
122
126
  "nitro": "npm:nitro-nightly@latest",
123
- "tsdown": "^0.16.6",
127
+ "tsdown": "^0.16.8",
124
128
  "typescript": "^5.9.3",
125
129
  "vite": "npm:rolldown-vite@latest",
126
130
  "vitepress-plugin-llms": "^1.9.3",
127
- "vitest": "^3.0.0"
131
+ "vitest": "^4.0.15"
128
132
  },
129
133
  "resolutions": {
130
134
  "nitro-graphql": "link:."
@@ -133,7 +137,7 @@
133
137
  "build": "tsdown",
134
138
  "dev": "tsdown --watch",
135
139
  "bumpp": "bumpp package.json",
136
- "release": "pnpm build && pnpm bumpp && pnpm publish --no-git-checks --access public",
140
+ "release": "pnpm build && pnpm bumpp",
137
141
  "playground:nitro": "cd playgrounds/nitro && pnpm install && pnpm dev",
138
142
  "playground:nuxt": "cd playgrounds/nuxt && pnpm install && pnpm dev",
139
143
  "playground:federation": "cd playgrounds/federation && pnpm install && pnpm dev",