nitro-graphql 1.4.3 → 2.0.0-beta.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/dist/ecosystem/nuxt.js +1 -3
- package/dist/index.d.ts +2 -2
- package/dist/index.js +11 -20
- package/dist/rollup.js +8 -16
- package/dist/routes/apollo-server.d.ts +2 -2
- package/dist/routes/apollo-server.js +10 -17
- package/dist/routes/graphql-yoga.d.ts +1 -1
- package/dist/routes/graphql-yoga.js +15 -23
- package/dist/routes/health.d.ts +2 -6
- package/dist/routes/health.js +6 -4
- package/dist/types/index.d.ts +2 -2
- package/dist/utils/apollo.js +2 -3
- package/dist/utils/client-codegen.js +30 -48
- package/dist/utils/directive-parser.js +7 -16
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +7 -15
- package/dist/utils/server-codegen.js +3 -5
- package/dist/utils/type-generation.d.ts +1 -1
- package/dist/utils/type-generation.js +10 -21
- package/package.json +22 -26
package/dist/ecosystem/nuxt.js
CHANGED
|
@@ -43,9 +43,7 @@ var nuxt_default = defineNuxtModule({
|
|
|
43
43
|
nitroConfig.graphql.layerDirectories = layerDirectories;
|
|
44
44
|
nitroConfig.graphql.layerServerDirs = layerServerDirs;
|
|
45
45
|
nitroConfig.graphql.layerAppDirs = layerAppDirs;
|
|
46
|
-
|
|
47
|
-
const hasAppGraphqlDir = existsSync(appGraphqlDir);
|
|
48
|
-
if (!hasAppGraphqlDir) {
|
|
46
|
+
if (!existsSync(resolve(nuxt.options.rootDir, "app/graphql"))) {
|
|
49
47
|
const defaultDir = join(clientDir, "default");
|
|
50
48
|
if (!existsSync(defaultDir)) mkdirSync(defaultDir, { recursive: true });
|
|
51
49
|
const sampleQueryFile = join(defaultDir, "queries.graphql");
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { StandardSchemaV1 } from "./types/standard-schema.js";
|
|
2
2
|
import { CodegenClientConfig, CodegenServerConfig, ExternalGraphQLService, FederationConfig, GenImport, GenericSdkConfig, NitroGraphQLOptions } from "./types/index.js";
|
|
3
|
-
import * as
|
|
3
|
+
import * as nitro_types0 from "nitro/types";
|
|
4
4
|
|
|
5
5
|
//#region src/index.d.ts
|
|
6
|
-
declare const _default:
|
|
6
|
+
declare const _default: nitro_types0.NitroModule;
|
|
7
7
|
//#endregion
|
|
8
8
|
export { CodegenClientConfig, CodegenServerConfig, ExternalGraphQLService, FederationConfig, GenImport, GenericSdkConfig, NitroGraphQLOptions, StandardSchemaV1, _default as default };
|
package/dist/index.js
CHANGED
|
@@ -7,7 +7,6 @@ import { fileURLToPath } from "node:url";
|
|
|
7
7
|
import { watch } from "chokidar";
|
|
8
8
|
import consola from "consola";
|
|
9
9
|
import defu from "defu";
|
|
10
|
-
import { defineNitroModule } from "nitropack/kit";
|
|
11
10
|
import { dirname, join, relative, resolve } from "pathe";
|
|
12
11
|
|
|
13
12
|
//#region src/index.ts
|
|
@@ -96,28 +95,21 @@ var src_default = defineNitroModule({
|
|
|
96
95
|
nitro.hooks.hook("close", () => {
|
|
97
96
|
watcher.close();
|
|
98
97
|
});
|
|
99
|
-
const
|
|
100
|
-
const tsconfigDir = dirname(tsConfigPath);
|
|
98
|
+
const tsconfigDir = dirname(resolve(nitro.options.buildDir, nitro.options.typescript.tsconfigPath));
|
|
101
99
|
const typesDir = resolve(nitro.options.buildDir, "types");
|
|
102
|
-
|
|
103
|
-
nitro.
|
|
104
|
-
|
|
105
|
-
nitro.scanDocuments = docs;
|
|
106
|
-
const resolvers = await scanResolvers(nitro);
|
|
107
|
-
nitro.scanResolvers = resolvers;
|
|
100
|
+
nitro.scanSchemas = await scanSchemas(nitro);
|
|
101
|
+
nitro.scanDocuments = await scanDocs(nitro);
|
|
102
|
+
nitro.scanResolvers = await scanResolvers(nitro);
|
|
108
103
|
const directives = await scanDirectives(nitro);
|
|
109
104
|
nitro.scanDirectives = directives;
|
|
110
105
|
await generateDirectiveSchemas(nitro, directives);
|
|
111
106
|
nitro.hooks.hook("dev:start", async () => {
|
|
112
|
-
|
|
113
|
-
nitro.
|
|
114
|
-
const resolvers$1 = await scanResolvers(nitro);
|
|
115
|
-
nitro.scanResolvers = resolvers$1;
|
|
107
|
+
nitro.scanSchemas = await scanSchemas(nitro);
|
|
108
|
+
nitro.scanResolvers = await scanResolvers(nitro);
|
|
116
109
|
const directives$1 = await scanDirectives(nitro);
|
|
117
110
|
nitro.scanDirectives = directives$1;
|
|
118
111
|
await generateDirectiveSchemas(nitro, directives$1);
|
|
119
|
-
|
|
120
|
-
nitro.scanDocuments = docs$1;
|
|
112
|
+
nitro.scanDocuments = await scanDocs(nitro);
|
|
121
113
|
});
|
|
122
114
|
await rollupConfig(nitro);
|
|
123
115
|
await serverTypeGeneration(nitro);
|
|
@@ -128,9 +120,9 @@ var src_default = defineNitroModule({
|
|
|
128
120
|
});
|
|
129
121
|
const runtime = fileURLToPath(new URL("routes", import.meta.url));
|
|
130
122
|
const methods = [
|
|
131
|
-
"
|
|
132
|
-
"
|
|
133
|
-
"
|
|
123
|
+
"GET",
|
|
124
|
+
"POST",
|
|
125
|
+
"OPTIONS"
|
|
134
126
|
];
|
|
135
127
|
if (nitro.options.graphql?.framework === "graphql-yoga") for (const method of methods) nitro.options.handlers.push({
|
|
136
128
|
route: nitro.options.runtimeConfig.graphql?.endpoint?.graphql || "/api/graphql",
|
|
@@ -145,7 +137,7 @@ var src_default = defineNitroModule({
|
|
|
145
137
|
nitro.options.handlers.push({
|
|
146
138
|
route: nitro.options.runtimeConfig.graphql?.endpoint?.healthCheck || "/api/graphql/health",
|
|
147
139
|
handler: join(runtime, "health"),
|
|
148
|
-
method: "
|
|
140
|
+
method: "GET"
|
|
149
141
|
});
|
|
150
142
|
if (nitro.options.imports) {
|
|
151
143
|
nitro.options.imports.presets ??= [];
|
|
@@ -170,7 +162,6 @@ var src_default = defineNitroModule({
|
|
|
170
162
|
if (id.endsWith(".graphql") || id.endsWith(".gql")) return "schemas";
|
|
171
163
|
if (id.endsWith(".resolver.ts")) return "resolvers";
|
|
172
164
|
if (typeof manualChunks === "function") return manualChunks(id, meta);
|
|
173
|
-
return void 0;
|
|
174
165
|
};
|
|
175
166
|
rollupConfig$1.output.chunkFileNames = (chunkInfo) => {
|
|
176
167
|
if (chunkInfo.moduleIds && chunkInfo.moduleIds.some((id) => id.endsWith(".graphql") || id.endsWith(".resolver.ts") || id.endsWith(".gql"))) return `chunks/graphql/[name].mjs`;
|
package/dist/rollup.js
CHANGED
|
@@ -49,26 +49,23 @@ async function rollupConfig(app) {
|
|
|
49
49
|
}
|
|
50
50
|
function virtualSchemas(app) {
|
|
51
51
|
const getSchemas = () => {
|
|
52
|
-
|
|
53
|
-
return schemas;
|
|
52
|
+
return [...app.scanSchemas, ...app.options.graphql?.typedefs ?? []];
|
|
54
53
|
};
|
|
55
54
|
app.options.virtual ??= {};
|
|
56
55
|
app.options.virtual["#nitro-internal-virtual/server-schemas"] = () => {
|
|
57
56
|
const imports = getSchemas();
|
|
58
|
-
|
|
57
|
+
return `
|
|
59
58
|
${imports.map((handler) => `import ${getImportId(handler)} from '${handler}';`).join("\n")}
|
|
60
59
|
|
|
61
60
|
export const schemas = [
|
|
62
61
|
${imports.map((h) => `{ def: ${getImportId(h)} }`).join(",\n")}
|
|
63
62
|
];
|
|
64
63
|
`;
|
|
65
|
-
return code;
|
|
66
64
|
};
|
|
67
65
|
}
|
|
68
66
|
function virtualResolvers(app) {
|
|
69
67
|
const getResolvers = () => {
|
|
70
|
-
|
|
71
|
-
return resolvers;
|
|
68
|
+
return [...app.scanResolvers];
|
|
72
69
|
};
|
|
73
70
|
app.options.virtual ??= {};
|
|
74
71
|
app.options.virtual["#nitro-internal-virtual/server-resolvers"] = () => {
|
|
@@ -76,22 +73,19 @@ function virtualResolvers(app) {
|
|
|
76
73
|
const importsContent = [...imports.map(({ specifier, imports: imports$1, options }) => {
|
|
77
74
|
return genImport(specifier, imports$1, options);
|
|
78
75
|
})];
|
|
79
|
-
const data = imports.map(({ imports: imports$1 }) => imports$1.map((i) => `{ resolver: ${i.as} }`).join(",\n")).filter(Boolean).join(",\n");
|
|
80
76
|
const content = [
|
|
81
77
|
"export const resolvers = [",
|
|
82
|
-
|
|
78
|
+
imports.map(({ imports: imports$1 }) => imports$1.map((i) => `{ resolver: ${i.as} }`).join(",\n")).filter(Boolean).join(",\n"),
|
|
83
79
|
"]",
|
|
84
80
|
""
|
|
85
81
|
];
|
|
86
82
|
content.unshift(...importsContent);
|
|
87
|
-
|
|
88
|
-
return code;
|
|
83
|
+
return content.join("\n");
|
|
89
84
|
};
|
|
90
85
|
}
|
|
91
86
|
function virtualDirectives(app) {
|
|
92
87
|
const getDirectives = () => {
|
|
93
|
-
|
|
94
|
-
return directives;
|
|
88
|
+
return [...app.scanDirectives || []];
|
|
95
89
|
};
|
|
96
90
|
app.options.virtual ??= {};
|
|
97
91
|
app.options.virtual["#nitro-internal-virtual/server-directives"] = () => {
|
|
@@ -99,16 +93,14 @@ function virtualDirectives(app) {
|
|
|
99
93
|
const importsContent = [...imports.map(({ specifier, imports: imports$1, options }) => {
|
|
100
94
|
return genImport(specifier, imports$1, options);
|
|
101
95
|
})];
|
|
102
|
-
const data = imports.map(({ imports: imports$1 }) => imports$1.map((i) => `{ directive: ${i.as} }`).join(",\n")).filter(Boolean).join(",\n");
|
|
103
96
|
const content = [
|
|
104
97
|
"export const directives = [",
|
|
105
|
-
|
|
98
|
+
imports.map(({ imports: imports$1 }) => imports$1.map((i) => `{ directive: ${i.as} }`).join(",\n")).filter(Boolean).join(",\n"),
|
|
106
99
|
"]",
|
|
107
100
|
""
|
|
108
101
|
];
|
|
109
102
|
content.unshift(...importsContent);
|
|
110
|
-
|
|
111
|
-
return code;
|
|
103
|
+
return content.join("\n");
|
|
112
104
|
};
|
|
113
105
|
}
|
|
114
106
|
function getGraphQLConfig(app) {
|
|
@@ -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, unknown>;
|
|
5
5
|
//#endregion
|
|
6
6
|
export { _default as default };
|
|
@@ -18,8 +18,7 @@ let buildSubgraphSchema = null;
|
|
|
18
18
|
async function loadFederationSupport() {
|
|
19
19
|
if (buildSubgraphSchema !== null) return buildSubgraphSchema;
|
|
20
20
|
try {
|
|
21
|
-
|
|
22
|
-
buildSubgraphSchema = apolloSubgraph.buildSubgraphSchema;
|
|
21
|
+
buildSubgraphSchema = (await import("@apollo/subgraph")).buildSubgraphSchema;
|
|
23
22
|
} catch {
|
|
24
23
|
buildSubgraphSchema = false;
|
|
25
24
|
}
|
|
@@ -27,8 +26,7 @@ async function loadFederationSupport() {
|
|
|
27
26
|
}
|
|
28
27
|
async function createMergedSchema() {
|
|
29
28
|
try {
|
|
30
|
-
const
|
|
31
|
-
const typeDefs = mergeTypeDefs([mergedSchemas], {
|
|
29
|
+
const typeDefs = mergeTypeDefs([schemas.map((schema$1) => schema$1.def).join("\n\n")], {
|
|
32
30
|
throwOnConflict: true,
|
|
33
31
|
commentDescriptions: true,
|
|
34
32
|
sort: true
|
|
@@ -38,13 +36,11 @@ async function createMergedSchema() {
|
|
|
38
36
|
let schema;
|
|
39
37
|
if (federationEnabled) {
|
|
40
38
|
const buildSubgraph = await loadFederationSupport();
|
|
41
|
-
if (buildSubgraph) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
});
|
|
47
|
-
} else {
|
|
39
|
+
if (buildSubgraph) schema = buildSubgraph({
|
|
40
|
+
typeDefs: typeof typeDefs === "string" ? parse(typeDefs) : typeDefs,
|
|
41
|
+
resolvers: mergedResolvers
|
|
42
|
+
});
|
|
43
|
+
else {
|
|
48
44
|
console.warn("Federation enabled but @apollo/subgraph not available, falling back to regular schema");
|
|
49
45
|
schema = makeExecutableSchema({
|
|
50
46
|
typeDefs,
|
|
@@ -68,9 +64,8 @@ let apolloServer = null;
|
|
|
68
64
|
let serverStarted = false;
|
|
69
65
|
async function createApolloServer() {
|
|
70
66
|
if (!apolloServer) {
|
|
71
|
-
const schema = await createMergedSchema();
|
|
72
67
|
apolloServer = new ApolloServer(defu({
|
|
73
|
-
schema,
|
|
68
|
+
schema: await createMergedSchema(),
|
|
74
69
|
introspection: true,
|
|
75
70
|
plugins: [ApolloServerPluginLandingPageLocalDefault({ embed: true })]
|
|
76
71
|
}, importedConfig));
|
|
@@ -84,12 +79,10 @@ async function createApolloServer() {
|
|
|
84
79
|
let serverPromise = null;
|
|
85
80
|
var apollo_server_default = defineEventHandler(async (event) => {
|
|
86
81
|
if (!serverPromise) serverPromise = createApolloServer();
|
|
87
|
-
|
|
88
|
-
const h3Handler = startServerAndCreateH3Handler(server, {
|
|
82
|
+
return startServerAndCreateH3Handler(await serverPromise, {
|
|
89
83
|
context: async () => ({ event }),
|
|
90
84
|
serverAlreadyStarted: true
|
|
91
|
-
});
|
|
92
|
-
return h3Handler(event);
|
|
85
|
+
})(event);
|
|
93
86
|
});
|
|
94
87
|
|
|
95
88
|
//#endregion
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as h31 from "h3";
|
|
2
2
|
|
|
3
3
|
//#region src/routes/graphql-yoga.d.ts
|
|
4
|
-
declare const _default: h31.EventHandler<h31.EventHandlerRequest,
|
|
4
|
+
declare const _default: h31.EventHandler<h31.EventHandlerRequest, unknown>;
|
|
5
5
|
//#endregion
|
|
6
6
|
export { _default as default };
|
|
@@ -8,7 +8,7 @@ import { directives } from "#nitro-internal-virtual/server-directives";
|
|
|
8
8
|
import { resolvers } from "#nitro-internal-virtual/server-resolvers";
|
|
9
9
|
import { schemas } from "#nitro-internal-virtual/server-schemas";
|
|
10
10
|
import { makeExecutableSchema } from "@graphql-tools/schema";
|
|
11
|
-
import { defineEventHandler
|
|
11
|
+
import { defineEventHandler } from "h3";
|
|
12
12
|
import { createYoga } from "graphql-yoga";
|
|
13
13
|
|
|
14
14
|
//#region src/routes/graphql-yoga.ts
|
|
@@ -16,8 +16,7 @@ let buildSubgraphSchema = null;
|
|
|
16
16
|
async function loadFederationSupport() {
|
|
17
17
|
if (buildSubgraphSchema !== null) return buildSubgraphSchema;
|
|
18
18
|
try {
|
|
19
|
-
|
|
20
|
-
buildSubgraphSchema = apolloSubgraph.buildSubgraphSchema;
|
|
19
|
+
buildSubgraphSchema = (await import("@apollo/subgraph")).buildSubgraphSchema;
|
|
21
20
|
} catch {
|
|
22
21
|
buildSubgraphSchema = false;
|
|
23
22
|
}
|
|
@@ -42,8 +41,7 @@ new window.EmbeddedSandbox({
|
|
|
42
41
|
</html>`;
|
|
43
42
|
async function createMergedSchema() {
|
|
44
43
|
try {
|
|
45
|
-
const
|
|
46
|
-
const typeDefs = mergeTypeDefs([mergedSchemas], {
|
|
44
|
+
const typeDefs = mergeTypeDefs([schemas.map((schema$1) => schema$1.def).join("\n\n")], {
|
|
47
45
|
throwOnConflict: true,
|
|
48
46
|
commentDescriptions: true,
|
|
49
47
|
sort: true
|
|
@@ -53,13 +51,11 @@ async function createMergedSchema() {
|
|
|
53
51
|
let schema;
|
|
54
52
|
if (federationEnabled) {
|
|
55
53
|
const buildSubgraph = await loadFederationSupport();
|
|
56
|
-
if (buildSubgraph) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
});
|
|
62
|
-
} else {
|
|
54
|
+
if (buildSubgraph) schema = buildSubgraph({
|
|
55
|
+
typeDefs: typeof typeDefs === "string" ? parse(typeDefs) : typeDefs,
|
|
56
|
+
resolvers: mergedResolvers
|
|
57
|
+
});
|
|
58
|
+
else {
|
|
63
59
|
console.warn("Federation enabled but @apollo/subgraph not available, falling back to regular schema");
|
|
64
60
|
schema = makeExecutableSchema({
|
|
65
61
|
typeDefs,
|
|
@@ -81,17 +77,13 @@ async function createMergedSchema() {
|
|
|
81
77
|
}
|
|
82
78
|
let yoga;
|
|
83
79
|
var graphql_yoga_default = defineEventHandler(async (event) => {
|
|
84
|
-
if (!yoga) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}, importedConfig));
|
|
92
|
-
}
|
|
93
|
-
const request = toWebRequest(event);
|
|
94
|
-
const response = await yoga.handleRequest(request, event);
|
|
80
|
+
if (!yoga) yoga = createYoga(defu({
|
|
81
|
+
schema: await createMergedSchema(),
|
|
82
|
+
graphqlEndpoint: "/api/graphql",
|
|
83
|
+
landingPage: false,
|
|
84
|
+
renderGraphiQL: () => apolloSandboxHtml
|
|
85
|
+
}, importedConfig));
|
|
86
|
+
const response = await yoga.handleRequest(event.req, event);
|
|
95
87
|
return new Response(response.body, response);
|
|
96
88
|
});
|
|
97
89
|
|
package/dist/routes/health.d.ts
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as h30 from "h3";
|
|
2
2
|
|
|
3
3
|
//#region src/routes/health.d.ts
|
|
4
|
-
declare const _default:
|
|
5
|
-
status: string;
|
|
6
|
-
message: string;
|
|
7
|
-
timestamp: string;
|
|
8
|
-
}>>;
|
|
4
|
+
declare const _default: h30.EventHandler<h30.EventHandlerRequest, unknown>;
|
|
9
5
|
//#endregion
|
|
10
6
|
export { _default as default };
|
package/dist/routes/health.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { defineEventHandler
|
|
2
|
-
import { useRuntimeConfig } from "
|
|
1
|
+
import { defineEventHandler } from "h3";
|
|
2
|
+
import { useRuntimeConfig } from "nitro/runtime";
|
|
3
3
|
|
|
4
4
|
//#region src/routes/health.ts
|
|
5
5
|
var health_default = defineEventHandler(async (event) => {
|
|
6
6
|
const runtime = useRuntimeConfig();
|
|
7
7
|
if (!runtime.graphql || !runtime.graphql.endpoint?.graphql) {
|
|
8
|
-
|
|
8
|
+
event.res.status = 404;
|
|
9
|
+
event.res.statusText = "Not Found";
|
|
9
10
|
return {
|
|
10
11
|
status: "error",
|
|
11
12
|
message: "GraphQL health check endpoint is not configured",
|
|
@@ -31,7 +32,8 @@ var health_default = defineEventHandler(async (event) => {
|
|
|
31
32
|
};
|
|
32
33
|
throw new Error("Invalid response from GraphQL server");
|
|
33
34
|
} catch (error) {
|
|
34
|
-
|
|
35
|
+
event.res.status = 503;
|
|
36
|
+
event.res.statusText = "Service Unavailable";
|
|
35
37
|
return {
|
|
36
38
|
status: "unhealthy",
|
|
37
39
|
message: error instanceof Error ? error.message : "GraphQL server is not responding",
|
package/dist/types/index.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ interface GenImport {
|
|
|
27
27
|
imports: IESMImport[];
|
|
28
28
|
options?: ESMCodeGenOptions;
|
|
29
29
|
}
|
|
30
|
-
declare module '
|
|
30
|
+
declare module 'nitro/types' {
|
|
31
31
|
interface Nitro {
|
|
32
32
|
scanSchemas: string[];
|
|
33
33
|
scanDocuments: string[];
|
|
@@ -46,7 +46,7 @@ declare module 'nitropack/types' {
|
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
-
declare module '
|
|
49
|
+
declare module 'nitro/types' {
|
|
50
50
|
interface NitroOptions {
|
|
51
51
|
graphql?: NitroGraphQLOptions;
|
|
52
52
|
}
|
package/dist/utils/apollo.js
CHANGED
|
@@ -49,13 +49,12 @@ function normalizeQueryString(url) {
|
|
|
49
49
|
return url.split("?")[1] || "";
|
|
50
50
|
}
|
|
51
51
|
async function normalizeBody(event) {
|
|
52
|
-
|
|
52
|
+
if (isMethod(event, [
|
|
53
53
|
"PATCH",
|
|
54
54
|
"POST",
|
|
55
55
|
"PUT",
|
|
56
56
|
"DELETE"
|
|
57
|
-
];
|
|
58
|
-
if (isMethod(event, PayloadMethods)) return await readBody(event);
|
|
57
|
+
])) return await readBody(event);
|
|
59
58
|
}
|
|
60
59
|
|
|
61
60
|
//#endregion
|
|
@@ -29,8 +29,7 @@ function pluginContent(_schema, _documents, _config, _info) {
|
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
31
|
async function graphQLLoadSchemaSync(schemaPointers, data = {}) {
|
|
32
|
-
const
|
|
33
|
-
const filteredPointers = [...pointers, "!**/vfs/**"];
|
|
32
|
+
const filteredPointers = [...Array.isArray(schemaPointers) ? schemaPointers : [schemaPointers], "!**/vfs/**"];
|
|
34
33
|
let result;
|
|
35
34
|
try {
|
|
36
35
|
result = loadSchemaSync(filteredPointers, {
|
|
@@ -58,8 +57,7 @@ async function loadExternalSchema(service, buildDir) {
|
|
|
58
57
|
const defaultPath = resolve(buildDir, "graphql", "schemas", `${service.name}.graphql`);
|
|
59
58
|
const schemaFilePath = service.downloadPath ? resolve(service.downloadPath) : defaultPath;
|
|
60
59
|
if (existsSync(schemaFilePath)) try {
|
|
61
|
-
|
|
62
|
-
return result$1;
|
|
60
|
+
return loadSchemaSync([schemaFilePath], { loaders: [new GraphQLFileLoader()] });
|
|
63
61
|
} catch {
|
|
64
62
|
consola$1.warn(`[graphql:${service.name}] Cached schema invalid, loading from source`);
|
|
65
63
|
}
|
|
@@ -70,14 +68,13 @@ async function loadExternalSchema(service, buildDir) {
|
|
|
70
68
|
if (hasLocalFiles) loaders.push(new GraphQLFileLoader());
|
|
71
69
|
if (hasUrls) loaders.push(new UrlLoader());
|
|
72
70
|
if (loaders.length === 0) throw new Error("No appropriate loaders found for schema sources");
|
|
73
|
-
|
|
71
|
+
return loadSchemaSync(schemas, {
|
|
74
72
|
loaders,
|
|
75
73
|
...Object.keys(headers).length > 0 && { headers }
|
|
76
74
|
});
|
|
77
|
-
return result;
|
|
78
75
|
} catch (error) {
|
|
79
76
|
consola$1.error(`[graphql:${service.name}] Failed to load external schema:`, error);
|
|
80
|
-
return
|
|
77
|
+
return;
|
|
81
78
|
}
|
|
82
79
|
}
|
|
83
80
|
/**
|
|
@@ -91,7 +88,7 @@ function isUrl(path) {
|
|
|
91
88
|
*/
|
|
92
89
|
async function downloadAndSaveSchema(service, buildDir) {
|
|
93
90
|
const downloadMode = service.downloadSchema;
|
|
94
|
-
if (!downloadMode || downloadMode === "manual") return
|
|
91
|
+
if (!downloadMode || downloadMode === "manual") return;
|
|
95
92
|
const defaultPath = resolve(buildDir, "graphql", "schemas", `${service.name}.graphql`);
|
|
96
93
|
const schemaFilePath = service.downloadPath ? resolve(service.downloadPath) : defaultPath;
|
|
97
94
|
try {
|
|
@@ -104,15 +101,13 @@ async function downloadAndSaveSchema(service, buildDir) {
|
|
|
104
101
|
if (downloadMode === "always") {
|
|
105
102
|
shouldDownload = true;
|
|
106
103
|
if (fileExists && hasUrlSchemas) try {
|
|
107
|
-
const
|
|
104
|
+
const remoteSchemaString = printSchemaWithDirectives(loadSchemaSync(schemas.filter(isUrl), {
|
|
108
105
|
loaders: [new UrlLoader()],
|
|
109
106
|
...Object.keys(headers).length > 0 && { headers }
|
|
110
|
-
});
|
|
111
|
-
const remoteSchemaString = printSchemaWithDirectives(remoteSchema);
|
|
107
|
+
}));
|
|
112
108
|
const remoteHash = createHash("md5").update(remoteSchemaString).digest("hex");
|
|
113
109
|
const localSchemaString = readFileSync(schemaFilePath, "utf-8");
|
|
114
|
-
|
|
115
|
-
if (remoteHash === localHash) {
|
|
110
|
+
if (remoteHash === createHash("md5").update(localSchemaString).digest("hex")) {
|
|
116
111
|
shouldDownload = false;
|
|
117
112
|
consola$1.info(`[graphql:${service.name}] Schema is up-to-date, using cached version`);
|
|
118
113
|
}
|
|
@@ -137,24 +132,21 @@ async function downloadAndSaveSchema(service, buildDir) {
|
|
|
137
132
|
} else if (downloadMode === true || downloadMode === "once") shouldDownload = !fileExists;
|
|
138
133
|
if (shouldDownload) {
|
|
139
134
|
if (hasUrlSchemas && hasLocalSchemas) {
|
|
140
|
-
const
|
|
135
|
+
const schemaString = printSchemaWithDirectives(loadSchemaSync(schemas, {
|
|
141
136
|
loaders: [new GraphQLFileLoader(), new UrlLoader()],
|
|
142
137
|
...Object.keys(headers).length > 0 && { headers }
|
|
143
|
-
});
|
|
144
|
-
const schemaString = printSchemaWithDirectives(schema);
|
|
138
|
+
}));
|
|
145
139
|
mkdirSync(dirname(schemaFilePath), { recursive: true });
|
|
146
140
|
writeFileSync(schemaFilePath, schemaString, "utf-8");
|
|
147
141
|
} else if (hasUrlSchemas) {
|
|
148
|
-
const
|
|
142
|
+
const schemaString = printSchemaWithDirectives(loadSchemaSync(schemas, {
|
|
149
143
|
loaders: [new UrlLoader()],
|
|
150
144
|
...Object.keys(headers).length > 0 && { headers }
|
|
151
|
-
});
|
|
152
|
-
const schemaString = printSchemaWithDirectives(schema);
|
|
145
|
+
}));
|
|
153
146
|
mkdirSync(dirname(schemaFilePath), { recursive: true });
|
|
154
147
|
writeFileSync(schemaFilePath, schemaString, "utf-8");
|
|
155
148
|
} else if (hasLocalSchemas) {
|
|
156
|
-
const
|
|
157
|
-
const schemaString = printSchemaWithDirectives(schema);
|
|
149
|
+
const schemaString = printSchemaWithDirectives(loadSchemaSync(schemas, { loaders: [new GraphQLFileLoader()] }));
|
|
158
150
|
mkdirSync(dirname(schemaFilePath), { recursive: true });
|
|
159
151
|
writeFileSync(schemaFilePath, schemaString, "utf-8");
|
|
160
152
|
}
|
|
@@ -162,13 +154,12 @@ async function downloadAndSaveSchema(service, buildDir) {
|
|
|
162
154
|
return schemaFilePath;
|
|
163
155
|
} catch (error) {
|
|
164
156
|
consola$1.error(`[graphql:${service.name}] Failed to download/copy schema:`, error);
|
|
165
|
-
return
|
|
157
|
+
return;
|
|
166
158
|
}
|
|
167
159
|
}
|
|
168
160
|
async function loadGraphQLDocuments(patterns) {
|
|
169
161
|
try {
|
|
170
|
-
|
|
171
|
-
return result;
|
|
162
|
+
return await loadDocuments(patterns, { loaders: [new GraphQLFileLoader()] });
|
|
172
163
|
} catch (e) {
|
|
173
164
|
if ((e.message || "").includes("Unable to find any GraphQL type definitions for the following pointers:")) return [];
|
|
174
165
|
else throw e;
|
|
@@ -180,7 +171,7 @@ async function generateClientTypes(schema, docs, config = {}, sdkConfig = {}, ou
|
|
|
180
171
|
return false;
|
|
181
172
|
}
|
|
182
173
|
const serviceLabel = serviceName ? `:${serviceName}` : "";
|
|
183
|
-
const
|
|
174
|
+
const mergedConfig = defu$1({
|
|
184
175
|
emitLegacyCommonJSImports: false,
|
|
185
176
|
useTypeImports: true,
|
|
186
177
|
enumsAsTypes: true,
|
|
@@ -204,12 +195,11 @@ async function generateClientTypes(schema, docs, config = {}, sdkConfig = {}, ou
|
|
|
204
195
|
output: "File"
|
|
205
196
|
}
|
|
206
197
|
}
|
|
207
|
-
};
|
|
208
|
-
const mergedConfig = defu$1(defaultConfig, config);
|
|
198
|
+
}, config);
|
|
209
199
|
const mergedSdkConfig = defu$1(mergedConfig, sdkConfig);
|
|
210
200
|
try {
|
|
211
|
-
if (docs.length === 0) {
|
|
212
|
-
|
|
201
|
+
if (docs.length === 0) return {
|
|
202
|
+
types: await codegen({
|
|
213
203
|
filename: outputPath || "client-types.generated.ts",
|
|
214
204
|
schema: parse(printSchemaWithDirectives(schema)),
|
|
215
205
|
documents: [],
|
|
@@ -219,8 +209,8 @@ async function generateClientTypes(schema, docs, config = {}, sdkConfig = {}, ou
|
|
|
219
209
|
pluginContent: { plugin: pluginContent },
|
|
220
210
|
typescript: { plugin }
|
|
221
211
|
}
|
|
222
|
-
})
|
|
223
|
-
|
|
212
|
+
}),
|
|
213
|
+
sdk: `// THIS FILE IS GENERATED, DO NOT EDIT!
|
|
224
214
|
/* eslint-disable eslint-comments/no-unlimited-disable */
|
|
225
215
|
/* tslint:disable */
|
|
226
216
|
/* eslint-disable */
|
|
@@ -244,12 +234,8 @@ export function getSdk(requester: Requester): Sdk {
|
|
|
244
234
|
}
|
|
245
235
|
}
|
|
246
236
|
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
types: output$1,
|
|
250
|
-
sdk: sdkContent$1
|
|
251
|
-
};
|
|
252
|
-
}
|
|
237
|
+
`
|
|
238
|
+
};
|
|
253
239
|
const output = await codegen({
|
|
254
240
|
filename: outputPath || "client-types.generated.ts",
|
|
255
241
|
schema: parse(printSchemaWithDirectives(schema)),
|
|
@@ -279,16 +265,14 @@ export function getSdk(requester: Requester): Sdk {
|
|
|
279
265
|
typescriptGenericSdk: { plugin: plugin$1 }
|
|
280
266
|
}
|
|
281
267
|
});
|
|
282
|
-
const results = await Promise.all(sdkOutput.map(async (config$1) => {
|
|
283
|
-
return {
|
|
284
|
-
file: config$1.filename,
|
|
285
|
-
content: await codegen(config$1)
|
|
286
|
-
};
|
|
287
|
-
}));
|
|
288
|
-
const sdkContent = results[0]?.content || "";
|
|
289
268
|
return {
|
|
290
269
|
types: output,
|
|
291
|
-
sdk:
|
|
270
|
+
sdk: (await Promise.all(sdkOutput.map(async (config$1) => {
|
|
271
|
+
return {
|
|
272
|
+
file: config$1.filename,
|
|
273
|
+
content: await codegen(config$1)
|
|
274
|
+
};
|
|
275
|
+
})))[0]?.content || ""
|
|
292
276
|
};
|
|
293
277
|
} catch (error) {
|
|
294
278
|
consola$1.warn(`[graphql${serviceLabel}] Client type generation failed:`, error);
|
|
@@ -299,9 +283,7 @@ export function getSdk(requester: Requester): Sdk {
|
|
|
299
283
|
* Generate client types for external GraphQL service
|
|
300
284
|
*/
|
|
301
285
|
async function generateExternalClientTypes(service, schema, docs) {
|
|
302
|
-
|
|
303
|
-
const sdkConfig = service.codegen?.clientSDK || {};
|
|
304
|
-
return generateClientTypes(schema, docs, config, sdkConfig, void 0, service.name);
|
|
286
|
+
return generateClientTypes(schema, docs, service.codegen?.client || {}, service.codegen?.clientSDK || {}, void 0, service.name);
|
|
305
287
|
}
|
|
306
288
|
|
|
307
289
|
//#endregion
|
|
@@ -109,14 +109,12 @@ var DirectiveParser = class {
|
|
|
109
109
|
*/
|
|
110
110
|
extractStringLiteral(node) {
|
|
111
111
|
if (node?.type === "Literal" && typeof node.value === "string") return node.value;
|
|
112
|
-
return void 0;
|
|
113
112
|
}
|
|
114
113
|
/**
|
|
115
114
|
* Extract boolean literal value
|
|
116
115
|
*/
|
|
117
116
|
extractBooleanLiteral(node) {
|
|
118
117
|
if (node?.type === "Literal" && typeof node.value === "boolean") return node.value;
|
|
119
|
-
return void 0;
|
|
120
118
|
}
|
|
121
119
|
/**
|
|
122
120
|
* Extract array of strings
|
|
@@ -169,7 +167,6 @@ var DirectiveParser = class {
|
|
|
169
167
|
*/
|
|
170
168
|
extractLiteralValue(node) {
|
|
171
169
|
if (node?.type === "Literal") return node.value;
|
|
172
|
-
return void 0;
|
|
173
170
|
}
|
|
174
171
|
};
|
|
175
172
|
/**
|
|
@@ -177,15 +174,12 @@ var DirectiveParser = class {
|
|
|
177
174
|
*/
|
|
178
175
|
function generateDirectiveSchema(directive) {
|
|
179
176
|
let args = "";
|
|
180
|
-
if (directive.args && Object.keys(directive.args).length > 0) {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
});
|
|
187
|
-
args = `(${argDefs.join(", ")})`;
|
|
188
|
-
}
|
|
177
|
+
if (directive.args && Object.keys(directive.args).length > 0) args = `(${Object.entries(directive.args).map(([name, arg]) => {
|
|
178
|
+
let defaultValue = "";
|
|
179
|
+
if (arg.defaultValue !== void 0) if (typeof arg.defaultValue === "string") defaultValue = ` = "${arg.defaultValue}"`;
|
|
180
|
+
else defaultValue = ` = ${arg.defaultValue}`;
|
|
181
|
+
return `${name}: ${arg.type}${defaultValue}`;
|
|
182
|
+
}).join(", ")})`;
|
|
189
183
|
const locations = directive.locations.join(" | ");
|
|
190
184
|
return `directive @${directive.name}${args} on ${locations}`;
|
|
191
185
|
}
|
|
@@ -220,10 +214,7 @@ ${directiveSchemas.join("\n\n")}`;
|
|
|
220
214
|
const targetDir = dirname(directivesPath);
|
|
221
215
|
if (!existsSync(targetDir)) mkdirSync(targetDir, { recursive: true });
|
|
222
216
|
let shouldWrite = true;
|
|
223
|
-
if (existsSync(directivesPath))
|
|
224
|
-
const existingContent = readFileSync(directivesPath, "utf-8");
|
|
225
|
-
shouldWrite = existingContent !== content;
|
|
226
|
-
}
|
|
217
|
+
if (existsSync(directivesPath)) shouldWrite = readFileSync(directivesPath, "utf-8") !== content;
|
|
227
218
|
if (shouldWrite) writeFileSync(directivesPath, content, "utf-8");
|
|
228
219
|
if (!nitro.scanSchemas.includes(directivesPath)) nitro.scanSchemas.push(directivesPath);
|
|
229
220
|
}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { GenImport } from "../types/index.js";
|
|
2
2
|
import { directiveParser, generateDirectiveSchema, generateDirectiveSchemas } from "./directive-parser.js";
|
|
3
|
-
import { Nitro } from "
|
|
3
|
+
import { Nitro } from "nitro/types";
|
|
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}";
|
package/dist/utils/index.js
CHANGED
|
@@ -44,8 +44,7 @@ function relativeWithDot(from, to) {
|
|
|
44
44
|
return RELATIVE_RE.test(rel) ? rel : `./${rel}`;
|
|
45
45
|
}
|
|
46
46
|
async function scanGraphql(nitro) {
|
|
47
|
-
|
|
48
|
-
return files.map((f) => f.fullPath);
|
|
47
|
+
return (await scanFiles(nitro, "graphql")).map((f) => f.fullPath);
|
|
49
48
|
}
|
|
50
49
|
async function scanResolvers(nitro) {
|
|
51
50
|
const files = await scanFiles(nitro, "graphql", "**/*.resolver.{ts,js}");
|
|
@@ -123,12 +122,10 @@ async function scanDirectives(nitro) {
|
|
|
123
122
|
return exportName;
|
|
124
123
|
}
|
|
125
124
|
async function scanTypeDefs(nitro) {
|
|
126
|
-
|
|
127
|
-
return files.map((f) => f.fullPath);
|
|
125
|
+
return (await scanFiles(nitro, "graphql", "**/*.typedef.{ts,js}")).map((f) => f.fullPath);
|
|
128
126
|
}
|
|
129
127
|
async function scanSchemas(nitro) {
|
|
130
|
-
|
|
131
|
-
return files.map((f) => f.fullPath);
|
|
128
|
+
return (await scanFiles(nitro, "graphql", "**/*.graphql")).map((f) => f.fullPath);
|
|
132
129
|
}
|
|
133
130
|
async function scanDocs(nitro) {
|
|
134
131
|
const files = await scanDir(nitro, nitro.options.rootDir, nitro.graphql.dir.client, "**/*.graphql");
|
|
@@ -141,16 +138,12 @@ async function scanDocs(nitro) {
|
|
|
141
138
|
seenPaths.add(file.fullPath);
|
|
142
139
|
return true;
|
|
143
140
|
});
|
|
144
|
-
const
|
|
145
|
-
const externalPatterns = externalServices.flatMap((service) => service.documents || []);
|
|
141
|
+
const externalPatterns = (nitro.options.graphql?.externalServices || []).flatMap((service) => service.documents || []);
|
|
146
142
|
return allFiles.filter((f) => !f.path.startsWith("external/")).filter((f) => {
|
|
147
143
|
const relativePath = f.path;
|
|
148
144
|
for (const pattern of externalPatterns) {
|
|
149
145
|
const clientDirPattern = `${nitro.graphql.dir.client}/`;
|
|
150
|
-
|
|
151
|
-
const patternDir = cleanPattern.split("/")[0];
|
|
152
|
-
const fileDir = relativePath.split("/")[0];
|
|
153
|
-
if (patternDir === fileDir) return false;
|
|
146
|
+
if (pattern.replace(/* @__PURE__ */ new RegExp(`^${clientDirPattern.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}`), "").split("/")[0] === relativePath.split("/")[0]) return false;
|
|
154
147
|
}
|
|
155
148
|
return true;
|
|
156
149
|
}).map((f) => f.fullPath);
|
|
@@ -213,7 +206,7 @@ async function scanFiles(nitro, name, globPattern = GLOB_SCAN_PATTERN) {
|
|
|
213
206
|
});
|
|
214
207
|
}
|
|
215
208
|
async function scanDir(nitro, dir, name, globPattern = GLOB_SCAN_PATTERN) {
|
|
216
|
-
|
|
209
|
+
return (await glob(join(name, globPattern), {
|
|
217
210
|
cwd: dir,
|
|
218
211
|
dot: true,
|
|
219
212
|
ignore: nitro.options.ignore,
|
|
@@ -224,8 +217,7 @@ async function scanDir(nitro, dir, name, globPattern = GLOB_SCAN_PATTERN) {
|
|
|
224
217
|
return [];
|
|
225
218
|
}
|
|
226
219
|
throw error;
|
|
227
|
-
})
|
|
228
|
-
return fileNames.map((fullPath) => {
|
|
220
|
+
})).map((fullPath) => {
|
|
229
221
|
return {
|
|
230
222
|
fullPath,
|
|
231
223
|
path: relative(join(dir, name), fullPath)
|
|
@@ -21,7 +21,7 @@ function pluginContent(_schema, _documents, _config, _info) {
|
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
23
|
async function generateTypes(selectFremework, schema, config = {}, outputPath) {
|
|
24
|
-
const
|
|
24
|
+
const mergedConfig = defu$1({
|
|
25
25
|
scalars: {
|
|
26
26
|
DateTime: DateTimeResolver.extensions.codegenScalarType,
|
|
27
27
|
DateTimeISO: DateTimeISOResolver.extensions.codegenScalarType,
|
|
@@ -43,9 +43,8 @@ async function generateTypes(selectFremework, schema, config = {}, outputPath) {
|
|
|
43
43
|
declarationKind: "interface",
|
|
44
44
|
enumsAsTypes: true,
|
|
45
45
|
...config.federation?.enabled && { federation: true }
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const output = await codegen({
|
|
46
|
+
}, config.codegen?.server);
|
|
47
|
+
return await codegen({
|
|
49
48
|
filename: outputPath || "types.generated.ts",
|
|
50
49
|
schema: parse(printSchemaWithDirectives(schema)),
|
|
51
50
|
documents: [],
|
|
@@ -131,7 +130,6 @@ type ResolverReturnTypeObject<T extends object> =
|
|
|
131
130
|
consola.withTag("graphql").error("Error generating types:", e);
|
|
132
131
|
return "";
|
|
133
132
|
});
|
|
134
|
-
return output;
|
|
135
133
|
}
|
|
136
134
|
|
|
137
135
|
//#endregion
|
|
@@ -31,8 +31,7 @@ function generateNuxtOfetchClient(clientDir, serviceName = "default") {
|
|
|
31
31
|
const serviceDir = resolve(clientDir, serviceName);
|
|
32
32
|
const ofetchPath = resolve(serviceDir, "ofetch.ts");
|
|
33
33
|
if (!existsSync(serviceDir)) mkdirSync(serviceDir, { recursive: true });
|
|
34
|
-
if (!existsSync(ofetchPath))
|
|
35
|
-
const ofetchContent = `// This file is auto-generated once by nitro-graphql for quick start
|
|
34
|
+
if (!existsSync(ofetchPath)) writeFileSync(ofetchPath, `// This file is auto-generated once by nitro-graphql for quick start
|
|
36
35
|
// You can modify this file according to your needs
|
|
37
36
|
import type { Requester } from './sdk'
|
|
38
37
|
import { getSdk } from './sdk'
|
|
@@ -54,9 +53,7 @@ export function createGraphQLClient(endpoint: string): Requester {
|
|
|
54
53
|
}
|
|
55
54
|
}
|
|
56
55
|
|
|
57
|
-
export const $sdk = getSdk(createGraphQLClient('/api/graphql'))
|
|
58
|
-
writeFileSync(ofetchPath, ofetchContent, "utf-8");
|
|
59
|
-
}
|
|
56
|
+
export const $sdk = getSdk(createGraphQLClient('/api/graphql'))`, "utf-8");
|
|
60
57
|
}
|
|
61
58
|
function generateExternalOfetchClient(clientDir, serviceName, endpoint) {
|
|
62
59
|
const serviceDir = resolve(clientDir, serviceName);
|
|
@@ -64,7 +61,7 @@ function generateExternalOfetchClient(clientDir, serviceName, endpoint) {
|
|
|
64
61
|
if (!existsSync(serviceDir)) mkdirSync(serviceDir, { recursive: true });
|
|
65
62
|
if (!existsSync(ofetchPath)) {
|
|
66
63
|
const capitalizedServiceName = serviceName.charAt(0).toUpperCase() + serviceName.slice(1);
|
|
67
|
-
|
|
64
|
+
writeFileSync(ofetchPath, `// This file is auto-generated once by nitro-graphql for quick start
|
|
68
65
|
// You can modify this file according to your needs
|
|
69
66
|
import type { Sdk, Requester } from './sdk'
|
|
70
67
|
import { getSdk } from './sdk'
|
|
@@ -86,8 +83,7 @@ export function create${capitalizedServiceName}GraphQLClient(endpoint: string =
|
|
|
86
83
|
}
|
|
87
84
|
}
|
|
88
85
|
|
|
89
|
-
export const $${serviceName}Sdk: Sdk = getSdk(create${capitalizedServiceName}GraphQLClient())
|
|
90
|
-
writeFileSync(ofetchPath, ofetchContent, "utf-8");
|
|
86
|
+
export const $${serviceName}Sdk: Sdk = getSdk(create${capitalizedServiceName}GraphQLClient())`, "utf-8");
|
|
91
87
|
}
|
|
92
88
|
}
|
|
93
89
|
/**
|
|
@@ -127,8 +123,7 @@ function validateNoDuplicateTypes(schemas, schemaStrings) {
|
|
|
127
123
|
schemaStrings.forEach((schemaContent, index) => {
|
|
128
124
|
const fileName = basename(schemas[index]);
|
|
129
125
|
try {
|
|
130
|
-
|
|
131
|
-
document.definitions.forEach((def) => {
|
|
126
|
+
parse(schemaContent).definitions.forEach((def) => {
|
|
132
127
|
if (def.kind === "ObjectTypeDefinition" || def.kind === "InterfaceTypeDefinition" || def.kind === "UnionTypeDefinition" || def.kind === "EnumTypeDefinition" || def.kind === "InputObjectTypeDefinition" || def.kind === "ScalarTypeDefinition") {
|
|
133
128
|
const typeName = def.name.value;
|
|
134
129
|
if ([
|
|
@@ -148,8 +143,7 @@ function validateNoDuplicateTypes(schemas, schemaStrings) {
|
|
|
148
143
|
const content = schemaStrings[i];
|
|
149
144
|
if (!content) return false;
|
|
150
145
|
try {
|
|
151
|
-
|
|
152
|
-
return doc.definitions.some((d) => (d.kind === "ObjectTypeDefinition" || d.kind === "InterfaceTypeDefinition" || d.kind === "UnionTypeDefinition" || d.kind === "EnumTypeDefinition" || d.kind === "InputObjectTypeDefinition" || d.kind === "ScalarTypeDefinition") && d.name.value === typeName);
|
|
146
|
+
return parse(content).definitions.some((d) => (d.kind === "ObjectTypeDefinition" || d.kind === "InterfaceTypeDefinition" || d.kind === "UnionTypeDefinition" || d.kind === "EnumTypeDefinition" || d.kind === "InputObjectTypeDefinition" || d.kind === "ScalarTypeDefinition") && d.name.value === typeName);
|
|
153
147
|
} catch {
|
|
154
148
|
return false;
|
|
155
149
|
}
|
|
@@ -189,10 +183,8 @@ async function serverTypeGeneration(app) {
|
|
|
189
183
|
consola.info("No GraphQL definitions found for server type generation.");
|
|
190
184
|
return;
|
|
191
185
|
}
|
|
192
|
-
const
|
|
193
|
-
|
|
194
|
-
const isValid = validateNoDuplicateTypes(schemas, schemaStrings);
|
|
195
|
-
if (!isValid) return;
|
|
186
|
+
const schemaStrings = loadFilesSync(schemas).map((schema$1) => typeof schema$1 === "string" ? schema$1 : schema$1.loc?.source?.body || "").filter(Boolean);
|
|
187
|
+
if (!validateNoDuplicateTypes(schemas, schemaStrings)) return;
|
|
196
188
|
const federationEnabled = app.options.graphql?.federation?.enabled === true;
|
|
197
189
|
const mergedSchemas = mergeTypeDefs([schemaStrings.join("\n\n")], {
|
|
198
190
|
throwOnConflict: true,
|
|
@@ -214,8 +206,7 @@ async function serverTypeGeneration(app) {
|
|
|
214
206
|
}
|
|
215
207
|
async function clientTypeGeneration(nitro) {
|
|
216
208
|
try {
|
|
217
|
-
|
|
218
|
-
if (hasServerSchema) await generateMainClientTypes(nitro);
|
|
209
|
+
if (nitro.scanSchemas && nitro.scanSchemas.length > 0) await generateMainClientTypes(nitro);
|
|
219
210
|
if (nitro.options.graphql?.externalServices?.length) await generateExternalServicesTypes(nitro);
|
|
220
211
|
} catch (error) {
|
|
221
212
|
consola.error("Client schema generation error:", error);
|
|
@@ -259,9 +250,7 @@ async function generateMainClientTypes(nitro) {
|
|
|
259
250
|
return;
|
|
260
251
|
}
|
|
261
252
|
const graphqlString = readFileSync(schemaFilePath, "utf-8");
|
|
262
|
-
const
|
|
263
|
-
const schema = federationEnabled ? buildSubgraphSchema([{ typeDefs: parse(graphqlString) }]) : buildSchema(graphqlString);
|
|
264
|
-
const types = await generateClientTypes(schema, loadDocs, nitro.options.graphql?.codegen?.client ?? {}, nitro.options.graphql?.codegen?.clientSDK ?? {});
|
|
253
|
+
const types = await generateClientTypes(nitro.options.graphql?.federation?.enabled === true ? buildSubgraphSchema([{ typeDefs: parse(graphqlString) }]) : buildSchema(graphqlString), loadDocs, nitro.options.graphql?.codegen?.client ?? {}, nitro.options.graphql?.codegen?.clientSDK ?? {});
|
|
265
254
|
if (types === false) return;
|
|
266
255
|
const clientTypesPath = resolve(nitro.options.buildDir, "types", "nitro-graphql-client.d.ts");
|
|
267
256
|
const defaultServiceDir = resolve(nitro.graphql.clientDir, "default");
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nitro-graphql",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "2.0.0-beta.1",
|
|
5
5
|
"description": "GraphQL integration for Nitro",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"sideEffects": false,
|
|
@@ -60,20 +60,16 @@
|
|
|
60
60
|
],
|
|
61
61
|
"peerDependencies": {
|
|
62
62
|
"@apollo/server": "^5.0.0",
|
|
63
|
-
"@apollo/subgraph": "^2.0.0",
|
|
64
63
|
"@apollo/utils.withrequired": "^3.0.0",
|
|
65
64
|
"@as-integrations/h3": "^2.0.0",
|
|
66
65
|
"graphql": "^16.11.0",
|
|
67
|
-
"h3": "^1.
|
|
68
|
-
"
|
|
66
|
+
"h3": "^2.0.1-rc.2",
|
|
67
|
+
"nitro": "^3.0.1-alpha.0"
|
|
69
68
|
},
|
|
70
69
|
"peerDependenciesMeta": {
|
|
71
70
|
"@apollo/server": {
|
|
72
71
|
"optional": true
|
|
73
72
|
},
|
|
74
|
-
"@apollo/subgraph": {
|
|
75
|
-
"optional": true
|
|
76
|
-
},
|
|
77
73
|
"@apollo/utils.withrequired": {
|
|
78
74
|
"optional": true
|
|
79
75
|
},
|
|
@@ -82,18 +78,19 @@
|
|
|
82
78
|
}
|
|
83
79
|
},
|
|
84
80
|
"dependencies": {
|
|
85
|
-
"@
|
|
81
|
+
"@apollo/subgraph": "^2.11.2",
|
|
82
|
+
"@graphql-codegen/core": "^5.0.0",
|
|
86
83
|
"@graphql-codegen/import-types-preset": "^3.0.1",
|
|
87
|
-
"@graphql-codegen/typescript": "^
|
|
84
|
+
"@graphql-codegen/typescript": "^5.0.1",
|
|
88
85
|
"@graphql-codegen/typescript-generic-sdk": "^4.0.2",
|
|
89
|
-
"@graphql-codegen/typescript-operations": "^
|
|
90
|
-
"@graphql-codegen/typescript-resolvers": "^
|
|
91
|
-
"@graphql-tools/graphql-file-loader": "^8.1.
|
|
86
|
+
"@graphql-codegen/typescript-operations": "^5.0.1",
|
|
87
|
+
"@graphql-codegen/typescript-resolvers": "^5.0.1",
|
|
88
|
+
"@graphql-tools/graphql-file-loader": "^8.1.2",
|
|
92
89
|
"@graphql-tools/load": "^8.1.2",
|
|
93
90
|
"@graphql-tools/load-files": "^7.0.1",
|
|
94
91
|
"@graphql-tools/merge": "^9.1.1",
|
|
95
92
|
"@graphql-tools/schema": "^10.0.25",
|
|
96
|
-
"@graphql-tools/url-loader": "^
|
|
93
|
+
"@graphql-tools/url-loader": "^9.0.0",
|
|
97
94
|
"@graphql-tools/utils": "^10.9.1",
|
|
98
95
|
"chokidar": "^4.0.3",
|
|
99
96
|
"consola": "^3.4.2",
|
|
@@ -102,26 +99,25 @@
|
|
|
102
99
|
"graphql-scalars": "^1.24.2",
|
|
103
100
|
"knitwork": "^1.2.0",
|
|
104
101
|
"ohash": "^2.0.11",
|
|
105
|
-
"oxc-parser": "^0.
|
|
102
|
+
"oxc-parser": "^0.93.0",
|
|
106
103
|
"pathe": "^2.0.3",
|
|
107
|
-
"tinyglobby": "^0.2.
|
|
104
|
+
"tinyglobby": "^0.2.15"
|
|
108
105
|
},
|
|
109
106
|
"devDependencies": {
|
|
110
|
-
"@antfu/eslint-config": "^5.
|
|
111
|
-
"@
|
|
112
|
-
"@nuxt/
|
|
113
|
-
"@
|
|
114
|
-
"@types/node": "^22.18.1",
|
|
107
|
+
"@antfu/eslint-config": "^5.4.1",
|
|
108
|
+
"@nuxt/kit": "^4.1.2",
|
|
109
|
+
"@nuxt/schema": "^4.1.2",
|
|
110
|
+
"@types/node": "^24.6.2",
|
|
115
111
|
"bumpp": "^10.2.3",
|
|
116
112
|
"changelogen": "^0.6.2",
|
|
117
113
|
"crossws": "0.3.5",
|
|
118
|
-
"eslint": "^9.
|
|
114
|
+
"eslint": "^9.37.0",
|
|
119
115
|
"graphql": "16.11.0",
|
|
120
|
-
"graphql-yoga": "^5.
|
|
121
|
-
"h3": "1.
|
|
122
|
-
"
|
|
123
|
-
"tsdown": "^0.
|
|
124
|
-
"typescript": "^5.9.
|
|
116
|
+
"graphql-yoga": "^5.16.0",
|
|
117
|
+
"h3": "^2.0.1-rc.2",
|
|
118
|
+
"nitro": "^3.0.1-alpha.0",
|
|
119
|
+
"tsdown": "^0.15.6",
|
|
120
|
+
"typescript": "^5.9.3"
|
|
125
121
|
},
|
|
126
122
|
"resolutions": {
|
|
127
123
|
"nitro-graphql": "link:."
|