nitro-graphql 2.0.0-beta.4 → 2.0.0-beta.40
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/README.md +441 -27
- package/dist/cli/commands/generate.d.mts +26 -0
- package/dist/cli/commands/generate.mjs +196 -0
- package/dist/cli/commands/index.d.mts +4 -0
- package/dist/cli/commands/index.mjs +5 -0
- package/dist/cli/commands/init.d.mts +46 -0
- package/dist/cli/commands/init.mjs +195 -0
- package/dist/cli/commands/validate.d.mts +10 -0
- package/dist/cli/commands/validate.mjs +69 -0
- package/dist/cli/completions.d.mts +7 -0
- package/dist/cli/completions.mjs +34 -0
- package/dist/cli/config.d.mts +75 -0
- package/dist/cli/config.mjs +20 -0
- package/dist/cli/index.d.mts +24 -0
- package/dist/cli/index.mjs +253 -0
- package/dist/core/codegen/client.d.mts +23 -0
- package/dist/core/codegen/client.mjs +150 -0
- package/dist/core/codegen/document-loader.d.mts +10 -0
- package/dist/core/codegen/document-loader.mjs +18 -0
- package/dist/core/codegen/index.d.mts +8 -0
- package/dist/core/codegen/index.mjs +9 -0
- package/dist/core/codegen/plugin.d.mts +20 -0
- package/dist/core/codegen/plugin.mjs +30 -0
- package/dist/core/codegen/runtime.d.mts +20 -0
- package/dist/core/codegen/runtime.mjs +60 -0
- package/dist/core/codegen/schema-loader.d.mts +28 -0
- package/dist/core/codegen/schema-loader.mjs +128 -0
- package/dist/core/codegen/server.d.mts +28 -0
- package/dist/core/codegen/server.mjs +143 -0
- package/dist/core/codegen/validation.d.mts +13 -0
- package/dist/core/codegen/validation.mjs +96 -0
- package/dist/core/config.d.mts +50 -0
- package/dist/core/config.mjs +82 -0
- package/dist/core/constants.d.mts +188 -0
- package/dist/core/constants.mjs +210 -0
- package/dist/core/index.d.mts +32 -0
- package/dist/core/index.mjs +26 -0
- package/dist/core/scanning/ast-scanner.d.mts +23 -0
- package/dist/core/scanning/ast-scanner.mjs +103 -0
- package/dist/core/scanning/common.d.mts +37 -0
- package/dist/core/scanning/common.mjs +60 -0
- package/dist/core/scanning/directives.d.mts +10 -0
- package/dist/core/scanning/directives.mjs +29 -0
- package/dist/core/scanning/documents.d.mts +21 -0
- package/dist/core/scanning/documents.mjs +43 -0
- package/dist/core/scanning/index.d.mts +7 -0
- package/dist/core/scanning/index.mjs +8 -0
- package/dist/core/scanning/resolvers.d.mts +10 -0
- package/dist/core/scanning/resolvers.mjs +58 -0
- package/dist/core/scanning/schemas.d.mts +14 -0
- package/dist/core/scanning/schemas.mjs +64 -0
- package/dist/core/schema/builder.d.mts +53 -0
- package/dist/core/schema/builder.mjs +70 -0
- package/dist/core/schema/federation.d.mts +34 -0
- package/dist/core/schema/federation.mjs +40 -0
- package/dist/core/schema/index.d.mts +3 -0
- package/dist/core/schema/index.mjs +4 -0
- package/dist/core/types/adapter.d.mts +58 -0
- package/dist/core/types/codegen.d.mts +133 -0
- package/dist/core/types/config.d.mts +212 -0
- package/dist/core/types/config.mjs +1 -0
- package/dist/{utils/define.d.ts → core/types/define.d.mts} +3 -30
- package/dist/core/types/define.mjs +1 -0
- package/dist/core/types/index.d.mts +5 -0
- package/dist/core/types/index.mjs +1 -0
- package/dist/core/types/scanning.d.mts +69 -0
- package/dist/core/types/scanning.mjs +1 -0
- package/dist/{utils/directive-parser.d.ts → core/utils/directive-parser.d.mts} +21 -4
- package/dist/{utils/directive-parser.js → core/utils/directive-parser.mjs} +25 -34
- package/dist/core/utils/errors.d.mts +77 -0
- package/dist/core/utils/errors.mjs +93 -0
- package/dist/core/utils/file-io.d.mts +24 -0
- package/dist/core/utils/file-io.mjs +47 -0
- package/dist/core/utils/imports.d.mts +15 -0
- package/dist/core/utils/imports.mjs +25 -0
- package/dist/core/utils/index.d.mts +7 -0
- package/dist/core/utils/index.mjs +8 -0
- package/dist/core/utils/logger.d.mts +19 -0
- package/dist/core/utils/logger.mjs +38 -0
- package/dist/core/utils/ofetch-templates.d.mts +30 -0
- package/dist/core/utils/ofetch-templates.mjs +135 -0
- package/dist/core/validation/external-services.d.mts +11 -0
- package/dist/core/validation/external-services.mjs +34 -0
- package/dist/core/validation/index.d.mts +2 -0
- package/dist/core/validation/index.mjs +3 -0
- package/dist/define.d.mts +294 -0
- package/dist/define.mjs +323 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.mjs +6 -0
- package/dist/nitro/adapter.d.mts +30 -0
- package/dist/nitro/adapter.mjs +97 -0
- package/dist/{utils/apollo.d.ts → nitro/apollo.d.mts} +3 -3
- package/dist/nitro/apollo.mjs +59 -0
- package/dist/nitro/codegen.d.mts +19 -0
- package/dist/nitro/codegen.mjs +141 -0
- package/dist/nitro/config.d.mts +52 -0
- package/dist/nitro/config.mjs +58 -0
- package/dist/nitro/index.d.mts +46 -0
- package/dist/nitro/index.mjs +65 -0
- package/dist/nitro/paths.d.mts +54 -0
- package/dist/nitro/paths.mjs +93 -0
- package/dist/nitro/rollup.d.mts +6 -0
- package/dist/nitro/rollup.mjs +95 -0
- package/dist/nitro/routes/apollo-server.d.mts +6 -0
- package/dist/nitro/routes/apollo-server.mjs +71 -0
- package/dist/nitro/routes/debug-template.d.mts +15 -0
- package/dist/nitro/routes/debug-template.mjs +385 -0
- package/dist/nitro/routes/debug.d.mts +55 -0
- package/dist/nitro/routes/debug.mjs +102 -0
- package/dist/nitro/routes/graphql-yoga.d.mts +6 -0
- package/dist/nitro/routes/graphql-yoga.mjs +62 -0
- package/dist/nitro/routes/health.d.mts +10 -0
- package/dist/{routes/health.js → nitro/routes/health.mjs} +4 -3
- package/dist/nitro/setup/file-watcher.d.mts +16 -0
- package/dist/nitro/setup/file-watcher.mjs +80 -0
- package/dist/nitro/setup/logging.d.mts +17 -0
- package/dist/nitro/setup/logging.mjs +66 -0
- package/dist/nitro/setup/rollup-integration.d.mts +16 -0
- package/dist/nitro/setup/rollup-integration.mjs +90 -0
- package/dist/nitro/setup/routes.d.mts +10 -0
- package/dist/nitro/setup/routes.mjs +35 -0
- package/dist/nitro/setup/ts-config.d.mts +11 -0
- package/dist/nitro/setup/ts-config.mjs +69 -0
- package/dist/nitro/setup.d.mts +12 -0
- package/dist/nitro/setup.mjs +231 -0
- package/dist/nitro/types.d.mts +378 -0
- package/dist/nitro/types.mjs +1 -0
- package/dist/nitro/virtual/generators.d.mts +31 -0
- package/dist/nitro/virtual/generators.mjs +193 -0
- package/dist/nitro/virtual/stubs.d.mts +20 -0
- package/dist/nitro/virtual/stubs.mjs +31 -0
- package/dist/{ecosystem/nuxt.d.ts → nuxt.d.mts} +1 -1
- package/dist/nuxt.mjs +109 -0
- package/dist/{graphql/server.d.ts → stubs/index.d.mts} +5 -1
- package/dist/stubs/index.mjs +1 -0
- package/package.json +97 -78
- package/dist/ecosystem/nuxt.js +0 -67
- package/dist/graphql/index.d.ts +0 -5
- package/dist/index.d.ts +0 -8
- package/dist/index.js +0 -264
- package/dist/rollup.js +0 -119
- package/dist/routes/apollo-server.d.ts +0 -6
- package/dist/routes/apollo-server.js +0 -89
- package/dist/routes/graphql-yoga.d.ts +0 -6
- package/dist/routes/graphql-yoga.js +0 -91
- package/dist/routes/health.d.ts +0 -6
- package/dist/types/index.d.ts +0 -128
- package/dist/types/standard-schema.d.ts +0 -59
- package/dist/utils/apollo.js +0 -61
- package/dist/utils/client-codegen.d.ts +0 -38
- package/dist/utils/client-codegen.js +0 -290
- package/dist/utils/define.js +0 -57
- package/dist/utils/index.d.ts +0 -39
- package/dist/utils/index.js +0 -250
- package/dist/utils/server-codegen.d.ts +0 -7
- package/dist/utils/server-codegen.js +0 -136
- package/dist/utils/type-generation.d.ts +0 -7
- package/dist/utils/type-generation.js +0 -287
- package/dist/vite.d.ts +0 -25
- package/dist/vite.js +0 -40
- /package/dist/{graphql/index.js → core/types/adapter.mjs} +0 -0
- /package/dist/{graphql/server.js → core/types/codegen.mjs} +0 -0
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { getImportId } from "../../core/utils/imports.mjs";
|
|
2
|
+
import { isAbsolute, resolve } from "pathe";
|
|
3
|
+
import { genImport } from "knitwork";
|
|
4
|
+
|
|
5
|
+
//#region src/nitro/virtual/generators.ts
|
|
6
|
+
function normalizeExtendConfig(extend) {
|
|
7
|
+
if (!extend || !Array.isArray(extend) || extend.length === 0) return null;
|
|
8
|
+
const resolvers = [];
|
|
9
|
+
const schemas = [];
|
|
10
|
+
for (const source of extend) if (typeof source === "string") {
|
|
11
|
+
resolvers.push(`${source}/resolvers`);
|
|
12
|
+
schemas.push(`${source}/schema`);
|
|
13
|
+
} else if (source && typeof source === "object") {
|
|
14
|
+
const obj = source;
|
|
15
|
+
if (obj.resolvers) {
|
|
16
|
+
const r = Array.isArray(obj.resolvers) ? obj.resolvers : [obj.resolvers];
|
|
17
|
+
resolvers.push(...r);
|
|
18
|
+
}
|
|
19
|
+
if (obj.schemas) {
|
|
20
|
+
const s = Array.isArray(obj.schemas) ? obj.schemas : [obj.schemas];
|
|
21
|
+
schemas.push(...s);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (resolvers.length === 0 && schemas.length === 0) return null;
|
|
25
|
+
return {
|
|
26
|
+
resolvers,
|
|
27
|
+
schemas
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Resolve extend path to absolute path
|
|
32
|
+
* Supports: relative paths, absolute paths, package names
|
|
33
|
+
*/
|
|
34
|
+
function resolveExtendPath(nitro, inputPath) {
|
|
35
|
+
if (inputPath.startsWith("@") || !inputPath.startsWith(".") && !inputPath.startsWith("/")) return inputPath;
|
|
36
|
+
if (isAbsolute(inputPath)) return inputPath;
|
|
37
|
+
return resolve(nitro.options.rootDir, inputPath);
|
|
38
|
+
}
|
|
39
|
+
function generateImportModule(items, exportName, wrapperKey) {
|
|
40
|
+
if (!items.length) return `export const ${exportName} = []`;
|
|
41
|
+
const imports = items.flatMap(({ specifier, imports: list, options }) => list?.length ? [genImport(specifier, list, options)] : []);
|
|
42
|
+
const data = items.flatMap(({ imports: list }) => list.map((i) => `{ ${wrapperKey}: ${i.as || i.name} }`));
|
|
43
|
+
return `${imports.join("\n")}\n\nexport const ${exportName} = [\n${data.join(",\n")}\n]`;
|
|
44
|
+
}
|
|
45
|
+
function safeGenerateModuleCode(nitro, moduleName) {
|
|
46
|
+
try {
|
|
47
|
+
const generator = nitro.options.virtual?.[moduleName];
|
|
48
|
+
if (generator && typeof generator === "function") return generator();
|
|
49
|
+
return "// Module not found";
|
|
50
|
+
} catch (error) {
|
|
51
|
+
return `// Error: ${error instanceof Error ? error.message : String(error)}`;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const serverSchemas = {
|
|
55
|
+
id: "#nitro-graphql/server-schemas",
|
|
56
|
+
getCode: (nitro) => {
|
|
57
|
+
const ext = normalizeExtendConfig(nitro.options.graphql?.extend);
|
|
58
|
+
const skipLocalScan = nitro.options.graphql?.skipLocalScan === true;
|
|
59
|
+
if (ext && ext.schemas.length > 0) {
|
|
60
|
+
const schemaPaths = ext.schemas.map((p) => resolveExtendPath(nitro, p));
|
|
61
|
+
const scannedSchemas = [...nitro.scanSchemas, ...nitro.options.graphql?.typedefs ?? []];
|
|
62
|
+
if (!skipLocalScan && scannedSchemas.length > 0) {
|
|
63
|
+
const extImports = schemaPaths.map((p, i) => `import { schemaString as extSchema${i} } from '${p}'`);
|
|
64
|
+
const scannedImports = scannedSchemas.map((s) => `import ${getImportId(s)} from '${s}';`);
|
|
65
|
+
const extDefs = schemaPaths.map((_, i) => `{ def: extSchema${i} }`);
|
|
66
|
+
const scannedDefs = scannedSchemas.map((s) => `{ def: ${getImportId(s)} }`);
|
|
67
|
+
return `${extImports.join("\n")}
|
|
68
|
+
${scannedImports.join("\n")}
|
|
69
|
+
|
|
70
|
+
export const schemas = [
|
|
71
|
+
${[...extDefs, ...scannedDefs].join(",\n")}
|
|
72
|
+
]`;
|
|
73
|
+
}
|
|
74
|
+
if (schemaPaths.length === 1) return `import { schemaString, typeDefs } from '${schemaPaths[0]}'
|
|
75
|
+
export { schemaString, typeDefs }
|
|
76
|
+
export const schemas = [{ def: schemaString }]`;
|
|
77
|
+
const imports = schemaPaths.map((p, i) => `import { schemaString as schema${i} } from '${p}'`);
|
|
78
|
+
const schemaVars = schemaPaths.map((_, i) => `schema${i}`);
|
|
79
|
+
const mergeCode = `export const schemaString = [${schemaVars.join(", ")}].join('\\n\\n')
|
|
80
|
+
import { parse } from 'graphql'
|
|
81
|
+
export const typeDefs = parse(schemaString)
|
|
82
|
+
export const schemas = [${schemaVars.map((v) => `{ def: ${v} }`).join(", ")}]`;
|
|
83
|
+
return `${imports.join("\n")}\n\n${mergeCode}`;
|
|
84
|
+
}
|
|
85
|
+
const schemas = [...nitro.scanSchemas, ...nitro.options.graphql?.typedefs ?? []];
|
|
86
|
+
if (!schemas.length) {
|
|
87
|
+
if (nitro.options.dev) nitro.logger.warn("[nitro-graphql] No schemas found. Virtual module will export empty array.");
|
|
88
|
+
return "export const schemas = []";
|
|
89
|
+
}
|
|
90
|
+
const importStatements = schemas.map((s) => `import ${getImportId(s)} from '${s}';`);
|
|
91
|
+
const schemaArray = schemas.map((s) => `{ def: ${getImportId(s)} }`);
|
|
92
|
+
return `${importStatements.join("\n")}\n\nexport const schemas = [\n${schemaArray.join(",\n")}\n];`;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
const serverResolvers = {
|
|
96
|
+
id: "#nitro-graphql/server-resolvers",
|
|
97
|
+
getCode: (nitro) => {
|
|
98
|
+
const ext = normalizeExtendConfig(nitro.options.graphql?.extend);
|
|
99
|
+
const skipLocalScan = nitro.options.graphql?.skipLocalScan === true;
|
|
100
|
+
if (ext && ext.resolvers.length > 0) {
|
|
101
|
+
const resolverPaths = ext.resolvers.map((p) => resolveExtendPath(nitro, p));
|
|
102
|
+
const imports$1 = resolverPaths.map((p, i) => `import { resolvers as resolvers${i} } from '${p}'`);
|
|
103
|
+
if (!skipLocalScan && nitro.scanResolvers.length > 0) {
|
|
104
|
+
const scannedCode = generateImportModule(nitro.scanResolvers, "scannedResolvers", "resolver");
|
|
105
|
+
const spreadAll$1 = [...resolverPaths.map((_, i) => `...resolvers${i}`), "...scannedResolvers"];
|
|
106
|
+
return `${imports$1.join("\n")}
|
|
107
|
+
${scannedCode}
|
|
108
|
+
|
|
109
|
+
export const resolvers = [${spreadAll$1.join(", ")}]`;
|
|
110
|
+
}
|
|
111
|
+
if (resolverPaths.length === 1) return `export { resolvers } from '${resolverPaths[0]}'`;
|
|
112
|
+
const spreadAll = resolverPaths.map((_, i) => `...resolvers${i}`);
|
|
113
|
+
return `${imports$1.join("\n")}
|
|
114
|
+
|
|
115
|
+
export const resolvers = [${spreadAll.join(", ")}]`;
|
|
116
|
+
}
|
|
117
|
+
const imports = [...nitro.scanResolvers];
|
|
118
|
+
if (!imports.length) {
|
|
119
|
+
if (nitro.options.dev) nitro.logger.warn("[nitro-graphql] No resolvers found. Virtual module will export empty array.");
|
|
120
|
+
return "export const resolvers = []";
|
|
121
|
+
}
|
|
122
|
+
return generateImportModule(imports, "resolvers", "resolver");
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
const serverDirectives = {
|
|
126
|
+
id: "#nitro-graphql/server-directives",
|
|
127
|
+
getCode: (nitro) => {
|
|
128
|
+
const imports = nitro.scanDirectives || [];
|
|
129
|
+
if (!imports.length) return "export const directives = []";
|
|
130
|
+
return generateImportModule(imports, "directives", "directive");
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
const graphqlConfig = {
|
|
134
|
+
id: "#nitro-graphql/graphql-config",
|
|
135
|
+
getCode: (nitro) => {
|
|
136
|
+
return `import config from '${resolve(nitro.graphql.serverDir, "config.ts")}'
|
|
137
|
+
const importedConfig = config
|
|
138
|
+
export { importedConfig }
|
|
139
|
+
`;
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
const moduleConfig = {
|
|
143
|
+
id: "#nitro-graphql/module-config",
|
|
144
|
+
getCode: (nitro) => {
|
|
145
|
+
const config = nitro.options.graphql || {};
|
|
146
|
+
return `export const moduleConfig = ${JSON.stringify(config, null, 2)};`;
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
const debugInfo = {
|
|
150
|
+
id: "#nitro-graphql/debug-info",
|
|
151
|
+
getCode: (nitro) => {
|
|
152
|
+
const virtualModuleCodes = {
|
|
153
|
+
"server-schemas": safeGenerateModuleCode(nitro, "#nitro-graphql/server-schemas"),
|
|
154
|
+
"server-resolvers": safeGenerateModuleCode(nitro, "#nitro-graphql/server-resolvers"),
|
|
155
|
+
"server-directives": safeGenerateModuleCode(nitro, "#nitro-graphql/server-directives"),
|
|
156
|
+
"module-config": safeGenerateModuleCode(nitro, "#nitro-graphql/module-config"),
|
|
157
|
+
"graphql-config": safeGenerateModuleCode(nitro, "#nitro-graphql/graphql-config")
|
|
158
|
+
};
|
|
159
|
+
const info = {
|
|
160
|
+
isDev: nitro.options.dev,
|
|
161
|
+
framework: nitro.options.framework.name,
|
|
162
|
+
graphqlFramework: nitro.options.graphql?.framework,
|
|
163
|
+
federation: nitro.options.graphql?.federation,
|
|
164
|
+
scanned: {
|
|
165
|
+
schemas: nitro.scanSchemas?.length || 0,
|
|
166
|
+
schemaFiles: nitro.scanSchemas || [],
|
|
167
|
+
resolvers: nitro.scanResolvers?.length || 0,
|
|
168
|
+
resolverFiles: nitro.scanResolvers || [],
|
|
169
|
+
directives: nitro.scanDirectives?.length || 0,
|
|
170
|
+
directiveFiles: nitro.scanDirectives || [],
|
|
171
|
+
documents: nitro.scanDocuments?.length || 0,
|
|
172
|
+
documentFiles: nitro.scanDocuments || []
|
|
173
|
+
},
|
|
174
|
+
virtualModules: virtualModuleCodes
|
|
175
|
+
};
|
|
176
|
+
return `export const debugInfo = ${JSON.stringify(info, null, 2)};`;
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
const allModules = [
|
|
180
|
+
serverSchemas,
|
|
181
|
+
serverResolvers,
|
|
182
|
+
serverDirectives,
|
|
183
|
+
graphqlConfig,
|
|
184
|
+
moduleConfig,
|
|
185
|
+
debugInfo
|
|
186
|
+
];
|
|
187
|
+
function registerAllVirtualModules(nitro) {
|
|
188
|
+
nitro.options.virtual ??= {};
|
|
189
|
+
for (const mod of allModules) nitro.options.virtual[mod.id] = () => mod.getCode(nitro);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
//#endregion
|
|
193
|
+
export { debugInfo, graphqlConfig, moduleConfig, registerAllVirtualModules, serverDirectives, serverResolvers, serverSchemas };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/nitro/virtual/stubs.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Virtual module stubs for #nitro-graphql/*
|
|
4
|
+
* Used during build to prevent import resolution errors.
|
|
5
|
+
* At runtime, Nitro overrides these with actual virtual modules.
|
|
6
|
+
*/
|
|
7
|
+
declare const schemas: Array<{
|
|
8
|
+
def: string;
|
|
9
|
+
}>;
|
|
10
|
+
declare const resolvers: Array<{
|
|
11
|
+
resolver: any;
|
|
12
|
+
}>;
|
|
13
|
+
declare const directives: Array<{
|
|
14
|
+
directive: any;
|
|
15
|
+
}>;
|
|
16
|
+
declare const moduleConfig: {};
|
|
17
|
+
declare const importedConfig: {};
|
|
18
|
+
declare const debugInfo: Record<string, any>;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { debugInfo, directives, importedConfig, moduleConfig, resolvers, schemas };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//#region src/nitro/virtual/stubs.ts
|
|
2
|
+
/**
|
|
3
|
+
* Virtual module stubs for #nitro-graphql/*
|
|
4
|
+
* Used during build to prevent import resolution errors.
|
|
5
|
+
* At runtime, Nitro overrides these with actual virtual modules.
|
|
6
|
+
*/
|
|
7
|
+
const schemas = [];
|
|
8
|
+
const resolvers = [];
|
|
9
|
+
const directives = [];
|
|
10
|
+
const moduleConfig = {};
|
|
11
|
+
const importedConfig = {};
|
|
12
|
+
const debugInfo = {
|
|
13
|
+
isDev: false,
|
|
14
|
+
framework: "",
|
|
15
|
+
graphqlFramework: "",
|
|
16
|
+
federation: {},
|
|
17
|
+
scanned: {
|
|
18
|
+
schemas: 0,
|
|
19
|
+
schemaFiles: [],
|
|
20
|
+
resolvers: 0,
|
|
21
|
+
resolverFiles: [],
|
|
22
|
+
directives: 0,
|
|
23
|
+
directiveFiles: [],
|
|
24
|
+
documents: 0,
|
|
25
|
+
documentFiles: []
|
|
26
|
+
},
|
|
27
|
+
virtualModules: {}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
export { debugInfo, directives, importedConfig, moduleConfig, resolvers, schemas };
|
package/dist/nuxt.mjs
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { getDefaultPaths, getTypesConfig, resolveFilePath } from "./nitro/paths.mjs";
|
|
2
|
+
import { dirname, join, relative, resolve } from "pathe";
|
|
3
|
+
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { defineNuxtModule, getLayerDirectories } from "@nuxt/kit";
|
|
5
|
+
|
|
6
|
+
//#region src/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
|
+
if (options.tsConfig.compilerOptions) options.tsConfig.compilerOptions.paths[`#graphql/client/${service.name}`] = [relativePath];
|
|
50
|
+
if (options.tsConfig.include) 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 };
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
//#region src/
|
|
1
|
+
//#region src/stubs/index.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Runtime type stubs for GraphQL types
|
|
4
|
+
* These interfaces are replaced by generated types at build time
|
|
5
|
+
*/
|
|
2
6
|
interface StandardSchemaV1 extends Record<string, any> {}
|
|
3
7
|
interface ResolversTypes extends Record<string, any> {}
|
|
4
8
|
interface Resolvers extends Record<string, any> {}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/package.json
CHANGED
|
@@ -1,127 +1,137 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nitro-graphql",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.40",
|
|
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": {
|
|
10
|
-
"types": "./dist/
|
|
11
|
-
"import": "./dist/
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
"exports": {
|
|
15
|
-
".": {
|
|
16
|
-
"types": "./dist/index.d.ts",
|
|
17
|
-
"import": "./dist/index.js"
|
|
14
|
+
"types": "./dist/stubs/index.d.mts",
|
|
15
|
+
"import": "./dist/stubs/index.mjs"
|
|
18
16
|
},
|
|
19
|
-
"
|
|
20
|
-
"types": "./dist/
|
|
21
|
-
"import": "./dist/
|
|
17
|
+
"#nitro-graphql/graphql-config": {
|
|
18
|
+
"types": "./dist/nitro/virtual/stubs.d.mts",
|
|
19
|
+
"import": "./dist/nitro/virtual/stubs.mjs"
|
|
22
20
|
},
|
|
23
|
-
"
|
|
24
|
-
"types": "./dist/
|
|
25
|
-
"import": "./dist/
|
|
21
|
+
"#nitro-graphql/server-schemas": {
|
|
22
|
+
"types": "./dist/nitro/virtual/stubs.d.mts",
|
|
23
|
+
"import": "./dist/nitro/virtual/stubs.mjs"
|
|
26
24
|
},
|
|
27
|
-
"
|
|
28
|
-
"types": "./dist/
|
|
29
|
-
"import": "./dist/
|
|
25
|
+
"#nitro-graphql/server-resolvers": {
|
|
26
|
+
"types": "./dist/nitro/virtual/stubs.d.mts",
|
|
27
|
+
"import": "./dist/nitro/virtual/stubs.mjs"
|
|
30
28
|
},
|
|
31
|
-
"
|
|
32
|
-
"types": "./dist/
|
|
33
|
-
"import": "./dist/
|
|
29
|
+
"#nitro-graphql/server-directives": {
|
|
30
|
+
"types": "./dist/nitro/virtual/stubs.d.mts",
|
|
31
|
+
"import": "./dist/nitro/virtual/stubs.mjs"
|
|
34
32
|
},
|
|
35
|
-
"
|
|
36
|
-
"types": "./dist/
|
|
37
|
-
"import": "./dist/
|
|
33
|
+
"#nitro-graphql/module-config": {
|
|
34
|
+
"types": "./dist/nitro/virtual/stubs.d.mts",
|
|
35
|
+
"import": "./dist/nitro/virtual/stubs.mjs"
|
|
38
36
|
},
|
|
39
|
-
"
|
|
40
|
-
"types": "./dist/
|
|
41
|
-
"import": "./dist/
|
|
37
|
+
"#nitro-graphql/debug-info": {
|
|
38
|
+
"types": "./dist/nitro/virtual/stubs.d.mts",
|
|
39
|
+
"import": "./dist/nitro/virtual/stubs.mjs"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"exports": {
|
|
43
|
+
".": {
|
|
44
|
+
"types": "./dist/index.d.mts",
|
|
45
|
+
"import": "./dist/index.mjs"
|
|
42
46
|
},
|
|
43
|
-
"./
|
|
44
|
-
"types": "./dist/
|
|
45
|
-
"import": "./dist/
|
|
47
|
+
"./core": {
|
|
48
|
+
"types": "./dist/core/index.d.mts",
|
|
49
|
+
"import": "./dist/core/index.mjs"
|
|
46
50
|
},
|
|
47
|
-
"./
|
|
48
|
-
"types": "./dist/
|
|
49
|
-
"import": "./dist/
|
|
51
|
+
"./cli": {
|
|
52
|
+
"types": "./dist/cli/index.d.mts",
|
|
53
|
+
"import": "./dist/cli/index.mjs"
|
|
50
54
|
},
|
|
51
|
-
"./
|
|
52
|
-
"types": "./dist/
|
|
53
|
-
"import": "./dist/
|
|
55
|
+
"./define": {
|
|
56
|
+
"types": "./dist/define.d.mts",
|
|
57
|
+
"import": "./dist/define.mjs"
|
|
58
|
+
},
|
|
59
|
+
"./apollo": {
|
|
60
|
+
"types": "./dist/nitro/apollo.d.mts",
|
|
61
|
+
"import": "./dist/nitro/apollo.mjs"
|
|
54
62
|
},
|
|
55
|
-
"./
|
|
56
|
-
"types": "./dist/
|
|
57
|
-
"import": "./dist/
|
|
63
|
+
"./nuxt": {
|
|
64
|
+
"types": "./dist/nuxt.d.mts",
|
|
65
|
+
"import": "./dist/nuxt.mjs"
|
|
58
66
|
}
|
|
59
67
|
},
|
|
60
|
-
"module": "./dist/index.
|
|
61
|
-
"types": "./dist/index.d.
|
|
68
|
+
"module": "./dist/index.mjs",
|
|
69
|
+
"types": "./dist/index.d.mts",
|
|
70
|
+
"bin": {
|
|
71
|
+
"nitro-graphql": "./dist/cli/index.mjs"
|
|
72
|
+
},
|
|
62
73
|
"files": [
|
|
63
74
|
"dist"
|
|
64
75
|
],
|
|
65
76
|
"peerDependencies": {
|
|
66
77
|
"@apollo/server": "^5.0.0",
|
|
67
|
-
"@apollo/utils.withrequired": "^3.0.0",
|
|
68
|
-
"@as-integrations/h3": "^2.0.0",
|
|
69
78
|
"graphql": "^16.11.0",
|
|
70
|
-
"h3": "^2.0.1-rc.2",
|
|
71
79
|
"nitro": "^3.0.1-alpha.0"
|
|
72
80
|
},
|
|
73
81
|
"peerDependenciesMeta": {
|
|
74
82
|
"@apollo/server": {
|
|
75
83
|
"optional": true
|
|
76
|
-
},
|
|
77
|
-
"@apollo/utils.withrequired": {
|
|
78
|
-
"optional": true
|
|
79
|
-
},
|
|
80
|
-
"@as-integrations/h3": {
|
|
81
|
-
"optional": true
|
|
82
84
|
}
|
|
83
85
|
},
|
|
84
86
|
"dependencies": {
|
|
85
|
-
"@apollo/subgraph": "^2.
|
|
87
|
+
"@apollo/subgraph": "^2.12.2",
|
|
88
|
+
"@bomb.sh/tab": "^0.0.11",
|
|
86
89
|
"@graphql-codegen/core": "^5.0.0",
|
|
87
90
|
"@graphql-codegen/import-types-preset": "^3.0.1",
|
|
88
|
-
"@graphql-codegen/
|
|
91
|
+
"@graphql-codegen/typed-document-node": "^6.1.5",
|
|
92
|
+
"@graphql-codegen/typescript": "^5.0.7",
|
|
89
93
|
"@graphql-codegen/typescript-generic-sdk": "^4.0.2",
|
|
90
|
-
"@graphql-codegen/typescript-operations": "^5.0.
|
|
91
|
-
"@graphql-codegen/typescript-resolvers": "^5.1.
|
|
92
|
-
"@graphql-tools/graphql-file-loader": "^8.1.
|
|
93
|
-
"@graphql-tools/load": "^8.1.
|
|
94
|
+
"@graphql-codegen/typescript-operations": "^5.0.7",
|
|
95
|
+
"@graphql-codegen/typescript-resolvers": "^5.1.5",
|
|
96
|
+
"@graphql-tools/graphql-file-loader": "^8.1.8",
|
|
97
|
+
"@graphql-tools/load": "^8.1.7",
|
|
94
98
|
"@graphql-tools/load-files": "^7.0.1",
|
|
95
|
-
"@graphql-tools/merge": "^9.1.
|
|
96
|
-
"@graphql-tools/schema": "^10.0.
|
|
97
|
-
"@graphql-tools/url-loader": "^9.0.
|
|
98
|
-
"@graphql-tools/utils": "^10.
|
|
99
|
-
"chokidar": "^
|
|
99
|
+
"@graphql-tools/merge": "^9.1.6",
|
|
100
|
+
"@graphql-tools/schema": "^10.0.30",
|
|
101
|
+
"@graphql-tools/url-loader": "^9.0.5",
|
|
102
|
+
"@graphql-tools/utils": "^10.11.0",
|
|
103
|
+
"chokidar": "^5.0.0",
|
|
104
|
+
"citty": "^0.1.6",
|
|
100
105
|
"consola": "^3.4.2",
|
|
101
106
|
"defu": "^6.1.4",
|
|
107
|
+
"giget": "^2.0.0",
|
|
102
108
|
"graphql-config": "^5.1.5",
|
|
103
109
|
"graphql-scalars": "^1.25.0",
|
|
104
|
-
"knitwork": "^1.
|
|
110
|
+
"knitwork": "^1.3.0",
|
|
105
111
|
"ohash": "^2.0.11",
|
|
106
|
-
"oxc-parser": "^0.
|
|
112
|
+
"oxc-parser": "^0.106.0",
|
|
107
113
|
"pathe": "^2.0.3",
|
|
108
114
|
"tinyglobby": "^0.2.15"
|
|
109
115
|
},
|
|
110
116
|
"devDependencies": {
|
|
111
|
-
"@antfu/eslint-config": "^6.
|
|
112
|
-
"@nuxt/kit": "^4.
|
|
113
|
-
"@nuxt/schema": "^4.
|
|
114
|
-
"@types/node": "^
|
|
115
|
-
"
|
|
117
|
+
"@antfu/eslint-config": "^6.7.3",
|
|
118
|
+
"@nuxt/kit": "^4.2.2",
|
|
119
|
+
"@nuxt/schema": "^4.2.2",
|
|
120
|
+
"@types/node": "^25.0.3",
|
|
121
|
+
"@vitejs/devtools": "^0.0.0-alpha.16",
|
|
122
|
+
"@vitest/ui": "^4.0.16",
|
|
123
|
+
"bumpp": "^10.3.2",
|
|
116
124
|
"changelogen": "^0.6.2",
|
|
117
|
-
"crossws": "0.
|
|
118
|
-
"eslint": "^9.
|
|
119
|
-
"graphql": "16.
|
|
120
|
-
"graphql-yoga": "
|
|
121
|
-
"
|
|
122
|
-
"
|
|
123
|
-
"
|
|
124
|
-
"
|
|
125
|
+
"crossws": "^0.4.1",
|
|
126
|
+
"eslint": "^9.39.2",
|
|
127
|
+
"graphql": "16.12.0",
|
|
128
|
+
"graphql-yoga": "5.16.2",
|
|
129
|
+
"nitro": "3.0.1-alpha.1",
|
|
130
|
+
"tsdown": "^0.18.4",
|
|
131
|
+
"typescript": "^5.9.3",
|
|
132
|
+
"vite": "8.0.0-beta.5",
|
|
133
|
+
"vitepress-plugin-llms": "^1.10.0",
|
|
134
|
+
"vitest": "^4.0.16"
|
|
125
135
|
},
|
|
126
136
|
"resolutions": {
|
|
127
137
|
"nitro-graphql": "link:."
|
|
@@ -130,11 +140,20 @@
|
|
|
130
140
|
"build": "tsdown",
|
|
131
141
|
"dev": "tsdown --watch",
|
|
132
142
|
"bumpp": "bumpp package.json",
|
|
133
|
-
"release": "pnpm build && pnpm bumpp
|
|
143
|
+
"release": "pnpm build && pnpm bumpp",
|
|
134
144
|
"playground:nitro": "cd playgrounds/nitro && pnpm install && pnpm dev",
|
|
135
145
|
"playground:nuxt": "cd playgrounds/nuxt && pnpm install && pnpm dev",
|
|
136
146
|
"playground:federation": "cd playgrounds/federation && pnpm install && pnpm dev",
|
|
147
|
+
"docs:dev": "cd .docs && pnpm install && pnpm update:metadata && pnpm dev",
|
|
148
|
+
"docs:build": "cd .docs && pnpm install && pnpm update:metadata && pnpm build",
|
|
149
|
+
"docs:preview": "cd .docs && pnpm preview",
|
|
150
|
+
"cli": "node ./dist/cli/index.mjs",
|
|
137
151
|
"lint": "eslint .",
|
|
138
|
-
"lint:fix": "eslint . --fix"
|
|
152
|
+
"lint:fix": "eslint . --fix",
|
|
153
|
+
"test": "vitest",
|
|
154
|
+
"test:ui": "vitest --ui",
|
|
155
|
+
"test:run": "vitest run",
|
|
156
|
+
"test:coverage": "vitest run --coverage",
|
|
157
|
+
"test:types": "tsc --noEmit"
|
|
139
158
|
}
|
|
140
159
|
}
|