nitro-graphql 1.5.6 → 2.0.0-beta.10
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 +29 -1
- package/dist/ecosystem/nuxt.js +13 -55
- package/dist/index.d.ts +2 -2
- package/dist/index.js +43 -48
- package/dist/rollup.js +84 -52
- package/dist/routes/apollo-server.d.ts +2 -2
- package/dist/routes/apollo-server.js +5 -5
- package/dist/routes/debug.d.ts +5 -5
- package/dist/routes/debug.js +6 -6
- package/dist/routes/graphql-yoga.d.ts +1 -1
- package/dist/routes/graphql-yoga.js +7 -8
- package/dist/routes/health.d.ts +1 -1
- package/dist/routes/health.js +6 -4
- package/dist/types/index.d.ts +2 -2
- package/dist/types/standard-schema.d.ts +2 -2
- package/dist/utils/client-codegen.d.ts +2 -2
- package/dist/utils/client-codegen.js +4 -4
- package/dist/utils/directive-parser.js +3 -7
- package/dist/utils/index.d.ts +3 -4
- package/dist/utils/index.js +47 -26
- package/dist/utils/path-resolver.js +2 -2
- package/dist/utils/type-generation.d.ts +1 -1
- package/dist/utils/type-generation.js +2 -1
- package/dist/virtual/debug-info.d.ts +9 -0
- package/dist/virtual/debug-info.js +26 -0
- package/dist/virtual/graphql-config.d.ts +9 -0
- package/dist/virtual/graphql-config.js +10 -0
- package/dist/virtual/module-config.d.ts +9 -0
- package/dist/virtual/module-config.js +10 -0
- package/dist/virtual/server-directives.d.ts +11 -0
- package/dist/virtual/server-directives.js +10 -0
- package/dist/virtual/server-resolvers.d.ts +11 -0
- package/dist/virtual/server-resolvers.js +10 -0
- package/dist/virtual/server-schemas.d.ts +11 -0
- package/dist/virtual/server-schemas.js +10 -0
- package/dist/vite.d.ts +25 -0
- package/dist/vite.js +40 -0
- package/package.json +46 -18
package/README.md
CHANGED
|
@@ -55,7 +55,7 @@ pnpm add nitro-graphql @apollo/server @apollo/utils.withrequired @as-integration
|
|
|
55
55
|
|
|
56
56
|
```ts
|
|
57
57
|
// nitro.config.ts
|
|
58
|
-
import { defineNitroConfig } from '
|
|
58
|
+
import { defineNitroConfig } from 'nitro/config'
|
|
59
59
|
|
|
60
60
|
export default defineNitroConfig({
|
|
61
61
|
modules: ['nitro-graphql'],
|
|
@@ -67,6 +67,33 @@ export default defineNitroConfig({
|
|
|
67
67
|
|
|
68
68
|
</details>
|
|
69
69
|
|
|
70
|
+
<details>
|
|
71
|
+
<summary>⚡ <strong>Vite + Nitro Project</strong></summary>
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
// vite.config.ts
|
|
75
|
+
import { defineConfig } from 'vite'
|
|
76
|
+
import { nitro } from 'nitro/vite'
|
|
77
|
+
import { graphql } from 'nitro-graphql/vite'
|
|
78
|
+
|
|
79
|
+
export default defineConfig({
|
|
80
|
+
plugins: [
|
|
81
|
+
graphql(), // ⚠️ Must be before nitro()
|
|
82
|
+
nitro(),
|
|
83
|
+
],
|
|
84
|
+
nitro: {
|
|
85
|
+
modules: ['nitro-graphql'],
|
|
86
|
+
graphql: {
|
|
87
|
+
framework: 'graphql-yoga',
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
})
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
> **⚠️ Important**: The `graphql()` plugin must be placed **before** `nitro()` to prevent Vite from trying to parse GraphQL files as JavaScript.
|
|
94
|
+
|
|
95
|
+
</details>
|
|
96
|
+
|
|
70
97
|
<details>
|
|
71
98
|
<summary>🟢 <strong>Nuxt Project</strong></summary>
|
|
72
99
|
|
|
@@ -128,6 +155,7 @@ Try these working examples:
|
|
|
128
155
|
| Example | Description | Demo |
|
|
129
156
|
|---------|-------------|------|
|
|
130
157
|
| [**Nitro Basic**](./playgrounds/nitro/) | Standalone Nitro with GraphQL | `pnpm playground:nitro` |
|
|
158
|
+
| [**Vite + Nitro**](./playgrounds/vite/) | Vite with Nitro GraphQL integration | `cd playgrounds/vite && pnpm dev` |
|
|
131
159
|
| [**Nuxt Integration**](./playgrounds/nuxt/) | Full Nuxt app with client types | `pnpm playground:nuxt` |
|
|
132
160
|
| [**Apollo Federation**](./playgrounds/federation/) | Federated GraphQL services | `pnpm playground:federation` |
|
|
133
161
|
|
package/dist/ecosystem/nuxt.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { getDefaultPaths, getTypesConfig, resolveFilePath } from "../utils/path-resolver.js";
|
|
2
1
|
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
3
|
-
import {
|
|
2
|
+
import { join, resolve } from "pathe";
|
|
4
3
|
import { defineNuxtModule, getLayerDirectories } from "@nuxt/kit";
|
|
5
4
|
|
|
6
5
|
//#region src/ecosystem/nuxt.ts
|
|
@@ -12,65 +11,24 @@ var nuxt_default = defineNuxtModule({
|
|
|
12
11
|
},
|
|
13
12
|
setup: async (_options, nuxt) => {
|
|
14
13
|
nuxt.hooks.hook("prepare:types", (options) => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
}
|
|
14
|
+
options.references.push({ path: "types/nitro-graphql-client.d.ts" });
|
|
15
|
+
options.tsConfig ??= {};
|
|
16
|
+
options.tsConfig.compilerOptions ??= {};
|
|
17
|
+
options.tsConfig.compilerOptions.paths ??= {};
|
|
18
|
+
options.tsConfig.compilerOptions.paths["#graphql/client"] = ["./types/nitro-graphql-client.d.ts"];
|
|
39
19
|
const externalServices$1 = nuxt.options.nitro?.graphql?.externalServices || [];
|
|
40
20
|
for (const service of externalServices$1) {
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
}
|
|
21
|
+
options.references.push({ path: `types/nitro-graphql-client-${service.name}.d.ts` });
|
|
22
|
+
options.tsConfig.compilerOptions.paths[`#graphql/client/${service.name}`] = [`./types/nitro-graphql-client-${service.name}.d.ts`];
|
|
52
23
|
}
|
|
24
|
+
options.tsConfig.include = options.tsConfig.include || [];
|
|
25
|
+
options.tsConfig.include.push("./types/nitro-graphql-client.d.ts");
|
|
26
|
+
for (const service of externalServices$1) options.tsConfig.include.push(`./types/nitro-graphql-client-${service.name}.d.ts`);
|
|
53
27
|
});
|
|
54
28
|
nuxt.options.alias = nuxt.options.alias || {};
|
|
55
|
-
|
|
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;
|
|
29
|
+
nuxt.options.alias["#graphql/client"] = join(nuxt.options.buildDir, "types/nitro-graphql-client.d.ts");
|
|
65
30
|
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
|
-
}
|
|
31
|
+
for (const service of externalServices) nuxt.options.alias[`#graphql/client/${service.name}`] = join(nuxt.options.buildDir, `types/nitro-graphql-client-${service.name}.d.ts`);
|
|
74
32
|
nuxt.hook("imports:dirs", (dirs) => {
|
|
75
33
|
const graphqlServerPath = nuxt.options.nitro?.graphql?.serverDir || resolve(nuxt.options.srcDir, "graphql");
|
|
76
34
|
dirs.push(graphqlServerPath);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { StandardSchemaV1 } from "./types/standard-schema.js";
|
|
2
2
|
import { ClientUtilsConfig, CodegenClientConfig, CodegenServerConfig, ExternalGraphQLService, ExternalServicePaths, FederationConfig, FileGenerationConfig, GenImport, GenericSdkConfig, NitroGraphQLOptions, PathsConfig, ScaffoldConfig, SdkConfig, TypesConfig } from "./types/index.js";
|
|
3
|
-
import * as
|
|
3
|
+
import * as nitropack_types0 from "nitropack/types";
|
|
4
4
|
|
|
5
5
|
//#region src/index.d.ts
|
|
6
|
-
declare const _default:
|
|
6
|
+
declare const _default: nitropack_types0.NitroModule;
|
|
7
7
|
//#endregion
|
|
8
8
|
export { ClientUtilsConfig, CodegenClientConfig, CodegenServerConfig, ExternalGraphQLService, ExternalServicePaths, FederationConfig, FileGenerationConfig, GenImport, GenericSdkConfig, NitroGraphQLOptions, PathsConfig, ScaffoldConfig, SdkConfig, StandardSchemaV1, TypesConfig, _default as default };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { generateDirectiveSchemas } from "./utils/directive-parser.js";
|
|
2
2
|
import { generateLayerIgnorePatterns, getLayerAppDirectories, getLayerServerDirectories, relativeWithDot, scanDirectives, scanDocs, scanResolvers, scanSchemas, validateExternalServices } from "./utils/index.js";
|
|
3
3
|
import { writeFileIfNotExists } from "./utils/file-generator.js";
|
|
4
|
-
import {
|
|
4
|
+
import { getScaffoldConfig, resolveFilePath, shouldGenerateScaffold } from "./utils/path-resolver.js";
|
|
5
5
|
import { clientTypeGeneration, serverTypeGeneration } from "./utils/type-generation.js";
|
|
6
6
|
import { rollupConfig } from "./rollup.js";
|
|
7
7
|
import { existsSync, mkdirSync } from "node:fs";
|
|
@@ -9,7 +9,6 @@ import { fileURLToPath } from "node:url";
|
|
|
9
9
|
import { watch } from "chokidar";
|
|
10
10
|
import consola from "consola";
|
|
11
11
|
import defu from "defu";
|
|
12
|
-
import { defineNitroModule } from "nitropack/kit";
|
|
13
12
|
import { dirname, join, relative, resolve } from "pathe";
|
|
14
13
|
|
|
15
14
|
//#region src/index.ts
|
|
@@ -26,11 +25,13 @@ var src_default = defineNitroModule({
|
|
|
26
25
|
}
|
|
27
26
|
consola.info(`Configured ${nitro.options.graphql.externalServices.length} external GraphQL services`);
|
|
28
27
|
}
|
|
28
|
+
const { getDefaultPaths: getDefaultPaths$1 } = await import("./utils/path-resolver.js");
|
|
29
|
+
const defaultPaths = getDefaultPaths$1(nitro);
|
|
29
30
|
nitro.graphql ||= {
|
|
30
31
|
buildDir: "",
|
|
31
32
|
watchDirs: [],
|
|
32
|
-
clientDir:
|
|
33
|
-
serverDir:
|
|
33
|
+
clientDir: defaultPaths.clientGraphql,
|
|
34
|
+
serverDir: defaultPaths.serverGraphql,
|
|
34
35
|
dir: {
|
|
35
36
|
build: relative(nitro.options.rootDir, nitro.options.buildDir),
|
|
36
37
|
client: "graphql",
|
|
@@ -62,11 +63,8 @@ var src_default = defineNitroModule({
|
|
|
62
63
|
const watchDirs = [];
|
|
63
64
|
switch (nitro.options.framework.name) {
|
|
64
65
|
case "nuxt": {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
nitro.graphql.dir.client = "app/graphql";
|
|
68
|
-
}
|
|
69
|
-
if (!nitro.options.graphql?.serverDir) nitro.graphql.serverDir = resolve(nitro.options.rootDir, "server", "graphql");
|
|
66
|
+
nitro.graphql.dir.client = relative(nitro.options.rootDir, nitro.graphql.clientDir);
|
|
67
|
+
nitro.graphql.dir.server = relative(nitro.options.rootDir, nitro.graphql.serverDir);
|
|
70
68
|
watchDirs.push(nitro.graphql.clientDir);
|
|
71
69
|
const layerServerDirs = getLayerServerDirectories(nitro);
|
|
72
70
|
const layerAppDirs = getLayerAppDirectories(nitro);
|
|
@@ -75,8 +73,10 @@ var src_default = defineNitroModule({
|
|
|
75
73
|
break;
|
|
76
74
|
}
|
|
77
75
|
case "nitro":
|
|
78
|
-
nitro.graphql.
|
|
79
|
-
nitro.graphql.dir.
|
|
76
|
+
nitro.graphql.dir.client = relative(nitro.options.rootDir, nitro.graphql.clientDir);
|
|
77
|
+
nitro.graphql.dir.server = relative(nitro.options.rootDir, nitro.graphql.serverDir);
|
|
78
|
+
watchDirs.push(nitro.graphql.clientDir);
|
|
79
|
+
watchDirs.push(nitro.graphql.serverDir);
|
|
80
80
|
break;
|
|
81
81
|
default:
|
|
82
82
|
}
|
|
@@ -93,12 +93,17 @@ var src_default = defineNitroModule({
|
|
|
93
93
|
ignoreInitial: true,
|
|
94
94
|
ignored: [...nitro.options.ignore, ...generateLayerIgnorePatterns(nitro)]
|
|
95
95
|
}).on("all", async (_, path) => {
|
|
96
|
-
if (path.endsWith(".graphql") || path.endsWith(".gql"))
|
|
96
|
+
if (path.endsWith(".graphql") || path.endsWith(".gql")) if (path.includes(nitro.graphql.serverDir) || path.includes("server/graphql") || path.includes("server\\graphql")) {
|
|
97
|
+
await serverTypeGeneration(nitro);
|
|
98
|
+
await clientTypeGeneration(nitro);
|
|
99
|
+
await nitro.hooks.callHook("dev:reload");
|
|
100
|
+
} else await clientTypeGeneration(nitro);
|
|
97
101
|
});
|
|
98
102
|
nitro.hooks.hook("close", () => {
|
|
99
103
|
watcher.close();
|
|
100
104
|
});
|
|
101
105
|
const tsconfigDir = dirname(resolve(nitro.options.buildDir, nitro.options.typescript.tsconfigPath));
|
|
106
|
+
const typesDir = resolve(nitro.options.buildDir, "types");
|
|
102
107
|
nitro.scanSchemas = await scanSchemas(nitro);
|
|
103
108
|
nitro.scanDocuments = await scanDocs(nitro);
|
|
104
109
|
nitro.scanResolvers = await scanResolvers(nitro);
|
|
@@ -163,9 +168,9 @@ var src_default = defineNitroModule({
|
|
|
163
168
|
});
|
|
164
169
|
const runtime = fileURLToPath(new URL("routes", import.meta.url));
|
|
165
170
|
const methods = [
|
|
166
|
-
"
|
|
167
|
-
"
|
|
168
|
-
"
|
|
171
|
+
"GET",
|
|
172
|
+
"POST",
|
|
173
|
+
"OPTIONS"
|
|
169
174
|
];
|
|
170
175
|
if (nitro.options.graphql?.framework === "graphql-yoga") for (const method of methods) nitro.options.handlers.push({
|
|
171
176
|
route: nitro.options.runtimeConfig.graphql?.endpoint?.graphql || "/api/graphql",
|
|
@@ -180,13 +185,13 @@ var src_default = defineNitroModule({
|
|
|
180
185
|
nitro.options.handlers.push({
|
|
181
186
|
route: nitro.options.runtimeConfig.graphql?.endpoint?.healthCheck || "/api/graphql/health",
|
|
182
187
|
handler: join(runtime, "health"),
|
|
183
|
-
method: "
|
|
188
|
+
method: "GET"
|
|
184
189
|
});
|
|
185
190
|
if (nitro.options.dev) {
|
|
186
191
|
nitro.options.handlers.push({
|
|
187
192
|
route: "/_nitro/graphql/debug",
|
|
188
193
|
handler: join(runtime, "debug"),
|
|
189
|
-
method: "
|
|
194
|
+
method: "GET"
|
|
190
195
|
});
|
|
191
196
|
consola.info("[nitro-graphql] Debug dashboard available at: /_nitro/graphql/debug");
|
|
192
197
|
}
|
|
@@ -209,11 +214,20 @@ var src_default = defineNitroModule({
|
|
|
209
214
|
nitro.hooks.hook("rollup:before", (_, rollupConfig$1) => {
|
|
210
215
|
const manualChunks = rollupConfig$1.output?.manualChunks;
|
|
211
216
|
const chunkFiles = rollupConfig$1.output?.chunkFileNames;
|
|
212
|
-
if (!rollupConfig$1.output.inlineDynamicImports)
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
+
if (!rollupConfig$1.output.inlineDynamicImports) {
|
|
218
|
+
rollupConfig$1.output.advancedChunks = { groups: [{
|
|
219
|
+
name: "schemas",
|
|
220
|
+
test: /\.(?:graphql|gql)$/
|
|
221
|
+
}, {
|
|
222
|
+
name: "resolvers",
|
|
223
|
+
test: /\.resolver\.ts$/
|
|
224
|
+
}] };
|
|
225
|
+
rollupConfig$1.output.manualChunks = (id, meta) => {
|
|
226
|
+
if (id.endsWith(".graphql") || id.endsWith(".gql")) return "schemas";
|
|
227
|
+
if (id.endsWith(".resolver.ts")) return "resolvers";
|
|
228
|
+
if (typeof manualChunks === "function") return manualChunks(id, meta);
|
|
229
|
+
};
|
|
230
|
+
}
|
|
217
231
|
rollupConfig$1.output.chunkFileNames = (chunkInfo) => {
|
|
218
232
|
if (chunkInfo.moduleIds && chunkInfo.moduleIds.some((id) => id.endsWith(".graphql") || id.endsWith(".resolver.ts") || id.endsWith(".gql"))) return `chunks/graphql/[name].mjs`;
|
|
219
233
|
if (typeof chunkFiles === "function") return chunkFiles(chunkInfo);
|
|
@@ -225,40 +239,20 @@ var src_default = defineNitroModule({
|
|
|
225
239
|
types.tsConfig ||= {};
|
|
226
240
|
types.tsConfig.compilerOptions ??= {};
|
|
227
241
|
types.tsConfig.compilerOptions.paths ??= {};
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
const serverTypesPath = resolveFilePath(typesConfig.server, typesConfig.enabled, true, "{typesDir}/nitro-graphql-server.d.ts", placeholders);
|
|
231
|
-
if (serverTypesPath) types.tsConfig.compilerOptions.paths["#graphql/server"] = [relativeWithDot(tsconfigDir, serverTypesPath)];
|
|
232
|
-
const clientTypesPath = resolveFilePath(typesConfig.client, typesConfig.enabled, true, "{typesDir}/nitro-graphql-client.d.ts", placeholders);
|
|
233
|
-
if (clientTypesPath) types.tsConfig.compilerOptions.paths["#graphql/client"] = [relativeWithDot(tsconfigDir, clientTypesPath)];
|
|
242
|
+
types.tsConfig.compilerOptions.paths["#graphql/server"] = [relativeWithDot(tsconfigDir, join(typesDir, "nitro-graphql-server.d.ts"))];
|
|
243
|
+
types.tsConfig.compilerOptions.paths["#graphql/client"] = [relativeWithDot(tsconfigDir, join(typesDir, "nitro-graphql-client.d.ts"))];
|
|
234
244
|
types.tsConfig.compilerOptions.paths["#graphql/schema"] = [relativeWithDot(tsconfigDir, join(nitro.graphql.serverDir, "schema.ts"))];
|
|
235
|
-
if (nitro.options.graphql?.externalServices?.length) for (const service of nitro.options.graphql.externalServices) {
|
|
236
|
-
const servicePlaceholders = {
|
|
237
|
-
...placeholders,
|
|
238
|
-
serviceName: service.name
|
|
239
|
-
};
|
|
240
|
-
const externalTypesPath = resolveFilePath(service.paths?.types ?? typesConfig.external, typesConfig.enabled, true, "{typesDir}/nitro-graphql-client-{serviceName}.d.ts", servicePlaceholders);
|
|
241
|
-
if (externalTypesPath) types.tsConfig.compilerOptions.paths[`#graphql/client/${service.name}`] = [relativeWithDot(tsconfigDir, externalTypesPath)];
|
|
242
|
-
}
|
|
245
|
+
if (nitro.options.graphql?.externalServices?.length) for (const service of nitro.options.graphql.externalServices) types.tsConfig.compilerOptions.paths[`#graphql/client/${service.name}`] = [relativeWithDot(tsconfigDir, join(typesDir, `nitro-graphql-client-${service.name}.d.ts`))];
|
|
243
246
|
types.tsConfig.include = types.tsConfig.include || [];
|
|
244
|
-
|
|
245
|
-
if (
|
|
246
|
-
types.tsConfig.include.push(relativeWithDot(tsconfigDir, join(placeholders.typesDir, "graphql.d.ts")));
|
|
247
|
-
if (nitro.options.graphql?.externalServices?.length) for (const service of nitro.options.graphql.externalServices) {
|
|
248
|
-
const servicePlaceholders = {
|
|
249
|
-
...placeholders,
|
|
250
|
-
serviceName: service.name
|
|
251
|
-
};
|
|
252
|
-
const externalTypesPath = resolveFilePath(service.paths?.types ?? typesConfig.external, typesConfig.enabled, true, "{typesDir}/nitro-graphql-client-{serviceName}.d.ts", servicePlaceholders);
|
|
253
|
-
if (externalTypesPath) types.tsConfig.include.push(relativeWithDot(tsconfigDir, externalTypesPath));
|
|
254
|
-
}
|
|
247
|
+
types.tsConfig.include.push(relativeWithDot(tsconfigDir, join(typesDir, "nitro-graphql-server.d.ts")), relativeWithDot(tsconfigDir, join(typesDir, "nitro-graphql-client.d.ts")), relativeWithDot(tsconfigDir, join(typesDir, "graphql.d.ts")));
|
|
248
|
+
if (nitro.options.graphql?.externalServices?.length) for (const service of nitro.options.graphql.externalServices) types.tsConfig.include.push(relativeWithDot(tsconfigDir, join(typesDir, `nitro-graphql-client-${service.name}.d.ts`)));
|
|
255
249
|
});
|
|
256
250
|
if (nitro.options.framework?.name === "nuxt" && nitro.options.graphql?.externalServices?.length) nitro.hooks.hook("build:before", () => {
|
|
257
251
|
const nuxtOptions = nitro._nuxt?.options;
|
|
258
252
|
if (nuxtOptions) nuxtOptions.nitroGraphqlExternalServices = nitro.options.graphql?.externalServices || [];
|
|
259
253
|
});
|
|
260
254
|
if (shouldGenerateScaffold(nitro)) {
|
|
261
|
-
const placeholders = getDefaultPaths(nitro);
|
|
255
|
+
const placeholders = getDefaultPaths$1(nitro);
|
|
262
256
|
const scaffoldConfig = getScaffoldConfig(nitro);
|
|
263
257
|
const graphqlConfigPath = resolveFilePath(scaffoldConfig.graphqlConfig, scaffoldConfig.enabled, true, "graphql.config.ts", placeholders);
|
|
264
258
|
if (graphqlConfigPath) writeFileIfNotExists(graphqlConfigPath, `
|
|
@@ -289,6 +283,7 @@ export default <IGraphQLConfig> {
|
|
|
289
283
|
if (serverConfigPath) writeFileIfNotExists(serverConfigPath, `// Example GraphQL config file please change it to your needs
|
|
290
284
|
// import * as tables from '../drizzle/schema/index'
|
|
291
285
|
// import { useDatabase } from '../utils/useDb'
|
|
286
|
+
import { defineGraphQLConfig } from 'nitro-graphql/utils/define'
|
|
292
287
|
|
|
293
288
|
export default defineGraphQLConfig({
|
|
294
289
|
// graphql-yoga example config
|
package/dist/rollup.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { getImportId, scanGraphql } from "./utils/index.js";
|
|
2
2
|
import { clientTypeGeneration, serverTypeGeneration } from "./utils/type-generation.js";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
3
4
|
import { resolve } from "pathe";
|
|
4
5
|
import { readFile } from "node:fs/promises";
|
|
5
6
|
import { parse } from "graphql";
|
|
@@ -15,30 +16,79 @@ async function rollupConfig(app) {
|
|
|
15
16
|
virtualDebugInfo(app);
|
|
16
17
|
app.hooks.hook("rollup:before", (nitro, rollupConfig$1) => {
|
|
17
18
|
rollupConfig$1.plugins = rollupConfig$1.plugins || [];
|
|
18
|
-
const { include = /\.(graphql|gql)$/i, exclude, validate = false } = app.options.graphql?.loader || {};
|
|
19
|
+
const { include = /\.(?:graphql|gql)$/i, exclude, validate = false } = app.options.graphql?.loader || {};
|
|
19
20
|
if (Array.isArray(rollupConfig$1.plugins)) {
|
|
20
21
|
rollupConfig$1.plugins.push({
|
|
21
|
-
name: "nitro-graphql",
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if (
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
+
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: 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
|
+
}
|
|
33
56
|
}
|
|
34
57
|
}
|
|
35
58
|
});
|
|
36
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({
|
|
37
85
|
name: "nitro-graphql-watcher",
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
86
|
+
buildStart: {
|
|
87
|
+
order: "pre",
|
|
88
|
+
async handler() {
|
|
89
|
+
const graphqlFiles = await scanGraphql(nitro);
|
|
90
|
+
for (const file of graphqlFiles) this.addWatchFile(file);
|
|
91
|
+
}
|
|
42
92
|
}
|
|
43
93
|
});
|
|
44
94
|
}
|
|
@@ -49,11 +99,9 @@ async function rollupConfig(app) {
|
|
|
49
99
|
});
|
|
50
100
|
}
|
|
51
101
|
function virtualSchemas(app) {
|
|
52
|
-
const getSchemas = () =>
|
|
53
|
-
return [...app.scanSchemas, ...app.options.graphql?.typedefs ?? []];
|
|
54
|
-
};
|
|
102
|
+
const getSchemas = () => [...app.scanSchemas, ...app.options.graphql?.typedefs ?? []];
|
|
55
103
|
app.options.virtual ??= {};
|
|
56
|
-
app.options.virtual["#nitro-
|
|
104
|
+
app.options.virtual["#nitro-graphql/server-schemas"] = () => {
|
|
57
105
|
try {
|
|
58
106
|
const imports = getSchemas();
|
|
59
107
|
if (imports.length === 0) {
|
|
@@ -62,15 +110,13 @@ function virtualSchemas(app) {
|
|
|
62
110
|
}
|
|
63
111
|
const importStatements = imports.map((handler) => `import ${getImportId(handler)} from '${handler}';`);
|
|
64
112
|
const schemaArray = imports.map((h) => `{ def: ${getImportId(h)} }`);
|
|
65
|
-
|
|
113
|
+
return `
|
|
66
114
|
${importStatements.join("\n")}
|
|
67
115
|
|
|
68
116
|
export const schemas = [
|
|
69
117
|
${schemaArray.join(",\n")}
|
|
70
118
|
];
|
|
71
119
|
`;
|
|
72
|
-
if (app.options.dev) app.logger.success(`[nitro-graphql] Generated virtual schema module: ${imports.length} schema(s)`);
|
|
73
|
-
return code;
|
|
74
120
|
} catch (error) {
|
|
75
121
|
app.logger.error("[nitro-graphql] Failed to generate virtual schema module:", error);
|
|
76
122
|
return "export const schemas = []";
|
|
@@ -78,11 +124,9 @@ ${schemaArray.join(",\n")}
|
|
|
78
124
|
};
|
|
79
125
|
}
|
|
80
126
|
function virtualResolvers(app) {
|
|
81
|
-
const getResolvers = () =>
|
|
82
|
-
return [...app.scanResolvers];
|
|
83
|
-
};
|
|
127
|
+
const getResolvers = () => [...app.scanResolvers];
|
|
84
128
|
app.options.virtual ??= {};
|
|
85
|
-
app.options.virtual["#nitro-
|
|
129
|
+
app.options.virtual["#nitro-graphql/server-resolvers"] = () => {
|
|
86
130
|
try {
|
|
87
131
|
const imports = getResolvers();
|
|
88
132
|
if (imports.length === 0) {
|
|
@@ -108,7 +152,7 @@ function virtualResolvers(app) {
|
|
|
108
152
|
for (const msg of invalidImports) app.logger.warn(` - ${msg}`);
|
|
109
153
|
}
|
|
110
154
|
const data = imports.map(({ imports: importList }) => importList.map((i) => `{ resolver: ${i.as} }`).join(",\n")).filter(Boolean).join(",\n");
|
|
111
|
-
|
|
155
|
+
return [
|
|
112
156
|
...importsContent,
|
|
113
157
|
"",
|
|
114
158
|
"export const resolvers = [",
|
|
@@ -116,11 +160,6 @@ function virtualResolvers(app) {
|
|
|
116
160
|
"]",
|
|
117
161
|
""
|
|
118
162
|
].join("\n");
|
|
119
|
-
if (app.options.dev) {
|
|
120
|
-
const totalExports = imports.reduce((sum, r) => sum + r.imports.length, 0);
|
|
121
|
-
app.logger.success(`[nitro-graphql] Generated virtual resolver module: ${totalExports} export(s) from ${imports.length} file(s)`);
|
|
122
|
-
}
|
|
123
|
-
return code;
|
|
124
163
|
} catch (error) {
|
|
125
164
|
app.logger.error("[nitro-graphql] Failed to generate virtual resolver module:", error);
|
|
126
165
|
return "export const resolvers = []";
|
|
@@ -128,11 +167,9 @@ function virtualResolvers(app) {
|
|
|
128
167
|
};
|
|
129
168
|
}
|
|
130
169
|
function virtualDirectives(app) {
|
|
131
|
-
const getDirectives = () =>
|
|
132
|
-
return [...app.scanDirectives || []];
|
|
133
|
-
};
|
|
170
|
+
const getDirectives = () => app.scanDirectives || [];
|
|
134
171
|
app.options.virtual ??= {};
|
|
135
|
-
app.options.virtual["#nitro-
|
|
172
|
+
app.options.virtual["#nitro-graphql/server-directives"] = () => {
|
|
136
173
|
try {
|
|
137
174
|
const imports = getDirectives();
|
|
138
175
|
if (imports.length === 0) return "export const directives = []";
|
|
@@ -155,7 +192,7 @@ function virtualDirectives(app) {
|
|
|
155
192
|
for (const msg of invalidImports) app.logger.warn(` - ${msg}`);
|
|
156
193
|
}
|
|
157
194
|
const data = imports.map(({ imports: importList }) => importList.map((i) => `{ directive: ${i.as} }`).join(",\n")).filter(Boolean).join(",\n");
|
|
158
|
-
|
|
195
|
+
return [
|
|
159
196
|
...importsContent,
|
|
160
197
|
"",
|
|
161
198
|
"export const directives = [",
|
|
@@ -163,11 +200,6 @@ function virtualDirectives(app) {
|
|
|
163
200
|
"]",
|
|
164
201
|
""
|
|
165
202
|
].join("\n");
|
|
166
|
-
if (app.options.dev) {
|
|
167
|
-
const totalExports = imports.reduce((sum, d) => sum + d.imports.length, 0);
|
|
168
|
-
app.logger.success(`[nitro-graphql] Generated virtual directive module: ${totalExports} directive(s) from ${imports.length} file(s)`);
|
|
169
|
-
}
|
|
170
|
-
return code;
|
|
171
203
|
} catch (error) {
|
|
172
204
|
app.logger.error("[nitro-graphql] Failed to generate virtual directive module:", error);
|
|
173
205
|
return "export const directives = []";
|
|
@@ -177,7 +209,7 @@ function virtualDirectives(app) {
|
|
|
177
209
|
function getGraphQLConfig(app) {
|
|
178
210
|
const configPath = resolve(app.graphql.serverDir, "config.ts");
|
|
179
211
|
app.options.virtual ??= {};
|
|
180
|
-
app.options.virtual["#nitro-
|
|
212
|
+
app.options.virtual["#nitro-graphql/graphql-config"] = () => {
|
|
181
213
|
return `import config from '${configPath}'
|
|
182
214
|
const importedConfig = config
|
|
183
215
|
export { importedConfig }
|
|
@@ -186,41 +218,41 @@ export { importedConfig }
|
|
|
186
218
|
}
|
|
187
219
|
function virtualModuleConfig(app) {
|
|
188
220
|
app.options.virtual ??= {};
|
|
189
|
-
app.options.virtual["#nitro-
|
|
221
|
+
app.options.virtual["#nitro-graphql/module-config"] = () => {
|
|
190
222
|
const moduleConfig = app.options.graphql || {};
|
|
191
223
|
return `export const moduleConfig = ${JSON.stringify(moduleConfig, null, 2)};`;
|
|
192
224
|
};
|
|
193
225
|
}
|
|
194
226
|
function virtualDebugInfo(app) {
|
|
195
227
|
app.options.virtual ??= {};
|
|
196
|
-
app.options.virtual["#nitro-
|
|
228
|
+
app.options.virtual["#nitro-graphql/debug-info"] = () => {
|
|
197
229
|
const virtualModuleCodes = {};
|
|
198
230
|
try {
|
|
199
|
-
const schemasGenerator = app.options.virtual["#nitro-
|
|
231
|
+
const schemasGenerator = app.options.virtual["#nitro-graphql/server-schemas"];
|
|
200
232
|
if (schemasGenerator && typeof schemasGenerator === "function") virtualModuleCodes["server-schemas"] = schemasGenerator();
|
|
201
233
|
} catch (error) {
|
|
202
234
|
virtualModuleCodes["server-schemas"] = `// Error generating: ${error instanceof Error ? error.message : String(error)}`;
|
|
203
235
|
}
|
|
204
236
|
try {
|
|
205
|
-
const resolversGenerator = app.options.virtual["#nitro-
|
|
237
|
+
const resolversGenerator = app.options.virtual["#nitro-graphql/server-resolvers"];
|
|
206
238
|
if (resolversGenerator && typeof resolversGenerator === "function") virtualModuleCodes["server-resolvers"] = resolversGenerator();
|
|
207
239
|
} catch (error) {
|
|
208
240
|
virtualModuleCodes["server-resolvers"] = `// Error generating: ${error instanceof Error ? error.message : String(error)}`;
|
|
209
241
|
}
|
|
210
242
|
try {
|
|
211
|
-
const directivesGenerator = app.options.virtual["#nitro-
|
|
243
|
+
const directivesGenerator = app.options.virtual["#nitro-graphql/server-directives"];
|
|
212
244
|
if (directivesGenerator && typeof directivesGenerator === "function") virtualModuleCodes["server-directives"] = directivesGenerator();
|
|
213
245
|
} catch (error) {
|
|
214
246
|
virtualModuleCodes["server-directives"] = `// Error generating: ${error instanceof Error ? error.message : String(error)}`;
|
|
215
247
|
}
|
|
216
248
|
try {
|
|
217
|
-
const moduleConfigGenerator = app.options.virtual["#nitro-
|
|
249
|
+
const moduleConfigGenerator = app.options.virtual["#nitro-graphql/module-config"];
|
|
218
250
|
if (moduleConfigGenerator && typeof moduleConfigGenerator === "function") virtualModuleCodes["module-config"] = moduleConfigGenerator();
|
|
219
251
|
} catch (error) {
|
|
220
252
|
virtualModuleCodes["module-config"] = `// Error generating: ${error instanceof Error ? error.message : String(error)}`;
|
|
221
253
|
}
|
|
222
254
|
try {
|
|
223
|
-
const graphqlConfigGenerator = app.options.virtual["#nitro-
|
|
255
|
+
const graphqlConfigGenerator = app.options.virtual["#nitro-graphql/graphql-config"];
|
|
224
256
|
if (graphqlConfigGenerator && typeof graphqlConfigGenerator === "function") virtualModuleCodes["graphql-config"] = graphqlConfigGenerator();
|
|
225
257
|
} catch (error) {
|
|
226
258
|
virtualModuleCodes["graphql-config"] = `// Error generating: ${error instanceof Error ? error.message : String(error)}`;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as h35 from "h3";
|
|
2
2
|
|
|
3
3
|
//#region src/routes/apollo-server.d.ts
|
|
4
|
-
declare const _default:
|
|
4
|
+
declare const _default: h35.EventHandlerWithFetch<h35.EventHandlerRequest, Promise<any>>;
|
|
5
5
|
//#endregion
|
|
6
6
|
export { _default as default };
|
|
@@ -2,11 +2,11 @@ import { consola as consola$1 } from "consola";
|
|
|
2
2
|
import defu from "defu";
|
|
3
3
|
import { parse } from "graphql";
|
|
4
4
|
import { mergeResolvers, mergeTypeDefs } from "@graphql-tools/merge";
|
|
5
|
-
import { importedConfig } from "#nitro-
|
|
6
|
-
import { moduleConfig } from "#nitro-
|
|
7
|
-
import { directives } from "#nitro-
|
|
8
|
-
import { resolvers } from "#nitro-
|
|
9
|
-
import { schemas } from "#nitro-
|
|
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";
|