nitro-graphql 2.0.0-beta.26 → 2.0.0-beta.28
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 +1 -1
- package/dist/routes/apollo-server.d.mts +2 -2
- package/dist/routes/debug.d.mts +2 -2
- package/dist/routes/graphql-yoga.d.mts +2 -2
- package/dist/routes/health.d.mts +2 -2
- package/dist/setup.mjs +14 -3
- package/dist/utils/apollo.d.mts +1 -1
- package/dist/utils/type-generation.mjs +24 -3
- package/package.json +1 -5
package/README.md
CHANGED
|
@@ -61,7 +61,7 @@ pnpm add nitro-graphql@beta graphql-yoga graphql graphql-config
|
|
|
61
61
|
|
|
62
62
|
**Apollo Server:**
|
|
63
63
|
```bash
|
|
64
|
-
pnpm add nitro-graphql@beta @apollo/server
|
|
64
|
+
pnpm add nitro-graphql@beta @apollo/server graphql graphql-config
|
|
65
65
|
```
|
|
66
66
|
|
|
67
67
|
### 2. Configure
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as h31 from "h3";
|
|
2
2
|
|
|
3
3
|
//#region src/routes/apollo-server.d.ts
|
|
4
|
-
declare const _default:
|
|
4
|
+
declare const _default: h31.EventHandlerWithFetch<h31.EventHandlerRequest, Promise<any>>;
|
|
5
5
|
//#endregion
|
|
6
6
|
export { _default as default };
|
package/dist/routes/debug.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as h33 from "h3";
|
|
2
2
|
|
|
3
3
|
//#region src/routes/debug.d.ts
|
|
4
4
|
|
|
@@ -10,7 +10,7 @@ import * as h31 from "h3";
|
|
|
10
10
|
* - /_nitro/graphql/debug - HTML dashboard
|
|
11
11
|
* - /_nitro/graphql/debug?format=json - JSON API
|
|
12
12
|
*/
|
|
13
|
-
declare const _default:
|
|
13
|
+
declare const _default: h33.EventHandlerWithFetch<h33.EventHandlerRequest, Promise<string | {
|
|
14
14
|
timestamp: string;
|
|
15
15
|
environment: {
|
|
16
16
|
dev: any;
|
|
@@ -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.EventHandlerWithFetch<h30.EventHandlerRequest, Promise<Response>>;
|
|
5
5
|
//#endregion
|
|
6
6
|
export { _default as default };
|
package/dist/routes/health.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as h35 from "h3";
|
|
2
2
|
|
|
3
3
|
//#region src/routes/health.d.ts
|
|
4
|
-
declare const _default:
|
|
4
|
+
declare const _default: h35.EventHandlerWithFetch<h35.EventHandlerRequest, Promise<{
|
|
5
5
|
status: string;
|
|
6
6
|
message: string;
|
|
7
7
|
timestamp: string;
|
package/dist/setup.mjs
CHANGED
|
@@ -18,6 +18,12 @@ const logger = consola.withTag("nitro-graphql");
|
|
|
18
18
|
* Used by both the direct Nitro module export and the Vite plugin's nitro: hook
|
|
19
19
|
*/
|
|
20
20
|
async function setupNitroGraphQL(nitro) {
|
|
21
|
+
nitro.options.graphql ||= {};
|
|
22
|
+
nitro.options.graphql.types = defu(nitro.options.graphql.types, {
|
|
23
|
+
server: ".graphql/nitro-graphql-server.d.ts",
|
|
24
|
+
client: ".graphql/nitro-graphql-client.d.ts",
|
|
25
|
+
enabled: true
|
|
26
|
+
});
|
|
21
27
|
if (!nitro.options.graphql?.framework) logger.warn("No GraphQL framework specified. Please set graphql.framework to \"graphql-yoga\" or \"apollo-server\".");
|
|
22
28
|
if (nitro.options.graphql?.externalServices?.length) {
|
|
23
29
|
const validationErrors = validateExternalServices(nitro.options.graphql.externalServices);
|
|
@@ -43,12 +49,17 @@ async function setupNitroGraphQL(nitro) {
|
|
|
43
49
|
};
|
|
44
50
|
nitro.hooks.hook("rollup:before", (_, rollupConfig$1) => {
|
|
45
51
|
rollupConfig$1.external = rollupConfig$1.external || [];
|
|
46
|
-
const
|
|
47
|
-
if (
|
|
52
|
+
const allExternals = [...["oxc-parser", "@oxc-parser"]];
|
|
53
|
+
if (!nitro.options.graphql?.federation?.enabled) allExternals.push(...[
|
|
54
|
+
"@apollo/subgraph",
|
|
55
|
+
"@apollo/federation-internals",
|
|
56
|
+
"@apollo/cache-control-types"
|
|
57
|
+
]);
|
|
58
|
+
if (Array.isArray(rollupConfig$1.external)) rollupConfig$1.external.push(...allExternals);
|
|
48
59
|
else if (typeof rollupConfig$1.external === "function") {
|
|
49
60
|
const originalExternal = rollupConfig$1.external;
|
|
50
61
|
rollupConfig$1.external = (id, parent, isResolved) => {
|
|
51
|
-
if (
|
|
62
|
+
if (allExternals.some((external) => id.includes(external))) return true;
|
|
52
63
|
return originalExternal(id, parent, isResolved);
|
|
53
64
|
};
|
|
54
65
|
}
|
package/dist/utils/apollo.d.mts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ApolloServer, BaseContext, ContextFunction } from "@apollo/server";
|
|
2
2
|
import { EventHandler, H3Event } from "h3";
|
|
3
|
-
import { WithRequired } from "@apollo/utils.withrequired";
|
|
4
3
|
import { Hooks } from "crossws";
|
|
5
4
|
|
|
6
5
|
//#region src/utils/apollo.d.ts
|
|
6
|
+
type WithRequired<T, K extends keyof T> = T & { [P in K]-?: T[P] };
|
|
7
7
|
interface H3ContextFunctionArgument {
|
|
8
8
|
event: H3Event;
|
|
9
9
|
}
|
|
@@ -6,13 +6,22 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
|
6
6
|
import consola from "consola";
|
|
7
7
|
import { basename, dirname, join, resolve } from "pathe";
|
|
8
8
|
import { buildSchema, parse } from "graphql";
|
|
9
|
-
import { buildSubgraphSchema } from "@apollo/subgraph";
|
|
10
9
|
import { loadFilesSync } from "@graphql-tools/load-files";
|
|
11
10
|
import { mergeTypeDefs } from "@graphql-tools/merge";
|
|
12
11
|
import { printSchemaWithDirectives } from "@graphql-tools/utils";
|
|
13
12
|
|
|
14
13
|
//#region src/utils/type-generation.ts
|
|
15
14
|
const logger = consola.withTag("nitro-graphql");
|
|
15
|
+
let buildSubgraphSchema = null;
|
|
16
|
+
async function loadFederationSupport() {
|
|
17
|
+
if (buildSubgraphSchema !== null) return buildSubgraphSchema;
|
|
18
|
+
try {
|
|
19
|
+
buildSubgraphSchema = (await import("@apollo/subgraph")).buildSubgraphSchema;
|
|
20
|
+
} catch {
|
|
21
|
+
buildSubgraphSchema = false;
|
|
22
|
+
}
|
|
23
|
+
return buildSubgraphSchema;
|
|
24
|
+
}
|
|
16
25
|
function generateGraphQLIndexFile(nitro, clientDir, externalServices = []) {
|
|
17
26
|
if (!shouldGenerateClientUtils(nitro)) return;
|
|
18
27
|
const placeholders = getDefaultPaths(nitro);
|
|
@@ -258,7 +267,12 @@ async function serverTypeGeneration(app, options = {}) {
|
|
|
258
267
|
commentDescriptions: true,
|
|
259
268
|
sort: true
|
|
260
269
|
});
|
|
261
|
-
|
|
270
|
+
let schema;
|
|
271
|
+
if (federationEnabled) {
|
|
272
|
+
const buildSubgraph = await loadFederationSupport();
|
|
273
|
+
if (!buildSubgraph) throw new Error("Federation is enabled but @apollo/subgraph is not installed. Run: pnpm add @apollo/subgraph");
|
|
274
|
+
schema = buildSubgraph([{ typeDefs: parse(mergedSchemas) }]);
|
|
275
|
+
} else schema = buildSchema(mergedSchemas);
|
|
262
276
|
const data = await generateTypes(app.options.graphql?.framework || "graphql-yoga", schema, app.options.graphql ?? {});
|
|
263
277
|
const printSchema = printSchemaWithDirectives(schema);
|
|
264
278
|
const schemaPath = resolve(app.graphql.buildDir, "schema.graphql");
|
|
@@ -322,7 +336,14 @@ async function generateMainClientTypes(nitro, options = {}) {
|
|
|
322
336
|
return;
|
|
323
337
|
}
|
|
324
338
|
const graphqlString = readFileSync(schemaFilePath, "utf-8");
|
|
325
|
-
const
|
|
339
|
+
const federationEnabled = nitro.options.graphql?.federation?.enabled === true;
|
|
340
|
+
let schema;
|
|
341
|
+
if (federationEnabled) {
|
|
342
|
+
const buildSubgraph = await loadFederationSupport();
|
|
343
|
+
if (!buildSubgraph) throw new Error("Federation is enabled but @apollo/subgraph is not installed. Run: pnpm add @apollo/subgraph");
|
|
344
|
+
schema = buildSubgraph([{ typeDefs: parse(graphqlString) }]);
|
|
345
|
+
} else schema = buildSchema(graphqlString);
|
|
346
|
+
const types = await generateClientTypes(schema, loadDocs, nitro.options.graphql?.codegen?.client ?? {}, nitro.options.graphql?.codegen?.clientSDK ?? {}, void 0, void 0, void 0, options);
|
|
326
347
|
if (types === false) return;
|
|
327
348
|
const placeholders = getDefaultPaths(nitro);
|
|
328
349
|
const typesConfig = getTypesConfig(nitro);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nitro-graphql",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.28",
|
|
5
5
|
"description": "GraphQL integration for Nitro",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"sideEffects": false,
|
|
@@ -72,7 +72,6 @@
|
|
|
72
72
|
],
|
|
73
73
|
"peerDependencies": {
|
|
74
74
|
"@apollo/server": "^5.0.0",
|
|
75
|
-
"@apollo/utils.withrequired": "^3.0.0",
|
|
76
75
|
"graphql": "^16.11.0",
|
|
77
76
|
"h3": "^2.0.1-rc.2",
|
|
78
77
|
"nitro": "^3.0.1-alpha.0"
|
|
@@ -80,9 +79,6 @@
|
|
|
80
79
|
"peerDependenciesMeta": {
|
|
81
80
|
"@apollo/server": {
|
|
82
81
|
"optional": true
|
|
83
|
-
},
|
|
84
|
-
"@apollo/utils.withrequired": {
|
|
85
|
-
"optional": true
|
|
86
82
|
}
|
|
87
83
|
},
|
|
88
84
|
"dependencies": {
|