nitro-graphql 1.3.1 → 1.4.1
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 +183 -1318
- package/dist/ecosystem/nuxt.js +12 -3
- package/dist/index.js +17 -9
- package/dist/rollup.js +4 -3
- package/dist/routes/apollo-server.d.ts +2 -2
- package/dist/routes/apollo-server.js +2 -1
- package/dist/routes/graphql-yoga.d.ts +2 -2
- package/dist/routes/graphql-yoga.js +2 -1
- package/dist/types/index.d.ts +6 -0
- package/dist/utils/directive-parser.js +4 -2
- package/dist/utils/index.d.ts +18 -2
- package/dist/utils/index.js +66 -16
- package/package.json +11 -9
package/dist/ecosystem/nuxt.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { join, resolve } from "pathe";
|
|
3
|
-
import { defineNuxtModule } from "@nuxt/kit";
|
|
3
|
+
import { defineNuxtModule, getLayerDirectories } from "@nuxt/kit";
|
|
4
4
|
|
|
5
5
|
//#region src/ecosystem/nuxt.ts
|
|
6
6
|
var nuxt_default = defineNuxtModule({
|
|
@@ -30,10 +30,19 @@ var nuxt_default = defineNuxtModule({
|
|
|
30
30
|
const externalServices = nuxt.options.nitro?.graphql?.externalServices || [];
|
|
31
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`);
|
|
32
32
|
nuxt.hook("imports:dirs", (dirs) => {
|
|
33
|
-
|
|
33
|
+
const graphqlServerPath = nuxt.options.nitro?.graphql?.serverDir || resolve(nuxt.options.srcDir, "graphql");
|
|
34
|
+
dirs.push(graphqlServerPath);
|
|
34
35
|
});
|
|
35
|
-
nuxt.hook("nitro:config", () => {
|
|
36
|
+
nuxt.hook("nitro:config", async (nitroConfig) => {
|
|
36
37
|
const clientDir = join(nuxt.options.buildDir, "graphql");
|
|
38
|
+
const layerDirs = await getLayerDirectories(nuxt);
|
|
39
|
+
const layerDirectories = layerDirs.map((layer) => layer.root.replace(/\/$/, "")).filter((root) => root !== nuxt.options.rootDir);
|
|
40
|
+
const layerServerDirs = layerDirs.filter((layer) => layer.root !== `${nuxt.options.rootDir}/`).map((layer) => layer.server?.replace(/\/$/, "")).filter(Boolean);
|
|
41
|
+
const layerAppDirs = layerDirs.filter((layer) => layer.root !== `${nuxt.options.rootDir}/`).map((layer) => layer.app?.replace(/\/$/, "")).filter(Boolean);
|
|
42
|
+
if (!nitroConfig.graphql) nitroConfig.graphql = {};
|
|
43
|
+
nitroConfig.graphql.layerDirectories = layerDirectories;
|
|
44
|
+
nitroConfig.graphql.layerServerDirs = layerServerDirs;
|
|
45
|
+
nitroConfig.graphql.layerAppDirs = layerAppDirs;
|
|
37
46
|
const appGraphqlDir = resolve(nuxt.options.rootDir, "app/graphql");
|
|
38
47
|
const hasAppGraphqlDir = existsSync(appGraphqlDir);
|
|
39
48
|
if (!hasAppGraphqlDir) {
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { generateDirectiveSchemas } from "./utils/directive-parser.js";
|
|
2
|
-
import { relativeWithDot, scanDirectives, scanDocs, scanResolvers, scanSchemas, validateExternalServices } from "./utils/index.js";
|
|
2
|
+
import { generateLayerIgnorePatterns, getLayerAppDirectories, getLayerServerDirectories, relativeWithDot, scanDirectives, scanDocs, scanResolvers, scanSchemas, validateExternalServices } from "./utils/index.js";
|
|
3
3
|
import { clientTypeGeneration, serverTypeGeneration } from "./utils/type-generation.js";
|
|
4
4
|
import { rollupConfig } from "./rollup.js";
|
|
5
5
|
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
@@ -35,7 +35,7 @@ var src_default = defineNitroModule({
|
|
|
35
35
|
server: "server"
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
-
nitro.hooks.hook("rollup:before", (
|
|
38
|
+
nitro.hooks.hook("rollup:before", (_, rollupConfig$1) => {
|
|
39
39
|
rollupConfig$1.external = rollupConfig$1.external || [];
|
|
40
40
|
const codegenExternals = ["oxc-parser", "@oxc-parser"];
|
|
41
41
|
if (Array.isArray(rollupConfig$1.external)) rollupConfig$1.external.push(...codegenExternals);
|
|
@@ -59,11 +59,19 @@ var src_default = defineNitroModule({
|
|
|
59
59
|
nitro.graphql.buildDir = graphqlBuildDir;
|
|
60
60
|
const watchDirs = [];
|
|
61
61
|
switch (nitro.options.framework.name) {
|
|
62
|
-
case "nuxt":
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
62
|
+
case "nuxt": {
|
|
63
|
+
if (!nitro.graphql.clientDir) {
|
|
64
|
+
nitro.graphql.clientDir = resolve(nitro.options.rootDir, "app", "graphql");
|
|
65
|
+
nitro.graphql.dir.client = "app/graphql";
|
|
66
|
+
}
|
|
67
|
+
if (!nitro.options.graphql?.serverDir) nitro.graphql.serverDir = resolve(nitro.options.rootDir, "server", "graphql");
|
|
68
|
+
watchDirs.push(nitro.graphql.clientDir);
|
|
69
|
+
const layerServerDirs = getLayerServerDirectories(nitro);
|
|
70
|
+
const layerAppDirs = getLayerAppDirectories(nitro);
|
|
71
|
+
for (const layerServerDir of layerServerDirs) watchDirs.push(join(layerServerDir, "graphql"));
|
|
72
|
+
for (const layerAppDir of layerAppDirs) watchDirs.push(join(layerAppDir, "graphql"));
|
|
66
73
|
break;
|
|
74
|
+
}
|
|
67
75
|
case "nitro":
|
|
68
76
|
nitro.graphql.clientDir = resolve(nitro.options.rootDir, "graphql");
|
|
69
77
|
nitro.graphql.dir.client = "graphql";
|
|
@@ -81,8 +89,8 @@ var src_default = defineNitroModule({
|
|
|
81
89
|
const watcher = watch(watchDirs, {
|
|
82
90
|
persistent: true,
|
|
83
91
|
ignoreInitial: true,
|
|
84
|
-
ignored: [...nitro.options.ignore,
|
|
85
|
-
}).on("all", async (
|
|
92
|
+
ignored: [...nitro.options.ignore, ...generateLayerIgnorePatterns(nitro)]
|
|
93
|
+
}).on("all", async (_, path) => {
|
|
86
94
|
if (path.endsWith(".graphql") || path.endsWith(".gql")) await clientTypeGeneration(nitro);
|
|
87
95
|
});
|
|
88
96
|
nitro.hooks.hook("close", () => {
|
|
@@ -155,7 +163,7 @@ var src_default = defineNitroModule({
|
|
|
155
163
|
]
|
|
156
164
|
});
|
|
157
165
|
}
|
|
158
|
-
nitro.hooks.hook("rollup:before", (
|
|
166
|
+
nitro.hooks.hook("rollup:before", (_, rollupConfig$1) => {
|
|
159
167
|
const manualChunks = rollupConfig$1.output?.manualChunks;
|
|
160
168
|
const chunkFiles = rollupConfig$1.output?.chunkFileNames;
|
|
161
169
|
if (!rollupConfig$1.output.inlineDynamicImports) rollupConfig$1.output.manualChunks = (id, meta) => {
|
package/dist/rollup.js
CHANGED
|
@@ -26,8 +26,9 @@ async function rollupConfig(app) {
|
|
|
26
26
|
if (validate) parse(content);
|
|
27
27
|
return `export default ${JSON.stringify(content)}`;
|
|
28
28
|
} catch (error) {
|
|
29
|
-
if (error.code === "ENOENT") return null;
|
|
30
|
-
|
|
29
|
+
if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") return null;
|
|
30
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
31
|
+
this.error(`Failed to read GraphQL file ${id}: ${message}`);
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
34
|
});
|
|
@@ -36,7 +37,7 @@ async function rollupConfig(app) {
|
|
|
36
37
|
async buildStart() {
|
|
37
38
|
const graphqlFiles = await scanGraphql(nitro);
|
|
38
39
|
for (const file of graphqlFiles) this.addWatchFile(file);
|
|
39
|
-
this.addWatchFile(
|
|
40
|
+
this.addWatchFile(app.graphql.serverDir);
|
|
40
41
|
}
|
|
41
42
|
});
|
|
42
43
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as h33 from "h3";
|
|
2
2
|
|
|
3
3
|
//#region src/routes/apollo-server.d.ts
|
|
4
|
-
declare const _default:
|
|
4
|
+
declare const _default: h33.EventHandler<h33.EventHandlerRequest, Promise<any>>;
|
|
5
5
|
//#endregion
|
|
6
6
|
export { _default as default };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { startServerAndCreateH3Handler } from "../utils/apollo.js";
|
|
2
|
+
import { consola as consola$1 } from "consola";
|
|
2
3
|
import defu from "defu";
|
|
3
4
|
import { parse } from "graphql";
|
|
4
5
|
import { mergeResolvers, mergeTypeDefs } from "@graphql-tools/merge";
|
|
@@ -59,7 +60,7 @@ async function createMergedSchema() {
|
|
|
59
60
|
}
|
|
60
61
|
return schema;
|
|
61
62
|
} catch (error) {
|
|
62
|
-
|
|
63
|
+
consola$1.error("Schema merge error:", error);
|
|
63
64
|
throw error;
|
|
64
65
|
}
|
|
65
66
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as h30 from "h3";
|
|
2
2
|
|
|
3
3
|
//#region src/routes/graphql-yoga.d.ts
|
|
4
|
-
declare const _default:
|
|
4
|
+
declare const _default: h30.EventHandler<h30.EventHandlerRequest, Promise<Response>>;
|
|
5
5
|
//#endregion
|
|
6
6
|
export { _default as default };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { consola as consola$1 } from "consola";
|
|
1
2
|
import defu from "defu";
|
|
2
3
|
import { parse } from "graphql";
|
|
3
4
|
import { mergeResolvers, mergeTypeDefs } from "@graphql-tools/merge";
|
|
@@ -74,7 +75,7 @@ async function createMergedSchema() {
|
|
|
74
75
|
}
|
|
75
76
|
return schema;
|
|
76
77
|
} catch (error) {
|
|
77
|
-
|
|
78
|
+
consola$1.error("Schema merge error:", error);
|
|
78
79
|
throw error;
|
|
79
80
|
}
|
|
80
81
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -117,6 +117,12 @@ interface NitroGraphQLOptions {
|
|
|
117
117
|
externalServices?: ExternalGraphQLService[];
|
|
118
118
|
/** Apollo Federation configuration */
|
|
119
119
|
federation?: FederationConfig;
|
|
120
|
+
/** Server GraphQL directory path */
|
|
121
|
+
serverDir?: string;
|
|
122
|
+
/** Layer directories (populated by Nuxt module) */
|
|
123
|
+
layerDirectories?: string[];
|
|
124
|
+
layerServerDirs?: string[];
|
|
125
|
+
layerAppDirs?: string[];
|
|
120
126
|
}
|
|
121
127
|
//#endregion
|
|
122
128
|
export { CodegenClientConfig, CodegenServerConfig, ExternalGraphQLService, FederationConfig, GenImport, GenericSdkConfig, NitroGraphQLOptions };
|
|
@@ -194,9 +194,9 @@ function generateDirectiveSchema(directive) {
|
|
|
194
194
|
*/
|
|
195
195
|
async function generateDirectiveSchemas(nitro, directives) {
|
|
196
196
|
if (directives.length === 0) return;
|
|
197
|
-
const { existsSync, readFileSync, writeFileSync } = await import("node:fs");
|
|
197
|
+
const { existsSync, readFileSync, writeFileSync, mkdirSync } = await import("node:fs");
|
|
198
198
|
const { readFile } = await import("node:fs/promises");
|
|
199
|
-
const { resolve } = await import("pathe");
|
|
199
|
+
const { resolve, dirname } = await import("pathe");
|
|
200
200
|
const directiveSchemas = [];
|
|
201
201
|
const seenDirectives = /* @__PURE__ */ new Set();
|
|
202
202
|
const parser = new DirectiveParser();
|
|
@@ -217,6 +217,8 @@ async function generateDirectiveSchemas(nitro, directives) {
|
|
|
217
217
|
# To define custom directives, create .directive.ts files using defineDirective()
|
|
218
218
|
|
|
219
219
|
${directiveSchemas.join("\n\n")}`;
|
|
220
|
+
const targetDir = dirname(directivesPath);
|
|
221
|
+
if (!existsSync(targetDir)) mkdirSync(targetDir, { recursive: true });
|
|
220
222
|
let shouldWrite = true;
|
|
221
223
|
if (existsSync(directivesPath)) {
|
|
222
224
|
const existingContent = readFileSync(directivesPath, "utf-8");
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -4,6 +4,22 @@ import { Nitro } from "nitropack";
|
|
|
4
4
|
|
|
5
5
|
//#region src/utils/index.d.ts
|
|
6
6
|
declare const GLOB_SCAN_PATTERN = "**/*.{graphql,gql,js,mjs,cjs,ts,mts,cts,tsx,jsx}";
|
|
7
|
+
/**
|
|
8
|
+
* Get all Nuxt layer directories from Nitro config
|
|
9
|
+
*/
|
|
10
|
+
declare function getLayerDirectories(nitro: Nitro): string[];
|
|
11
|
+
/**
|
|
12
|
+
* Get all Nuxt layer server directories from Nitro config
|
|
13
|
+
*/
|
|
14
|
+
declare function getLayerServerDirectories(nitro: Nitro): string[];
|
|
15
|
+
/**
|
|
16
|
+
* Get all Nuxt layer app directories from Nitro config
|
|
17
|
+
*/
|
|
18
|
+
declare function getLayerAppDirectories(nitro: Nitro): string[];
|
|
19
|
+
/**
|
|
20
|
+
* Generate layer-aware ignore patterns for auto-generated files
|
|
21
|
+
*/
|
|
22
|
+
declare function generateLayerIgnorePatterns(nitro: Nitro): string[];
|
|
7
23
|
declare function getImportId(p: string, lazy?: boolean): string;
|
|
8
24
|
declare function relativeWithDot(from: string, to: string): string;
|
|
9
25
|
declare function scanGraphql(nitro: Nitro): Promise<string[]>;
|
|
@@ -19,6 +35,6 @@ declare function scanExternalServiceDocs(nitro: Nitro, serviceName: string, patt
|
|
|
19
35
|
/**
|
|
20
36
|
* Validate external GraphQL service configuration
|
|
21
37
|
*/
|
|
22
|
-
declare function validateExternalServices(services:
|
|
38
|
+
declare function validateExternalServices(services: unknown[]): string[];
|
|
23
39
|
//#endregion
|
|
24
|
-
export { GLOB_SCAN_PATTERN, directiveParser, generateDirectiveSchema, generateDirectiveSchemas, getImportId, relativeWithDot, scanDirectives, scanDocs, scanExternalServiceDocs, scanGraphql, scanResolvers, scanSchemas, scanTypeDefs, validateExternalServices };
|
|
40
|
+
export { GLOB_SCAN_PATTERN, directiveParser, generateDirectiveSchema, generateDirectiveSchemas, generateLayerIgnorePatterns, getImportId, getLayerAppDirectories, getLayerDirectories, getLayerServerDirectories, relativeWithDot, scanDirectives, scanDocs, scanExternalServiceDocs, scanGraphql, scanResolvers, scanSchemas, scanTypeDefs, validateExternalServices };
|
package/dist/utils/index.js
CHANGED
|
@@ -7,6 +7,34 @@ import { glob } from "tinyglobby";
|
|
|
7
7
|
|
|
8
8
|
//#region src/utils/index.ts
|
|
9
9
|
const GLOB_SCAN_PATTERN = "**/*.{graphql,gql,js,mjs,cjs,ts,mts,cts,tsx,jsx}";
|
|
10
|
+
/**
|
|
11
|
+
* Get all Nuxt layer directories from Nitro config
|
|
12
|
+
*/
|
|
13
|
+
function getLayerDirectories(nitro) {
|
|
14
|
+
return nitro.options.graphql?.layerDirectories || [];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Get all Nuxt layer server directories from Nitro config
|
|
18
|
+
*/
|
|
19
|
+
function getLayerServerDirectories(nitro) {
|
|
20
|
+
return nitro.options.graphql?.layerServerDirs || [];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Get all Nuxt layer app directories from Nitro config
|
|
24
|
+
*/
|
|
25
|
+
function getLayerAppDirectories(nitro) {
|
|
26
|
+
return nitro.options.graphql?.layerAppDirs || [];
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Generate layer-aware ignore patterns for auto-generated files
|
|
30
|
+
*/
|
|
31
|
+
function generateLayerIgnorePatterns(nitro) {
|
|
32
|
+
const patterns = [];
|
|
33
|
+
patterns.push(`${nitro.graphql.serverDir}/_directives.graphql`);
|
|
34
|
+
const layerServerDirs = nitro.options.graphql?.layerServerDirs || [];
|
|
35
|
+
for (const layerServerDir of layerServerDirs) patterns.push(`${layerServerDir}/graphql/_directives.graphql`);
|
|
36
|
+
return patterns;
|
|
37
|
+
}
|
|
10
38
|
function getImportId(p, lazy) {
|
|
11
39
|
return (lazy ? "_lazy_" : "_") + hash(p).replace(/-/g, "").slice(0, 6);
|
|
12
40
|
}
|
|
@@ -35,32 +63,32 @@ async function scanResolvers(nitro) {
|
|
|
35
63
|
if (decl.init.callee.type === "Identifier" && decl.init.callee.name === "defineResolver") exports.imports.push({
|
|
36
64
|
name: decl.id.name,
|
|
37
65
|
type: "resolver",
|
|
38
|
-
as: `_${hash(decl.id.name + file.
|
|
66
|
+
as: `_${hash(decl.id.name + file.fullPath).replace(/-/g, "").slice(0, 6)}`
|
|
39
67
|
});
|
|
40
68
|
if (decl.init.callee.type === "Identifier" && decl.init.callee.name === "defineQuery") exports.imports.push({
|
|
41
69
|
name: decl.id.name,
|
|
42
70
|
type: "query",
|
|
43
|
-
as: `_${hash(decl.id.name + file.
|
|
71
|
+
as: `_${hash(decl.id.name + file.fullPath).replace(/-/g, "").slice(0, 6)}`
|
|
44
72
|
});
|
|
45
73
|
if (decl.init.callee.type === "Identifier" && decl.init.callee.name === "defineMutation") exports.imports.push({
|
|
46
74
|
name: decl.id.name,
|
|
47
75
|
type: "mutation",
|
|
48
|
-
as: `_${hash(decl.id.name + file.
|
|
76
|
+
as: `_${hash(decl.id.name + file.fullPath).replace(/-/g, "").slice(0, 6)}`
|
|
49
77
|
});
|
|
50
78
|
if (decl.init.callee.type === "Identifier" && decl.init.callee.name === "defineType") exports.imports.push({
|
|
51
79
|
name: decl.id.name,
|
|
52
80
|
type: "type",
|
|
53
|
-
as: `_${hash(decl.id.name + file.
|
|
81
|
+
as: `_${hash(decl.id.name + file.fullPath).replace(/-/g, "").slice(0, 6)}`
|
|
54
82
|
});
|
|
55
83
|
if (decl.init.callee.type === "Identifier" && decl.init.callee.name === "defineSubscription") exports.imports.push({
|
|
56
84
|
name: decl.id.name,
|
|
57
85
|
type: "subscription",
|
|
58
|
-
as: `_${hash(decl.id.name + file.
|
|
86
|
+
as: `_${hash(decl.id.name + file.fullPath).replace(/-/g, "").slice(0, 6)}`
|
|
59
87
|
});
|
|
60
88
|
if (decl.init.callee.type === "Identifier" && decl.init.callee.name === "defineDirective") exports.imports.push({
|
|
61
89
|
name: decl.id.name,
|
|
62
90
|
type: "directive",
|
|
63
|
-
as: `_${hash(decl.id.name + file.
|
|
91
|
+
as: `_${hash(decl.id.name + file.fullPath).replace(/-/g, "").slice(0, 6)}`
|
|
64
92
|
});
|
|
65
93
|
}
|
|
66
94
|
}
|
|
@@ -85,7 +113,7 @@ async function scanDirectives(nitro) {
|
|
|
85
113
|
if (decl.init.callee.type === "Identifier" && decl.init.callee.name === "defineDirective") exports.imports.push({
|
|
86
114
|
name: decl.id.name,
|
|
87
115
|
type: "directive",
|
|
88
|
-
as: `_${hash(decl.id.name + file.
|
|
116
|
+
as: `_${hash(decl.id.name + file.fullPath).replace(/-/g, "").slice(0, 6)}`
|
|
89
117
|
});
|
|
90
118
|
}
|
|
91
119
|
}
|
|
@@ -104,12 +132,22 @@ async function scanSchemas(nitro) {
|
|
|
104
132
|
}
|
|
105
133
|
async function scanDocs(nitro) {
|
|
106
134
|
const files = await scanDir(nitro, nitro.options.rootDir, nitro.graphql.dir.client, "**/*.graphql");
|
|
135
|
+
const layerAppDirs = getLayerAppDirectories(nitro);
|
|
136
|
+
const layerFiles = await Promise.all(layerAppDirs.map((layerAppDir) => scanDir(nitro, layerAppDir, "graphql", "**/*.graphql"))).then((r) => r.flat());
|
|
137
|
+
const combinedFiles = [...files, ...layerFiles];
|
|
138
|
+
const seenPaths = /* @__PURE__ */ new Set();
|
|
139
|
+
const allFiles = combinedFiles.filter((file) => {
|
|
140
|
+
if (seenPaths.has(file.fullPath)) return false;
|
|
141
|
+
seenPaths.add(file.fullPath);
|
|
142
|
+
return true;
|
|
143
|
+
});
|
|
107
144
|
const externalServices = nitro.options.graphql?.externalServices || [];
|
|
108
145
|
const externalPatterns = externalServices.flatMap((service) => service.documents || []);
|
|
109
|
-
return
|
|
146
|
+
return allFiles.filter((f) => !f.path.startsWith("external/")).filter((f) => {
|
|
110
147
|
const relativePath = f.path;
|
|
111
148
|
for (const pattern of externalPatterns) {
|
|
112
|
-
const
|
|
149
|
+
const clientDirPattern = `${nitro.graphql.dir.client}/`;
|
|
150
|
+
const cleanPattern = pattern.replace(/* @__PURE__ */ new RegExp(`^${clientDirPattern.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}`), "");
|
|
113
151
|
const patternDir = cleanPattern.split("/")[0];
|
|
114
152
|
const fileDir = relativePath.split("/")[0];
|
|
115
153
|
if (patternDir === fileDir) return false;
|
|
@@ -144,23 +182,35 @@ function validateExternalServices(services) {
|
|
|
144
182
|
const serviceNames = /* @__PURE__ */ new Set();
|
|
145
183
|
for (const [index, service] of services.entries()) {
|
|
146
184
|
const prefix = `externalServices[${index}]`;
|
|
147
|
-
if (!service
|
|
185
|
+
if (!service || typeof service !== "object") {
|
|
186
|
+
errors.push(`${prefix} must be an object`);
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
if (!("name" in service) || typeof service.name !== "string") errors.push(`${prefix}.name is required and must be a string`);
|
|
148
190
|
else if (serviceNames.has(service.name)) errors.push(`${prefix}.name "${service.name}" must be unique`);
|
|
149
191
|
else serviceNames.add(service.name);
|
|
150
|
-
if (!service.schema) errors.push(`${prefix}.schema is required`);
|
|
151
|
-
if (!
|
|
192
|
+
if (!("schema" in service) || !service.schema) errors.push(`${prefix}.schema is required`);
|
|
193
|
+
if (!("endpoint" in service) || typeof service.endpoint !== "string") errors.push(`${prefix}.endpoint is required and must be a string`);
|
|
152
194
|
else try {
|
|
153
195
|
new URL(service.endpoint);
|
|
154
196
|
} catch {
|
|
155
197
|
errors.push(`${prefix}.endpoint "${service.endpoint}" must be a valid URL`);
|
|
156
198
|
}
|
|
157
|
-
if (service.name && !/^[a-z]\w*$/i.test(service.name)) errors.push(`${prefix}.name "${service.name}" must be a valid identifier (letters, numbers, underscore, starting with letter)`);
|
|
199
|
+
if ("name" in service && service.name && typeof service.name === "string" && !/^[a-z]\w*$/i.test(service.name)) errors.push(`${prefix}.name "${service.name}" must be a valid identifier (letters, numbers, underscore, starting with letter)`);
|
|
158
200
|
}
|
|
159
201
|
return errors;
|
|
160
202
|
}
|
|
161
203
|
async function scanFiles(nitro, name, globPattern = GLOB_SCAN_PATTERN) {
|
|
162
|
-
const
|
|
163
|
-
|
|
204
|
+
const regularFiles = await Promise.all(nitro.options.scanDirs.map((dir) => scanDir(nitro, dir, name, globPattern))).then((r) => r.flat());
|
|
205
|
+
const layerDirectories = getLayerDirectories(nitro);
|
|
206
|
+
const layerFiles = await Promise.all(layerDirectories.map((layerDir) => scanDir(nitro, layerDir, `server/${name}`, globPattern))).then((r) => r.flat());
|
|
207
|
+
const allFiles = [...regularFiles, ...layerFiles];
|
|
208
|
+
const seenPaths = /* @__PURE__ */ new Set();
|
|
209
|
+
return allFiles.filter((file) => {
|
|
210
|
+
if (seenPaths.has(file.fullPath)) return false;
|
|
211
|
+
seenPaths.add(file.fullPath);
|
|
212
|
+
return true;
|
|
213
|
+
});
|
|
164
214
|
}
|
|
165
215
|
async function scanDir(nitro, dir, name, globPattern = GLOB_SCAN_PATTERN) {
|
|
166
216
|
const fileNames = await glob(join(name, globPattern), {
|
|
@@ -184,4 +234,4 @@ async function scanDir(nitro, dir, name, globPattern = GLOB_SCAN_PATTERN) {
|
|
|
184
234
|
}
|
|
185
235
|
|
|
186
236
|
//#endregion
|
|
187
|
-
export { GLOB_SCAN_PATTERN, directiveParser, generateDirectiveSchema, generateDirectiveSchemas, getImportId, relativeWithDot, scanDirectives, scanDocs, scanExternalServiceDocs, scanGraphql, scanResolvers, scanSchemas, scanTypeDefs, validateExternalServices };
|
|
237
|
+
export { GLOB_SCAN_PATTERN, directiveParser, generateDirectiveSchema, generateDirectiveSchemas, generateLayerIgnorePatterns, getImportId, getLayerAppDirectories, getLayerDirectories, getLayerServerDirectories, relativeWithDot, scanDirectives, scanDocs, scanExternalServiceDocs, scanGraphql, scanResolvers, scanSchemas, scanTypeDefs, validateExternalServices };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nitro-graphql",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.4.1",
|
|
5
5
|
"description": "GraphQL integration for Nitro",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"sideEffects": false,
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
"@graphql-codegen/typescript": "^4.1.6",
|
|
84
84
|
"@graphql-codegen/typescript-generic-sdk": "^4.0.2",
|
|
85
85
|
"@graphql-codegen/typescript-operations": "^4.6.1",
|
|
86
|
-
"@graphql-codegen/typescript-resolvers": "^4.5.
|
|
86
|
+
"@graphql-codegen/typescript-resolvers": "^4.5.2",
|
|
87
87
|
"@graphql-tools/graphql-file-loader": "^8.1.0",
|
|
88
88
|
"@graphql-tools/load": "^8.1.2",
|
|
89
89
|
"@graphql-tools/load-files": "^7.0.1",
|
|
@@ -98,16 +98,16 @@
|
|
|
98
98
|
"graphql-scalars": "^1.24.2",
|
|
99
99
|
"knitwork": "^1.2.0",
|
|
100
100
|
"ohash": "^2.0.11",
|
|
101
|
-
"oxc-parser": "^0.
|
|
101
|
+
"oxc-parser": "^0.86.0",
|
|
102
102
|
"pathe": "^2.0.3",
|
|
103
103
|
"tinyglobby": "^0.2.14"
|
|
104
104
|
},
|
|
105
105
|
"devDependencies": {
|
|
106
|
-
"@antfu/eslint-config": "^5.2.
|
|
106
|
+
"@antfu/eslint-config": "^5.2.2",
|
|
107
107
|
"@apollo/subgraph": "^2.11.2",
|
|
108
|
-
"@nuxt/kit": "^4.0
|
|
109
|
-
"@nuxt/schema": "^4.0
|
|
110
|
-
"@types/node": "^22.18.
|
|
108
|
+
"@nuxt/kit": "^4.1.0",
|
|
109
|
+
"@nuxt/schema": "^4.1.0",
|
|
110
|
+
"@types/node": "^22.18.1",
|
|
111
111
|
"bumpp": "^10.2.3",
|
|
112
112
|
"changelogen": "^0.6.2",
|
|
113
113
|
"crossws": "0.3.5",
|
|
@@ -115,7 +115,7 @@
|
|
|
115
115
|
"graphql": "^16.11.0",
|
|
116
116
|
"graphql-yoga": "^5.15.1",
|
|
117
117
|
"h3": "1.15.3",
|
|
118
|
-
"nitropack": "^2.12.
|
|
118
|
+
"nitropack": "^2.12.5",
|
|
119
119
|
"tsdown": "^0.14.2",
|
|
120
120
|
"typescript": "^5.9.2"
|
|
121
121
|
},
|
|
@@ -127,7 +127,9 @@
|
|
|
127
127
|
"dev": "tsdown --watch",
|
|
128
128
|
"bumpp": "bumpp package.json",
|
|
129
129
|
"release": "pnpm build && pnpm bumpp && pnpm publish --no-git-checks --access public",
|
|
130
|
-
"playground": "cd
|
|
130
|
+
"playground:nitro": "cd playgrounds/nitro && pnpm install && pnpm dev",
|
|
131
|
+
"playground:nuxt": "cd playgrounds/nuxt && pnpm install && pnpm dev",
|
|
132
|
+
"playground:federation": "cd playgrounds/federation && pnpm install && pnpm dev",
|
|
131
133
|
"lint": "eslint .",
|
|
132
134
|
"lint:fix": "eslint . --fix"
|
|
133
135
|
}
|