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

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 (72) hide show
  1. package/README.md +477 -20
  2. package/dist/define.d.mts +296 -0
  3. package/dist/define.mjs +323 -0
  4. package/dist/ecosystem/nuxt.mjs +109 -0
  5. package/dist/index.d.mts +43 -0
  6. package/dist/index.mjs +63 -0
  7. package/dist/rollup.d.mts +12 -0
  8. package/dist/rollup.mjs +282 -0
  9. package/dist/routes/apollo-server.d.mts +6 -0
  10. package/dist/routes/{apollo-server.js → apollo-server.mjs} +7 -7
  11. package/dist/routes/debug.d.mts +61 -0
  12. package/dist/routes/debug.mjs +445 -0
  13. package/dist/routes/graphql-yoga.d.mts +6 -0
  14. package/dist/routes/{graphql-yoga.js → graphql-yoga.mjs} +11 -7
  15. package/dist/routes/health.d.mts +10 -0
  16. package/dist/routes/{health.js → health.mjs} +3 -2
  17. package/dist/setup.d.mts +11 -0
  18. package/dist/setup.mjs +376 -0
  19. package/dist/{utils/define.d.ts → types/define.d.mts} +4 -27
  20. package/dist/types/define.mjs +1 -0
  21. package/dist/types/index.d.mts +246 -0
  22. package/dist/types/index.mjs +1 -0
  23. package/dist/types/standard-schema.mjs +1 -0
  24. package/dist/utils/{apollo.d.ts → apollo.d.mts} +2 -2
  25. package/dist/utils/apollo.mjs +59 -0
  26. package/dist/utils/{client-codegen.d.ts → client-codegen.d.mts} +6 -3
  27. package/dist/utils/{client-codegen.js → client-codegen.mjs} +6 -6
  28. package/dist/utils/errors.d.mts +73 -0
  29. package/dist/utils/errors.mjs +89 -0
  30. package/dist/utils/file-generator.d.mts +37 -0
  31. package/dist/utils/file-generator.mjs +72 -0
  32. package/dist/utils/{index.d.ts → index.d.mts} +4 -3
  33. package/dist/utils/{index.js → index.mjs} +80 -40
  34. package/dist/utils/path-resolver.d.mts +70 -0
  35. package/dist/utils/path-resolver.mjs +127 -0
  36. package/dist/utils/{server-codegen.d.ts → server-codegen.d.mts} +1 -1
  37. package/dist/utils/{server-codegen.js → server-codegen.mjs} +3 -3
  38. package/dist/utils/type-generation.d.mts +12 -0
  39. package/dist/utils/type-generation.mjs +420 -0
  40. package/dist/virtual/debug-info.d.mts +9 -0
  41. package/dist/virtual/debug-info.mjs +26 -0
  42. package/dist/virtual/graphql-config.d.mts +9 -0
  43. package/dist/virtual/graphql-config.mjs +10 -0
  44. package/dist/virtual/module-config.d.mts +9 -0
  45. package/dist/virtual/module-config.mjs +10 -0
  46. package/dist/virtual/server-directives.d.mts +11 -0
  47. package/dist/virtual/server-directives.mjs +10 -0
  48. package/dist/virtual/server-resolvers.d.mts +11 -0
  49. package/dist/virtual/server-resolvers.mjs +10 -0
  50. package/dist/virtual/server-schemas.d.mts +11 -0
  51. package/dist/virtual/server-schemas.mjs +10 -0
  52. package/package.json +79 -70
  53. package/dist/ecosystem/nuxt.js +0 -67
  54. package/dist/index.d.ts +0 -8
  55. package/dist/index.js +0 -264
  56. package/dist/rollup.js +0 -114
  57. package/dist/routes/apollo-server.d.ts +0 -6
  58. package/dist/routes/graphql-yoga.d.ts +0 -6
  59. package/dist/routes/health.d.ts +0 -6
  60. package/dist/types/index.d.ts +0 -128
  61. package/dist/utils/apollo.js +0 -61
  62. package/dist/utils/define.js +0 -57
  63. package/dist/utils/type-generation.d.ts +0 -7
  64. package/dist/utils/type-generation.js +0 -287
  65. /package/dist/ecosystem/{nuxt.d.ts → nuxt.d.mts} +0 -0
  66. /package/dist/graphql/{index.d.ts → index.d.mts} +0 -0
  67. /package/dist/graphql/{index.js → index.mjs} +0 -0
  68. /package/dist/graphql/{server.d.ts → server.d.mts} +0 -0
  69. /package/dist/graphql/{server.js → server.mjs} +0 -0
  70. /package/dist/types/{standard-schema.d.ts → standard-schema.d.mts} +0 -0
  71. /package/dist/utils/{directive-parser.d.ts → directive-parser.d.mts} +0 -0
  72. /package/dist/utils/{directive-parser.js → directive-parser.mjs} +0 -0
@@ -0,0 +1,109 @@
1
+ import { getDefaultPaths, getTypesConfig, resolveFilePath } from "../utils/path-resolver.mjs";
2
+ import { existsSync, mkdirSync, writeFileSync } from "node:fs";
3
+ import { dirname, join, relative, resolve } from "pathe";
4
+ import { defineNuxtModule, getLayerDirectories } from "@nuxt/kit";
5
+
6
+ //#region src/ecosystem/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$1 = { 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$1 = getDefaultPaths(mockNitro$1);
22
+ const typesConfig$1 = getTypesConfig(mockNitro$1);
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$1 = resolveFilePath(typesConfig$1.client, typesConfig$1.enabled, true, "{typesDir}/nitro-graphql-client.d.ts", placeholders$1);
29
+ if (clientTypesPath$1) {
30
+ const relativePath = relativeWithDot(tsconfigDir, clientTypesPath$1);
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$1 = nuxt.options.nitro?.graphql?.externalServices || [];
40
+ for (const service of externalServices$1) {
41
+ const servicePlaceholders = {
42
+ ...placeholders$1,
43
+ serviceName: service.name
44
+ };
45
+ const externalTypesPath = resolveFilePath(service.paths?.types ?? typesConfig$1.external, typesConfig$1.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
+ options.tsConfig.compilerOptions.paths[`#graphql/client/${service.name}`] = [relativePath];
50
+ 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 layerDirs = await getLayerDirectories(nuxt);
81
+ const layerDirectories = layerDirs.map((layer) => layer.root.replace(/\/$/, "")).filter((root) => root !== nuxt.options.rootDir);
82
+ const layerServerDirs = layerDirs.filter((layer) => layer.root !== `${nuxt.options.rootDir}/`).map((layer) => layer.server?.replace(/\/$/, "")).filter(Boolean);
83
+ const layerAppDirs = layerDirs.filter((layer) => layer.root !== `${nuxt.options.rootDir}/`).map((layer) => layer.app?.replace(/\/$/, "")).filter(Boolean);
84
+ if (!nitroConfig.graphql) nitroConfig.graphql = {};
85
+ nitroConfig.graphql.layerDirectories = layerDirectories;
86
+ nitroConfig.graphql.layerServerDirs = layerServerDirs;
87
+ nitroConfig.graphql.layerAppDirs = layerAppDirs;
88
+ if (!existsSync(resolve(nuxt.options.rootDir, "app/graphql"))) {
89
+ const defaultDir = join(clientDir, "default");
90
+ if (!existsSync(defaultDir)) mkdirSync(defaultDir, { recursive: true });
91
+ const sampleQueryFile = join(defaultDir, "queries.graphql");
92
+ if (!existsSync(sampleQueryFile)) writeFileSync(sampleQueryFile, `# Example GraphQL queries
93
+ # Add your GraphQL queries here
94
+
95
+ # query GetUser($id: ID!) {
96
+ # user(id: $id) {
97
+ # id
98
+ # name
99
+ # email
100
+ # }
101
+ # }
102
+ `, "utf-8");
103
+ }
104
+ });
105
+ }
106
+ });
107
+
108
+ //#endregion
109
+ export { nuxt_default as default };
@@ -0,0 +1,43 @@
1
+ import { NitroGraphQLOptions } from "./types/index.mjs";
2
+ import { NitroModule } from "nitro/types";
3
+ import { Plugin } from "vite";
4
+
5
+ //#region src/index.d.ts
6
+
7
+ /**
8
+ * Vite plugin to load GraphQL files as strings AND auto-register Nitro module
9
+ * This prevents Vite from trying to parse .graphql/.gql files as JavaScript
10
+ * and automatically sets up the nitro-graphql module via the nitro: hook
11
+ *
12
+ * @example - Vite usage
13
+ * ```ts
14
+ * import { defineConfig } from 'vite'
15
+ * import { nitro } from 'nitro/vite'
16
+ * import graphql from 'nitro-graphql'
17
+ *
18
+ * export default defineConfig({
19
+ * plugins: [
20
+ * graphql({ framework: 'graphql-yoga' }), // Auto-registers Nitro module
21
+ * nitro()
22
+ * ]
23
+ * })
24
+ * ```
25
+ *
26
+ *
27
+ * @example - Nitro direct usage
28
+ * ```ts
29
+ *
30
+ * import graphql from 'nitro-graphql'
31
+ *
32
+ * export default defineConfig({
33
+ * modules: [
34
+ * graphql({ framework: 'graphql-yoga' }) // Auto-registers Nitro module
35
+ * ]
36
+ * })
37
+ * ```
38
+ */
39
+ declare function graphqlModule(options?: NitroGraphQLOptions): Plugin & {
40
+ nitro?: NitroModule;
41
+ };
42
+ //#endregion
43
+ export { graphqlModule as default };
package/dist/index.mjs ADDED
@@ -0,0 +1,63 @@
1
+ import { setupNitroGraphQL } from "./setup.mjs";
2
+ import { readFile } from "node:fs/promises";
3
+ import defu from "defu";
4
+
5
+ //#region src/index.ts
6
+ /**
7
+ * Vite plugin to load GraphQL files as strings AND auto-register Nitro module
8
+ * This prevents Vite from trying to parse .graphql/.gql files as JavaScript
9
+ * and automatically sets up the nitro-graphql module via the nitro: hook
10
+ *
11
+ * @example - Vite usage
12
+ * ```ts
13
+ * import { defineConfig } from 'vite'
14
+ * import { nitro } from 'nitro/vite'
15
+ * import graphql from 'nitro-graphql'
16
+ *
17
+ * export default defineConfig({
18
+ * plugins: [
19
+ * graphql({ framework: 'graphql-yoga' }), // Auto-registers Nitro module
20
+ * nitro()
21
+ * ]
22
+ * })
23
+ * ```
24
+ *
25
+ *
26
+ * @example - Nitro direct usage
27
+ * ```ts
28
+ *
29
+ * import graphql from 'nitro-graphql'
30
+ *
31
+ * export default defineConfig({
32
+ * modules: [
33
+ * graphql({ framework: 'graphql-yoga' }) // Auto-registers Nitro module
34
+ * ]
35
+ * })
36
+ * ```
37
+ */
38
+ function graphqlModule(options) {
39
+ return {
40
+ name: "nitro-graphql",
41
+ enforce: "pre",
42
+ async load(id) {
43
+ if (!/\.(?:graphql|gql)$/i.test(id)) return null;
44
+ try {
45
+ const content = await readFile(id, "utf-8");
46
+ return `export default ${JSON.stringify(content)}`;
47
+ } catch (error) {
48
+ if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") return null;
49
+ throw error;
50
+ }
51
+ },
52
+ nitro: { async setup(nitro) {
53
+ if (options) nitro.options.graphql = defu(nitro.options.graphql || {}, options);
54
+ nitro.options.graphql = nitro.options.graphql || {};
55
+ nitro.options.graphql._vitePlugin = true;
56
+ await setupNitroGraphQL(nitro);
57
+ } }
58
+ };
59
+ }
60
+ var src_default = graphqlModule;
61
+
62
+ //#endregion
63
+ export { src_default as default };
@@ -0,0 +1,12 @@
1
+ import { Nitro } from "nitro/types";
2
+
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;
11
+ //#endregion
12
+ export { getGraphQLConfig, rollupConfig, virtualDebugInfo, virtualDirectives, virtualModuleConfig, virtualResolvers, virtualSchemas };
@@ -0,0 +1,282 @@
1
+ import { getImportId, scanGraphql } from "./utils/index.mjs";
2
+ import { clientTypeGeneration, serverTypeGeneration } from "./utils/type-generation.mjs";
3
+ import { readFile } from "node:fs/promises";
4
+ import { fileURLToPath } from "node:url";
5
+ import { resolve } from "pathe";
6
+ import { parse } from "graphql";
7
+ import { genImport } from "knitwork";
8
+
9
+ //#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) => {
18
+ rollupConfig$1.plugins = rollupConfig$1.plugins || [];
19
+ const { include = /\.(?:graphql|gql)$/i, exclude, validate = false } = app.options.graphql?.loader || {};
20
+ if (Array.isArray(rollupConfig$1.plugins)) {
21
+ rollupConfig$1.plugins.push({
22
+ name: "nitro-graphql:virtual",
23
+ resolveId: {
24
+ order: "pre",
25
+ filter: { id: /^#nitro-graphql\// },
26
+ async handler(id, parent, options) {
27
+ if (id.startsWith("#nitro-graphql/")) return `\0virtual:${id}`;
28
+ if (parent?.startsWith("\0virtual:#nitro-graphql")) {
29
+ const runtimeDir = fileURLToPath(new URL("routes", import.meta.url));
30
+ const internalRes = await this.resolve(id, runtimeDir, {
31
+ skipSelf: true,
32
+ ...options
33
+ });
34
+ if (internalRes) return internalRes;
35
+ }
36
+ }
37
+ },
38
+ load: {
39
+ order: "pre",
40
+ filter: { id: /^\0virtual:#nitro-graphql\// },
41
+ async handler(id) {
42
+ if (id.startsWith("\0virtual:#nitro-graphql/")) {
43
+ const moduleName = id.slice(9);
44
+ const generator = app.options.virtual?.[moduleName];
45
+ if (typeof generator === "function") try {
46
+ return {
47
+ code: await generator(),
48
+ moduleType: "js"
49
+ };
50
+ } catch (error) {
51
+ const message = error instanceof Error ? error.message : String(error);
52
+ this.error(`Failed to generate virtual module ${moduleName}: ${message}`);
53
+ }
54
+ else this.error(`No generator function found for virtual module ${moduleName}`);
55
+ }
56
+ }
57
+ }
58
+ });
59
+ rollupConfig$1.plugins.push({
60
+ name: "nitro-graphql",
61
+ resolveId: {
62
+ order: "pre",
63
+ handler(id) {
64
+ if (/\.(?:graphql|gql)$/i.test(id)) return null;
65
+ }
66
+ },
67
+ load: {
68
+ order: "pre",
69
+ async handler(id) {
70
+ if (exclude?.test?.(id)) return null;
71
+ if (!include.test(id)) return null;
72
+ try {
73
+ const content = await readFile(id, "utf-8");
74
+ if (validate) parse(content);
75
+ return `export default ${JSON.stringify(content)}`;
76
+ } catch (error) {
77
+ if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") return null;
78
+ const message = error instanceof Error ? error.message : String(error);
79
+ this.error(`Failed to read GraphQL file ${id}: ${message}`);
80
+ }
81
+ }
82
+ }
83
+ });
84
+ if (app.options.dev) rollupConfig$1.plugins.push({
85
+ name: "nitro-graphql-watcher",
86
+ buildStart: {
87
+ order: "pre",
88
+ async handler() {
89
+ const graphqlFiles = await scanGraphql(nitro);
90
+ for (const file of graphqlFiles) this.addWatchFile(file);
91
+ }
92
+ }
93
+ });
94
+ }
95
+ });
96
+ app.hooks.hook("dev:reload", async () => {
97
+ await serverTypeGeneration(app, { silent: true });
98
+ await clientTypeGeneration(app, { silent: true });
99
+ });
100
+ }
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
+
281
+ //#endregion
282
+ export { getGraphQLConfig, rollupConfig, virtualDebugInfo, virtualDirectives, virtualModuleConfig, virtualResolvers, virtualSchemas };
@@ -0,0 +1,6 @@
1
+ import * as nitro_deps_h31 from "nitro/deps/h3";
2
+
3
+ //#region src/routes/apollo-server.d.ts
4
+ declare const _default: nitro_deps_h31.EventHandlerWithFetch<nitro_deps_h31.EventHandlerRequest, Promise<any>>;
5
+ //#endregion
6
+ export { _default as default };
@@ -1,17 +1,17 @@
1
- import { consola as consola$1 } from "consola";
2
1
  import defu from "defu";
2
+ import { consola as consola$1 } from "consola";
3
3
  import { parse } from "graphql";
4
4
  import { mergeResolvers, mergeTypeDefs } from "@graphql-tools/merge";
5
- import { importedConfig } from "#nitro-internal-virtual/graphql-config";
6
- import { moduleConfig } from "#nitro-internal-virtual/module-config";
7
- import { directives } from "#nitro-internal-virtual/server-directives";
8
- import { resolvers } from "#nitro-internal-virtual/server-resolvers";
9
- import { schemas } from "#nitro-internal-virtual/server-schemas";
5
+ import { importedConfig } from "#nitro-graphql/graphql-config";
6
+ import { moduleConfig } from "#nitro-graphql/module-config";
7
+ import { directives } from "#nitro-graphql/server-directives";
8
+ import { resolvers } from "#nitro-graphql/server-resolvers";
9
+ import { schemas } from "#nitro-graphql/server-schemas";
10
10
  import { ApolloServer } from "@apollo/server";
11
11
  import { ApolloServerPluginLandingPageLocalDefault } from "@apollo/server/plugin/landingPage/default";
12
12
  import { makeExecutableSchema } from "@graphql-tools/schema";
13
- import { defineEventHandler } from "h3";
14
13
  import { startServerAndCreateH3Handler } from "nitro-graphql/utils/apollo";
14
+ import { defineEventHandler } from "nitro/h3";
15
15
 
16
16
  //#region src/routes/apollo-server.ts
17
17
  let buildSubgraphSchema = null;
@@ -0,0 +1,61 @@
1
+ import * as nitro_deps_h30 from "nitro/deps/h3";
2
+
3
+ //#region src/routes/debug.d.ts
4
+
5
+ /**
6
+ * Debug endpoint for inspecting virtual modules and GraphQL setup
7
+ * Only available in development mode
8
+ *
9
+ * Routes:
10
+ * - /_nitro/graphql/debug - HTML dashboard
11
+ * - /_nitro/graphql/debug?format=json - JSON API
12
+ */
13
+ declare const _default: nitro_deps_h30.EventHandlerWithFetch<nitro_deps_h30.EventHandlerRequest, Promise<string | {
14
+ timestamp: string;
15
+ environment: {
16
+ dev: any;
17
+ framework: any;
18
+ };
19
+ graphql: {
20
+ framework: any;
21
+ federation: any;
22
+ };
23
+ scanned: {
24
+ schemas: any;
25
+ schemaFiles: any;
26
+ resolvers: any;
27
+ resolverFiles: any;
28
+ directives: any;
29
+ directiveFiles: any;
30
+ documents: any;
31
+ documentFiles: any;
32
+ };
33
+ runtime: {
34
+ loadedResolvers: number;
35
+ loadedSchemas: number;
36
+ loadedDirectives: number;
37
+ };
38
+ virtualModules: any;
39
+ virtualModuleSamples: {
40
+ 'server-resolvers': {
41
+ resolverCount: number;
42
+ sample: {
43
+ hasResolver: boolean;
44
+ resolverKeys: string[];
45
+ }[];
46
+ };
47
+ 'server-schemas': {
48
+ schemaCount: number;
49
+ sample: {
50
+ defLength: number;
51
+ defPreview: string;
52
+ }[];
53
+ };
54
+ 'server-directives': {
55
+ directiveCount: number;
56
+ };
57
+ 'module-config': Record<string, any>;
58
+ };
59
+ }>>;
60
+ //#endregion
61
+ export { _default as default };