nitro-graphql 2.0.0-beta.31 → 2.0.0-beta.32
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.
- package/dist/codegen/client-types.d.mts +13 -0
- package/dist/codegen/client-types.mjs +176 -0
- package/dist/codegen/external-types.d.mts +12 -0
- package/dist/codegen/external-types.mjs +129 -0
- package/dist/codegen/index.d.mts +25 -0
- package/dist/codegen/index.mjs +38 -0
- package/dist/codegen/server-types.d.mts +13 -0
- package/dist/codegen/server-types.mjs +76 -0
- package/dist/codegen/validation.d.mts +13 -0
- package/dist/codegen/validation.mjs +96 -0
- package/dist/config/defaults.mjs +36 -0
- package/dist/constants.mjs +91 -0
- package/dist/ecosystem/nuxt.mjs +3 -3
- package/dist/rollup.d.mts +7 -7
- package/dist/rollup.mjs +73 -73
- package/dist/routes/apollo-server.d.mts +2 -2
- package/dist/routes/debug.d.mts +2 -2
- package/dist/routes/health.d.mts +2 -2
- package/dist/setup/file-watcher.mjs +80 -0
- package/dist/setup/rollup-integration.mjs +90 -0
- package/dist/setup/scaffold-generator.mjs +109 -0
- package/dist/setup/ts-config.mjs +69 -0
- package/dist/setup.d.mts +2 -2
- package/dist/setup.mjs +127 -274
- package/dist/types/index.d.mts +1 -1
- package/dist/utils/client-codegen.d.mts +1 -1
- package/dist/utils/client-codegen.mjs +5 -2
- package/dist/utils/directive-parser.d.mts +2 -1
- package/dist/utils/directive-parser.mjs +4 -2
- package/dist/utils/file-generator.mjs +1 -1
- package/dist/utils/index.d.mts +2 -2
- package/dist/utils/index.mjs +2 -2
- package/dist/utils/path-resolver.d.mts +2 -2
- package/dist/utils/path-resolver.mjs +2 -2
- package/dist/utils/server-codegen.mjs +4 -1
- package/dist/utils/type-generation.d.mts +6 -12
- package/dist/utils/type-generation.mjs +6 -419
- package/package.json +8 -2
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
//#region src/constants.ts
|
|
2
|
+
/**
|
|
3
|
+
* Constants and magic strings used throughout nitro-graphql
|
|
4
|
+
* Centralizing these values prevents typos and makes refactoring easier
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* GraphQL schema file extensions
|
|
8
|
+
*/
|
|
9
|
+
const GRAPHQL_EXTENSIONS = [".graphql", ".gql"];
|
|
10
|
+
/**
|
|
11
|
+
* Resolver file extensions
|
|
12
|
+
*/
|
|
13
|
+
const RESOLVER_EXTENSIONS = [".resolver.ts", ".resolver.js"];
|
|
14
|
+
/**
|
|
15
|
+
* Directive file extensions
|
|
16
|
+
*/
|
|
17
|
+
const DIRECTIVE_EXTENSIONS = [".directive.ts", ".directive.js"];
|
|
18
|
+
/**
|
|
19
|
+
* Framework names
|
|
20
|
+
*/
|
|
21
|
+
const FRAMEWORK_NUXT = "nuxt";
|
|
22
|
+
const FRAMEWORK_NITRO = "nitro";
|
|
23
|
+
/**
|
|
24
|
+
* Default directory names for GraphQL files
|
|
25
|
+
*/
|
|
26
|
+
const DIR_SERVER_GRAPHQL = "server/graphql";
|
|
27
|
+
/**
|
|
28
|
+
* Windows-compatible server GraphQL directory
|
|
29
|
+
*/
|
|
30
|
+
const DIR_SERVER_GRAPHQL_WIN = "server\\graphql";
|
|
31
|
+
/**
|
|
32
|
+
* Default GraphQL endpoint paths
|
|
33
|
+
*/
|
|
34
|
+
const ENDPOINT_GRAPHQL = "/api/graphql";
|
|
35
|
+
const ENDPOINT_HEALTH = "/api/graphql/health";
|
|
36
|
+
const ENDPOINT_DEBUG = "/_nitro/graphql/debug";
|
|
37
|
+
/**
|
|
38
|
+
* Configuration and scaffold file names
|
|
39
|
+
*/
|
|
40
|
+
const FILE_GRAPHQL_CONFIG = "graphql.config.ts";
|
|
41
|
+
const FILE_SCHEMA_TS = "schema.ts";
|
|
42
|
+
const FILE_CONFIG_TS = "config.ts";
|
|
43
|
+
const FILE_CONTEXT_DTS = "context.d.ts";
|
|
44
|
+
const FILE_CONTEXT_TS = "context.ts";
|
|
45
|
+
const FILE_INDEX_TS = "index.ts";
|
|
46
|
+
/**
|
|
47
|
+
* Rollup/Rolldown chunk output paths
|
|
48
|
+
*/
|
|
49
|
+
const CHUNK_PATH_GRAPHQL = "chunks/graphql/[name].mjs";
|
|
50
|
+
const CHUNK_PATH_UNKNOWN = "chunks/_/[name].mjs";
|
|
51
|
+
/**
|
|
52
|
+
* Default chunk names
|
|
53
|
+
*/
|
|
54
|
+
const CHUNK_NAME_SCHEMAS = "schemas";
|
|
55
|
+
const CHUNK_NAME_RESOLVERS = "resolvers";
|
|
56
|
+
/**
|
|
57
|
+
* Built-in GraphQL scalar types (should not be flagged as duplicates)
|
|
58
|
+
*/
|
|
59
|
+
const BUILTIN_SCALARS = [
|
|
60
|
+
"String",
|
|
61
|
+
"Int",
|
|
62
|
+
"Float",
|
|
63
|
+
"Boolean",
|
|
64
|
+
"ID",
|
|
65
|
+
"DateTime",
|
|
66
|
+
"JSON"
|
|
67
|
+
];
|
|
68
|
+
/**
|
|
69
|
+
* Supported HTTP methods for GraphQL endpoints
|
|
70
|
+
*/
|
|
71
|
+
const GRAPHQL_HTTP_METHODS = [
|
|
72
|
+
"GET",
|
|
73
|
+
"POST",
|
|
74
|
+
"OPTIONS"
|
|
75
|
+
];
|
|
76
|
+
/**
|
|
77
|
+
* Default paths for type generation (relative to buildDir)
|
|
78
|
+
*/
|
|
79
|
+
const DEFAULT_SERVER_TYPES_PATH = ".graphql/nitro-graphql-server.d.ts";
|
|
80
|
+
const DEFAULT_CLIENT_TYPES_PATH = ".graphql/nitro-graphql-client.d.ts";
|
|
81
|
+
/**
|
|
82
|
+
* Logger tag for nitro-graphql module
|
|
83
|
+
*/
|
|
84
|
+
const LOG_TAG = "nitro-graphql";
|
|
85
|
+
/**
|
|
86
|
+
* Default service directory name for main service
|
|
87
|
+
*/
|
|
88
|
+
const SERVICE_DEFAULT = "default";
|
|
89
|
+
|
|
90
|
+
//#endregion
|
|
91
|
+
export { BUILTIN_SCALARS, CHUNK_NAME_RESOLVERS, CHUNK_NAME_SCHEMAS, CHUNK_PATH_GRAPHQL, CHUNK_PATH_UNKNOWN, DEFAULT_CLIENT_TYPES_PATH, DEFAULT_SERVER_TYPES_PATH, DIRECTIVE_EXTENSIONS, DIR_SERVER_GRAPHQL, DIR_SERVER_GRAPHQL_WIN, ENDPOINT_DEBUG, ENDPOINT_GRAPHQL, ENDPOINT_HEALTH, FILE_CONFIG_TS, FILE_CONTEXT_DTS, FILE_CONTEXT_TS, FILE_GRAPHQL_CONFIG, FILE_INDEX_TS, FILE_SCHEMA_TS, FRAMEWORK_NITRO, FRAMEWORK_NUXT, GRAPHQL_EXTENSIONS, GRAPHQL_HTTP_METHODS, LOG_TAG, RESOLVER_EXTENSIONS, SERVICE_DEFAULT };
|
package/dist/ecosystem/nuxt.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getDefaultPaths, getTypesConfig, resolveFilePath } from "../utils/path-resolver.mjs";
|
|
2
|
-
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
3
2
|
import { dirname, join, relative, resolve } from "pathe";
|
|
3
|
+
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
4
4
|
import { defineNuxtModule, getLayerDirectories } from "@nuxt/kit";
|
|
5
5
|
|
|
6
6
|
//#region src/ecosystem/nuxt.ts
|
|
@@ -46,8 +46,8 @@ var nuxt_default = defineNuxtModule({
|
|
|
46
46
|
if (externalTypesPath) {
|
|
47
47
|
const relativePath = relativeWithDot(tsconfigDir, externalTypesPath);
|
|
48
48
|
options.references.push({ path: relativePath });
|
|
49
|
-
options.tsConfig.compilerOptions.paths[`#graphql/client/${service.name}`] = [relativePath];
|
|
50
|
-
options.tsConfig.include.push(relativePath);
|
|
49
|
+
if (options.tsConfig.compilerOptions) options.tsConfig.compilerOptions.paths[`#graphql/client/${service.name}`] = [relativePath];
|
|
50
|
+
if (options.tsConfig.include) options.tsConfig.include.push(relativePath);
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
});
|
package/dist/rollup.d.mts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Nitro } from "nitro/types";
|
|
2
2
|
|
|
3
3
|
//#region src/rollup.d.ts
|
|
4
|
-
declare function rollupConfig(
|
|
5
|
-
declare function virtualSchemas(
|
|
6
|
-
declare function virtualResolvers(
|
|
7
|
-
declare function virtualDirectives(
|
|
8
|
-
declare function getGraphQLConfig(
|
|
9
|
-
declare function virtualModuleConfig(
|
|
10
|
-
declare function virtualDebugInfo(
|
|
4
|
+
declare function rollupConfig(nitro: Nitro): Promise<void>;
|
|
5
|
+
declare function virtualSchemas(nitro: Nitro): void;
|
|
6
|
+
declare function virtualResolvers(nitro: Nitro): void;
|
|
7
|
+
declare function virtualDirectives(nitro: Nitro): void;
|
|
8
|
+
declare function getGraphQLConfig(nitro: Nitro): void;
|
|
9
|
+
declare function virtualModuleConfig(nitro: Nitro): void;
|
|
10
|
+
declare function virtualDebugInfo(nitro: Nitro): void;
|
|
11
11
|
//#endregion
|
|
12
12
|
export { getGraphQLConfig, rollupConfig, virtualDebugInfo, virtualDirectives, virtualModuleConfig, virtualResolvers, virtualSchemas };
|
package/dist/rollup.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getImportId, scanGraphql } from "./utils/index.mjs";
|
|
2
|
-
import { clientTypeGeneration, serverTypeGeneration } from "./
|
|
2
|
+
import { clientTypeGeneration, serverTypeGeneration } from "./codegen/index.mjs";
|
|
3
3
|
import { readFile } from "node:fs/promises";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
import { resolve } from "pathe";
|
|
@@ -7,23 +7,23 @@ import { parse } from "graphql";
|
|
|
7
7
|
import { genImport } from "knitwork";
|
|
8
8
|
|
|
9
9
|
//#region src/rollup.ts
|
|
10
|
-
async function rollupConfig(
|
|
11
|
-
virtualSchemas(
|
|
12
|
-
virtualResolvers(
|
|
13
|
-
virtualDirectives(
|
|
14
|
-
getGraphQLConfig(
|
|
15
|
-
virtualModuleConfig(
|
|
16
|
-
virtualDebugInfo(
|
|
17
|
-
|
|
10
|
+
async function rollupConfig(nitro) {
|
|
11
|
+
virtualSchemas(nitro);
|
|
12
|
+
virtualResolvers(nitro);
|
|
13
|
+
virtualDirectives(nitro);
|
|
14
|
+
getGraphQLConfig(nitro);
|
|
15
|
+
virtualModuleConfig(nitro);
|
|
16
|
+
virtualDebugInfo(nitro);
|
|
17
|
+
nitro.hooks.hook("rollup:before", (_, rollupConfig$1) => {
|
|
18
18
|
rollupConfig$1.plugins = rollupConfig$1.plugins || [];
|
|
19
|
-
const { include = /\.(?:graphql|gql)$/i, exclude, validate = false } =
|
|
19
|
+
const { include = /\.(?:graphql|gql)$/i, exclude, validate = false } = nitro.options.graphql?.loader || {};
|
|
20
20
|
if (Array.isArray(rollupConfig$1.plugins)) {
|
|
21
21
|
rollupConfig$1.plugins.push({
|
|
22
22
|
name: "nitro-graphql:virtual",
|
|
23
23
|
resolveId: {
|
|
24
24
|
order: "pre",
|
|
25
25
|
filter: { id: /^#nitro-graphql\// },
|
|
26
|
-
async handler(id, parent,
|
|
26
|
+
async handler(id, parent, _options) {
|
|
27
27
|
if (id.startsWith("#nitro-graphql/")) return `\0virtual:${id}`;
|
|
28
28
|
if (parent?.startsWith("\0virtual:#nitro-graphql")) {
|
|
29
29
|
const runtimeDir = fileURLToPath(new URL("routes", import.meta.url));
|
|
@@ -41,7 +41,7 @@ async function rollupConfig(app) {
|
|
|
41
41
|
async handler(id) {
|
|
42
42
|
if (id.startsWith("\0virtual:#nitro-graphql/")) {
|
|
43
43
|
const moduleName = id.slice(9);
|
|
44
|
-
const generator =
|
|
44
|
+
const generator = nitro.options.virtual?.[moduleName];
|
|
45
45
|
if (typeof generator === "function") try {
|
|
46
46
|
return {
|
|
47
47
|
code: await generator(),
|
|
@@ -81,7 +81,7 @@ async function rollupConfig(app) {
|
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
});
|
|
84
|
-
if (
|
|
84
|
+
if (nitro.options.dev) rollupConfig$1.plugins.push({
|
|
85
85
|
name: "nitro-graphql-watcher",
|
|
86
86
|
buildStart: {
|
|
87
87
|
order: "pre",
|
|
@@ -93,19 +93,19 @@ async function rollupConfig(app) {
|
|
|
93
93
|
});
|
|
94
94
|
}
|
|
95
95
|
});
|
|
96
|
-
|
|
97
|
-
await serverTypeGeneration(
|
|
98
|
-
await clientTypeGeneration(
|
|
96
|
+
nitro.hooks.hook("dev:reload", async () => {
|
|
97
|
+
await serverTypeGeneration(nitro, { silent: true });
|
|
98
|
+
await clientTypeGeneration(nitro, { silent: true });
|
|
99
99
|
});
|
|
100
100
|
}
|
|
101
|
-
function virtualSchemas(
|
|
102
|
-
const getSchemas = () => [...
|
|
103
|
-
|
|
104
|
-
|
|
101
|
+
function virtualSchemas(nitro) {
|
|
102
|
+
const getSchemas = () => [...nitro.scanSchemas, ...nitro.options.graphql?.typedefs ?? []];
|
|
103
|
+
nitro.options.virtual ??= {};
|
|
104
|
+
nitro.options.virtual["#nitro-graphql/server-schemas"] = () => {
|
|
105
105
|
try {
|
|
106
106
|
const imports = getSchemas();
|
|
107
107
|
if (imports.length === 0) {
|
|
108
|
-
if (
|
|
108
|
+
if (nitro.options.dev) nitro.logger.warn("[nitro-graphql] No schemas found. Virtual module will export empty array.");
|
|
109
109
|
return "export const schemas = []";
|
|
110
110
|
}
|
|
111
111
|
const importStatements = imports.map((handler) => `import ${getImportId(handler)} from '${handler}';`);
|
|
@@ -118,38 +118,38 @@ ${schemaArray.join(",\n")}
|
|
|
118
118
|
];
|
|
119
119
|
`;
|
|
120
120
|
} catch (error) {
|
|
121
|
-
|
|
121
|
+
nitro.logger.error("[nitro-graphql] Failed to generate virtual schema module:", error);
|
|
122
122
|
return "export const schemas = []";
|
|
123
123
|
}
|
|
124
124
|
};
|
|
125
125
|
}
|
|
126
|
-
function virtualResolvers(
|
|
127
|
-
const getResolvers = () => [...
|
|
128
|
-
|
|
129
|
-
|
|
126
|
+
function virtualResolvers(nitro) {
|
|
127
|
+
const getResolvers = () => [...nitro.scanResolvers];
|
|
128
|
+
nitro.options.virtual ??= {};
|
|
129
|
+
nitro.options.virtual["#nitro-graphql/server-resolvers"] = () => {
|
|
130
130
|
try {
|
|
131
131
|
const imports = getResolvers();
|
|
132
132
|
if (imports.length === 0) {
|
|
133
|
-
if (
|
|
133
|
+
if (nitro.options.dev) nitro.logger.warn("[nitro-graphql] No resolvers found. Virtual module will export empty array.");
|
|
134
134
|
return "export const resolvers = []";
|
|
135
135
|
}
|
|
136
136
|
const importsContent = [];
|
|
137
137
|
const invalidImports = [];
|
|
138
|
-
for (const { specifier, imports: importList, options } of imports) try {
|
|
138
|
+
for (const { specifier, imports: importList, options: options$1 } of imports) try {
|
|
139
139
|
if (!importList || importList.length === 0) {
|
|
140
140
|
invalidImports.push(`${specifier}: No exports found`);
|
|
141
141
|
continue;
|
|
142
142
|
}
|
|
143
|
-
const importCode = genImport(specifier, importList, options);
|
|
143
|
+
const importCode = genImport(specifier, importList, options$1);
|
|
144
144
|
importsContent.push(importCode);
|
|
145
145
|
} catch (error) {
|
|
146
146
|
const message = error instanceof Error ? error.message : String(error);
|
|
147
147
|
invalidImports.push(`${specifier}: ${message}`);
|
|
148
|
-
if (
|
|
148
|
+
if (nitro.options.dev) nitro.logger.error(`[nitro-graphql] Failed to generate import for ${specifier}:`, error);
|
|
149
149
|
}
|
|
150
|
-
if (invalidImports.length > 0 &&
|
|
151
|
-
|
|
152
|
-
for (const msg of invalidImports)
|
|
150
|
+
if (invalidImports.length > 0 && nitro.options.dev) {
|
|
151
|
+
nitro.logger.warn("[nitro-graphql] Some resolver imports could not be generated:");
|
|
152
|
+
for (const msg of invalidImports) nitro.logger.warn(` - ${msg}`);
|
|
153
153
|
}
|
|
154
154
|
const data = imports.map(({ imports: importList }) => importList.map((i) => `{ resolver: ${i.as} }`).join(",\n")).filter(Boolean).join(",\n");
|
|
155
155
|
return [
|
|
@@ -161,35 +161,35 @@ function virtualResolvers(app) {
|
|
|
161
161
|
""
|
|
162
162
|
].join("\n");
|
|
163
163
|
} catch (error) {
|
|
164
|
-
|
|
164
|
+
nitro.logger.error("[nitro-graphql] Failed to generate virtual resolver module:", error);
|
|
165
165
|
return "export const resolvers = []";
|
|
166
166
|
}
|
|
167
167
|
};
|
|
168
168
|
}
|
|
169
|
-
function virtualDirectives(
|
|
170
|
-
const getDirectives = () =>
|
|
171
|
-
|
|
172
|
-
|
|
169
|
+
function virtualDirectives(nitro) {
|
|
170
|
+
const getDirectives = () => nitro.scanDirectives || [];
|
|
171
|
+
nitro.options.virtual ??= {};
|
|
172
|
+
nitro.options.virtual["#nitro-graphql/server-directives"] = () => {
|
|
173
173
|
try {
|
|
174
174
|
const imports = getDirectives();
|
|
175
175
|
if (imports.length === 0) return "export const directives = []";
|
|
176
176
|
const importsContent = [];
|
|
177
177
|
const invalidImports = [];
|
|
178
|
-
for (const { specifier, imports: importList, options } of imports) try {
|
|
178
|
+
for (const { specifier, imports: importList, options: options$1 } of imports) try {
|
|
179
179
|
if (!importList || importList.length === 0) {
|
|
180
180
|
invalidImports.push(`${specifier}: No exports found`);
|
|
181
181
|
continue;
|
|
182
182
|
}
|
|
183
|
-
const importCode = genImport(specifier, importList, options);
|
|
183
|
+
const importCode = genImport(specifier, importList, options$1);
|
|
184
184
|
importsContent.push(importCode);
|
|
185
185
|
} catch (error) {
|
|
186
186
|
const message = error instanceof Error ? error.message : String(error);
|
|
187
187
|
invalidImports.push(`${specifier}: ${message}`);
|
|
188
|
-
if (
|
|
188
|
+
if (nitro.options.dev) nitro.logger.error(`[nitro-graphql] Failed to generate import for directive ${specifier}:`, error);
|
|
189
189
|
}
|
|
190
|
-
if (invalidImports.length > 0 &&
|
|
191
|
-
|
|
192
|
-
for (const msg of invalidImports)
|
|
190
|
+
if (invalidImports.length > 0 && nitro.options.dev) {
|
|
191
|
+
nitro.logger.warn("[nitro-graphql] Some directive imports could not be generated:");
|
|
192
|
+
for (const msg of invalidImports) nitro.logger.warn(` - ${msg}`);
|
|
193
193
|
}
|
|
194
194
|
const data = imports.map(({ imports: importList }) => importList.map((i) => `{ directive: ${i.as} }`).join(",\n")).filter(Boolean).join(",\n");
|
|
195
195
|
return [
|
|
@@ -201,76 +201,76 @@ function virtualDirectives(app) {
|
|
|
201
201
|
""
|
|
202
202
|
].join("\n");
|
|
203
203
|
} catch (error) {
|
|
204
|
-
|
|
204
|
+
nitro.logger.error("[nitro-graphql] Failed to generate virtual directive module:", error);
|
|
205
205
|
return "export const directives = []";
|
|
206
206
|
}
|
|
207
207
|
};
|
|
208
208
|
}
|
|
209
|
-
function getGraphQLConfig(
|
|
210
|
-
const configPath = resolve(
|
|
211
|
-
|
|
212
|
-
|
|
209
|
+
function getGraphQLConfig(nitro) {
|
|
210
|
+
const configPath = resolve(nitro.graphql.serverDir, "config.ts");
|
|
211
|
+
nitro.options.virtual ??= {};
|
|
212
|
+
nitro.options.virtual["#nitro-graphql/graphql-config"] = () => {
|
|
213
213
|
return `import config from '${configPath}'
|
|
214
214
|
const importedConfig = config
|
|
215
215
|
export { importedConfig }
|
|
216
216
|
`;
|
|
217
217
|
};
|
|
218
218
|
}
|
|
219
|
-
function virtualModuleConfig(
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
const moduleConfig =
|
|
219
|
+
function virtualModuleConfig(nitro) {
|
|
220
|
+
nitro.options.virtual ??= {};
|
|
221
|
+
nitro.options.virtual["#nitro-graphql/module-config"] = () => {
|
|
222
|
+
const moduleConfig = nitro.options.graphql || {};
|
|
223
223
|
return `export const moduleConfig = ${JSON.stringify(moduleConfig, null, 2)};`;
|
|
224
224
|
};
|
|
225
225
|
}
|
|
226
|
-
function virtualDebugInfo(
|
|
227
|
-
|
|
228
|
-
|
|
226
|
+
function virtualDebugInfo(nitro) {
|
|
227
|
+
nitro.options.virtual ??= {};
|
|
228
|
+
nitro.options.virtual["#nitro-graphql/debug-info"] = () => {
|
|
229
229
|
const virtualModuleCodes = {};
|
|
230
230
|
try {
|
|
231
|
-
const schemasGenerator =
|
|
231
|
+
const schemasGenerator = nitro.options.virtual["#nitro-graphql/server-schemas"];
|
|
232
232
|
if (schemasGenerator && typeof schemasGenerator === "function") virtualModuleCodes["server-schemas"] = schemasGenerator();
|
|
233
233
|
} catch (error) {
|
|
234
234
|
virtualModuleCodes["server-schemas"] = `// Error generating: ${error instanceof Error ? error.message : String(error)}`;
|
|
235
235
|
}
|
|
236
236
|
try {
|
|
237
|
-
const resolversGenerator =
|
|
237
|
+
const resolversGenerator = nitro.options.virtual["#nitro-graphql/server-resolvers"];
|
|
238
238
|
if (resolversGenerator && typeof resolversGenerator === "function") virtualModuleCodes["server-resolvers"] = resolversGenerator();
|
|
239
239
|
} catch (error) {
|
|
240
240
|
virtualModuleCodes["server-resolvers"] = `// Error generating: ${error instanceof Error ? error.message : String(error)}`;
|
|
241
241
|
}
|
|
242
242
|
try {
|
|
243
|
-
const directivesGenerator =
|
|
243
|
+
const directivesGenerator = nitro.options.virtual["#nitro-graphql/server-directives"];
|
|
244
244
|
if (directivesGenerator && typeof directivesGenerator === "function") virtualModuleCodes["server-directives"] = directivesGenerator();
|
|
245
245
|
} catch (error) {
|
|
246
246
|
virtualModuleCodes["server-directives"] = `// Error generating: ${error instanceof Error ? error.message : String(error)}`;
|
|
247
247
|
}
|
|
248
248
|
try {
|
|
249
|
-
const moduleConfigGenerator =
|
|
249
|
+
const moduleConfigGenerator = nitro.options.virtual["#nitro-graphql/module-config"];
|
|
250
250
|
if (moduleConfigGenerator && typeof moduleConfigGenerator === "function") virtualModuleCodes["module-config"] = moduleConfigGenerator();
|
|
251
251
|
} catch (error) {
|
|
252
252
|
virtualModuleCodes["module-config"] = `// Error generating: ${error instanceof Error ? error.message : String(error)}`;
|
|
253
253
|
}
|
|
254
254
|
try {
|
|
255
|
-
const graphqlConfigGenerator =
|
|
255
|
+
const graphqlConfigGenerator = nitro.options.virtual["#nitro-graphql/graphql-config"];
|
|
256
256
|
if (graphqlConfigGenerator && typeof graphqlConfigGenerator === "function") virtualModuleCodes["graphql-config"] = graphqlConfigGenerator();
|
|
257
257
|
} catch (error) {
|
|
258
258
|
virtualModuleCodes["graphql-config"] = `// Error generating: ${error instanceof Error ? error.message : String(error)}`;
|
|
259
259
|
}
|
|
260
260
|
const debugInfo = {
|
|
261
|
-
isDev:
|
|
262
|
-
framework:
|
|
263
|
-
graphqlFramework:
|
|
264
|
-
federation:
|
|
261
|
+
isDev: nitro.options.dev,
|
|
262
|
+
framework: nitro.options.framework.name,
|
|
263
|
+
graphqlFramework: nitro.options.graphql?.framework,
|
|
264
|
+
federation: nitro.options.graphql?.federation,
|
|
265
265
|
scanned: {
|
|
266
|
-
schemas:
|
|
267
|
-
schemaFiles:
|
|
268
|
-
resolvers:
|
|
269
|
-
resolverFiles:
|
|
270
|
-
directives:
|
|
271
|
-
directiveFiles:
|
|
272
|
-
documents:
|
|
273
|
-
documentFiles:
|
|
266
|
+
schemas: nitro.scanSchemas?.length || 0,
|
|
267
|
+
schemaFiles: nitro.scanSchemas || [],
|
|
268
|
+
resolvers: nitro.scanResolvers?.length || 0,
|
|
269
|
+
resolverFiles: nitro.scanResolvers || [],
|
|
270
|
+
directives: nitro.scanDirectives?.length || 0,
|
|
271
|
+
directiveFiles: nitro.scanDirectives || [],
|
|
272
|
+
documents: nitro.scanDocuments?.length || 0,
|
|
273
|
+
documentFiles: nitro.scanDocuments || []
|
|
274
274
|
},
|
|
275
275
|
virtualModules: virtualModuleCodes
|
|
276
276
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as nitro_deps_h35 from "nitro/deps/h3";
|
|
2
2
|
|
|
3
3
|
//#region src/routes/apollo-server.d.ts
|
|
4
|
-
declare const _default:
|
|
4
|
+
declare const _default: nitro_deps_h35.EventHandlerWithFetch<nitro_deps_h35.EventHandlerRequest, Promise<any>>;
|
|
5
5
|
//#endregion
|
|
6
6
|
export { _default as default };
|
package/dist/routes/debug.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as nitro_deps_h31 from "nitro/deps/h3";
|
|
2
2
|
|
|
3
3
|
//#region src/routes/debug.d.ts
|
|
4
4
|
|
|
@@ -10,7 +10,7 @@ import * as nitro_deps_h30 from "nitro/deps/h3";
|
|
|
10
10
|
* - /_nitro/graphql/debug - HTML dashboard
|
|
11
11
|
* - /_nitro/graphql/debug?format=json - JSON API
|
|
12
12
|
*/
|
|
13
|
-
declare const _default:
|
|
13
|
+
declare const _default: nitro_deps_h31.EventHandlerWithFetch<nitro_deps_h31.EventHandlerRequest, Promise<string | {
|
|
14
14
|
timestamp: string;
|
|
15
15
|
environment: {
|
|
16
16
|
dev: any;
|
package/dist/routes/health.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as nitro_deps_h30 from "nitro/deps/h3";
|
|
2
2
|
|
|
3
3
|
//#region src/routes/health.d.ts
|
|
4
|
-
declare const _default:
|
|
4
|
+
declare const _default: nitro_deps_h30.EventHandlerWithFetch<nitro_deps_h30.EventHandlerRequest, Promise<{
|
|
5
5
|
status: string;
|
|
6
6
|
message: string;
|
|
7
7
|
timestamp: string;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { DIRECTIVE_EXTENSIONS, DIR_SERVER_GRAPHQL, DIR_SERVER_GRAPHQL_WIN, GRAPHQL_EXTENSIONS, LOG_TAG, RESOLVER_EXTENSIONS } from "../constants.mjs";
|
|
2
|
+
import { DEFAULT_WATCHER_IGNORE_INITIAL, DEFAULT_WATCHER_PERSISTENT } from "../config/defaults.mjs";
|
|
3
|
+
import { generateDirectiveSchemas } from "../utils/directive-parser.mjs";
|
|
4
|
+
import { generateLayerIgnorePatterns, getLayerAppDirectories, getLayerServerDirectories, scanDirectives, scanResolvers, scanSchemas } from "../utils/index.mjs";
|
|
5
|
+
import { clientTypeGeneration, serverTypeGeneration } from "../codegen/index.mjs";
|
|
6
|
+
import consola from "consola";
|
|
7
|
+
import { join } from "pathe";
|
|
8
|
+
import { watch } from "chokidar";
|
|
9
|
+
|
|
10
|
+
//#region src/setup/file-watcher.ts
|
|
11
|
+
const logger = consola.withTag(LOG_TAG);
|
|
12
|
+
/**
|
|
13
|
+
* Setup file watcher for GraphQL files (schemas, resolvers, directives, documents)
|
|
14
|
+
* Watches for changes and triggers type regeneration and dev server reload
|
|
15
|
+
*/
|
|
16
|
+
function setupFileWatcher(nitro, watchDirs) {
|
|
17
|
+
const watcher = watch(watchDirs, {
|
|
18
|
+
persistent: DEFAULT_WATCHER_PERSISTENT,
|
|
19
|
+
ignoreInitial: DEFAULT_WATCHER_IGNORE_INITIAL,
|
|
20
|
+
ignored: [...nitro.options.ignore, ...generateLayerIgnorePatterns()]
|
|
21
|
+
});
|
|
22
|
+
watcher.on("all", async (_, path) => {
|
|
23
|
+
const isGraphQLFile = GRAPHQL_EXTENSIONS.some((ext) => path.endsWith(ext));
|
|
24
|
+
const isResolverFile = RESOLVER_EXTENSIONS.some((ext) => path.endsWith(ext));
|
|
25
|
+
const isDirectiveFile = DIRECTIVE_EXTENSIONS.some((ext) => path.endsWith(ext));
|
|
26
|
+
if (isGraphQLFile || isResolverFile || isDirectiveFile) if (path.includes(nitro.graphql.serverDir) || path.includes(DIR_SERVER_GRAPHQL) || path.includes(DIR_SERVER_GRAPHQL_WIN) || isResolverFile || isDirectiveFile) {
|
|
27
|
+
const directives = await scanDirectives(nitro);
|
|
28
|
+
nitro.scanDirectives = directives;
|
|
29
|
+
if (!nitro.scanSchemas) nitro.scanSchemas = [];
|
|
30
|
+
const directivesPath = await generateDirectiveSchemas(nitro, directives);
|
|
31
|
+
const schemas = await scanSchemas(nitro);
|
|
32
|
+
if (directivesPath && !schemas.includes(directivesPath)) schemas.push(directivesPath);
|
|
33
|
+
nitro.scanSchemas = schemas;
|
|
34
|
+
await scanResolvers(nitro).then((r) => nitro.scanResolvers = r);
|
|
35
|
+
logger.success("Types regenerated");
|
|
36
|
+
await serverTypeGeneration(nitro, { silent: true });
|
|
37
|
+
await clientTypeGeneration(nitro, { silent: true });
|
|
38
|
+
await nitro.hooks.callHook("dev:reload");
|
|
39
|
+
} else {
|
|
40
|
+
logger.success("Types regenerated");
|
|
41
|
+
await clientTypeGeneration(nitro, { silent: true });
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
return watcher;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Determine which directories to watch based on framework and configuration
|
|
48
|
+
*/
|
|
49
|
+
function getWatchDirectories(nitro) {
|
|
50
|
+
const watchDirs = [];
|
|
51
|
+
switch (nitro.options.framework.name) {
|
|
52
|
+
case "nuxt": {
|
|
53
|
+
watchDirs.push(nitro.graphql.clientDir);
|
|
54
|
+
const layerServerDirs = getLayerServerDirectories(nitro);
|
|
55
|
+
const layerAppDirs = getLayerAppDirectories(nitro);
|
|
56
|
+
for (const layerServerDir of layerServerDirs) watchDirs.push(join(layerServerDir, "graphql"));
|
|
57
|
+
for (const layerAppDir of layerAppDirs) watchDirs.push(join(layerAppDir, "graphql"));
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
case "nitro":
|
|
61
|
+
watchDirs.push(nitro.graphql.clientDir);
|
|
62
|
+
watchDirs.push(nitro.graphql.serverDir);
|
|
63
|
+
break;
|
|
64
|
+
default:
|
|
65
|
+
watchDirs.push(nitro.graphql.clientDir);
|
|
66
|
+
watchDirs.push(nitro.graphql.serverDir);
|
|
67
|
+
}
|
|
68
|
+
if (nitro.options.graphql?.externalServices?.length) {
|
|
69
|
+
for (const service of nitro.options.graphql.externalServices) if (service.documents?.length) for (const pattern of service.documents) {
|
|
70
|
+
if (!pattern) continue;
|
|
71
|
+
const baseDir = pattern.split("**")[0]?.replace(/\/$/, "") || ".";
|
|
72
|
+
const resolvedDir = join(nitro.options.rootDir, baseDir);
|
|
73
|
+
if (!watchDirs.includes(resolvedDir)) watchDirs.push(resolvedDir);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return watchDirs;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
//#endregion
|
|
80
|
+
export { getWatchDirectories, setupFileWatcher };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { CHUNK_NAME_RESOLVERS, CHUNK_NAME_SCHEMAS, CHUNK_PATH_GRAPHQL, CHUNK_PATH_UNKNOWN, GRAPHQL_EXTENSIONS, RESOLVER_EXTENSIONS } from "../constants.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/setup/rollup-integration.ts
|
|
4
|
+
/**
|
|
5
|
+
* Setup Rollup/Rolldown chunking configuration for GraphQL files
|
|
6
|
+
* Creates separate chunks for schemas and resolvers to optimize bundle size
|
|
7
|
+
*/
|
|
8
|
+
function setupRollupChunking(nitro) {
|
|
9
|
+
nitro.hooks.hook("rollup:before", (_, rollupConfig) => {
|
|
10
|
+
const manualChunks = rollupConfig.output?.manualChunks;
|
|
11
|
+
const chunkFiles = rollupConfig.output?.chunkFileNames;
|
|
12
|
+
if (!rollupConfig.output.inlineDynamicImports) {
|
|
13
|
+
rollupConfig.output.manualChunks = (id, _meta) => {
|
|
14
|
+
if (isGraphQLFile(id)) return getSchemaChunkName(id);
|
|
15
|
+
if (isResolverFile(id)) return getResolverChunkName(id);
|
|
16
|
+
if (typeof manualChunks === "function") return manualChunks(id, meta);
|
|
17
|
+
};
|
|
18
|
+
rollupConfig.output.advancedChunks = {
|
|
19
|
+
groups: [{
|
|
20
|
+
name: CHUNK_NAME_SCHEMAS,
|
|
21
|
+
test: /* @__PURE__ */ new RegExp(`\\.(${GRAPHQL_EXTENSIONS.map((e) => e.slice(1)).join("|")})$`)
|
|
22
|
+
}, {
|
|
23
|
+
name: CHUNK_NAME_RESOLVERS,
|
|
24
|
+
test: /\.resolver\.(ts|js)$/
|
|
25
|
+
}],
|
|
26
|
+
minSize: 0,
|
|
27
|
+
minShareCount: 1
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
rollupConfig.output.chunkFileNames = (chunkInfo) => {
|
|
31
|
+
if (chunkInfo.moduleIds && chunkInfo.moduleIds.some((id) => isGraphQLFile(id) || isResolverFile(id))) return CHUNK_PATH_GRAPHQL;
|
|
32
|
+
if (typeof chunkFiles === "function") return chunkFiles(chunkInfo);
|
|
33
|
+
return CHUNK_PATH_UNKNOWN;
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Check if a file is a GraphQL schema file
|
|
39
|
+
*/
|
|
40
|
+
function isGraphQLFile(id) {
|
|
41
|
+
return GRAPHQL_EXTENSIONS.some((ext) => id.endsWith(ext));
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Check if a file is a resolver file
|
|
45
|
+
*/
|
|
46
|
+
function isResolverFile(id) {
|
|
47
|
+
return RESOLVER_EXTENSIONS.some((ext) => id.endsWith(ext));
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Get chunk name for GraphQL schema files
|
|
51
|
+
* All schemas are bundled into a single chunk since GraphQL server
|
|
52
|
+
* merges them at runtime anyway - no benefit from separate chunks
|
|
53
|
+
*/
|
|
54
|
+
function getSchemaChunkName(_id) {
|
|
55
|
+
return CHUNK_NAME_SCHEMAS;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Get chunk name for resolver files
|
|
59
|
+
* All resolvers are bundled into a single chunk since GraphQL server
|
|
60
|
+
* requires all resolvers to be registered at startup - no runtime lazy loading
|
|
61
|
+
*/
|
|
62
|
+
function getResolverChunkName(_id) {
|
|
63
|
+
return CHUNK_NAME_RESOLVERS;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Configure external dependencies for Rollup
|
|
67
|
+
* Marks codegen and federation packages as external
|
|
68
|
+
*/
|
|
69
|
+
function setupRollupExternals(nitro) {
|
|
70
|
+
nitro.hooks.hook("rollup:before", (_, rollupConfig) => {
|
|
71
|
+
rollupConfig.external = rollupConfig.external || [];
|
|
72
|
+
const allExternals = [...["oxc-parser", "@oxc-parser"]];
|
|
73
|
+
if (!nitro.options.graphql?.federation?.enabled) allExternals.push(...[
|
|
74
|
+
"@apollo/subgraph",
|
|
75
|
+
"@apollo/federation-internals",
|
|
76
|
+
"@apollo/cache-control-types"
|
|
77
|
+
]);
|
|
78
|
+
if (Array.isArray(rollupConfig.external)) rollupConfig.external.push(...allExternals);
|
|
79
|
+
else if (typeof rollupConfig.external === "function") {
|
|
80
|
+
const originalExternal = rollupConfig.external;
|
|
81
|
+
rollupConfig.external = (id, parent, isResolved) => {
|
|
82
|
+
if (allExternals.some((external) => id.includes(external))) return true;
|
|
83
|
+
return originalExternal(id, parent, isResolved);
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
//#endregion
|
|
90
|
+
export { setupRollupChunking, setupRollupExternals };
|