nitro-graphql 2.0.0-beta.26 → 2.0.0-beta.27

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 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 @apollo/utils.withrequired graphql graphql-config
64
+ pnpm add nitro-graphql@beta @apollo/server graphql graphql-config
65
65
  ```
66
66
 
67
67
  ### 2. Configure
@@ -1,4 +1,4 @@
1
- import * as h31 from "h3";
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: h31.EventHandlerWithFetch<h31.EventHandlerRequest, Promise<string | {
13
+ declare const _default: h33.EventHandlerWithFetch<h33.EventHandlerRequest, Promise<string | {
14
14
  timestamp: string;
15
15
  environment: {
16
16
  dev: any;
@@ -1,7 +1,7 @@
1
- import * as h33 from "h3";
1
+ import * as h31 from "h3";
2
2
 
3
3
  //#region src/routes/health.d.ts
4
- declare const _default: h33.EventHandlerWithFetch<h33.EventHandlerRequest, Promise<{
4
+ declare const _default: h31.EventHandlerWithFetch<h31.EventHandlerRequest, Promise<{
5
5
  status: string;
6
6
  message: string;
7
7
  timestamp: string;
package/dist/setup.mjs CHANGED
@@ -43,12 +43,17 @@ async function setupNitroGraphQL(nitro) {
43
43
  };
44
44
  nitro.hooks.hook("rollup:before", (_, rollupConfig$1) => {
45
45
  rollupConfig$1.external = rollupConfig$1.external || [];
46
- const codegenExternals = ["oxc-parser", "@oxc-parser"];
47
- if (Array.isArray(rollupConfig$1.external)) rollupConfig$1.external.push(...codegenExternals);
46
+ const allExternals = [...["oxc-parser", "@oxc-parser"]];
47
+ if (!nitro.options.graphql?.federation?.enabled) allExternals.push(...[
48
+ "@apollo/subgraph",
49
+ "@apollo/federation-internals",
50
+ "@apollo/cache-control-types"
51
+ ]);
52
+ if (Array.isArray(rollupConfig$1.external)) rollupConfig$1.external.push(...allExternals);
48
53
  else if (typeof rollupConfig$1.external === "function") {
49
54
  const originalExternal = rollupConfig$1.external;
50
55
  rollupConfig$1.external = (id, parent, isResolved) => {
51
- if (codegenExternals.some((external) => id.includes(external))) return true;
56
+ if (allExternals.some((external) => id.includes(external))) return true;
52
57
  return originalExternal(id, parent, isResolved);
53
58
  };
54
59
  }
@@ -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
- const schema = federationEnabled ? buildSubgraphSchema([{ typeDefs: parse(mergedSchemas) }]) : buildSchema(mergedSchemas);
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 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 ?? {}, void 0, void 0, void 0, options);
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.26",
4
+ "version": "2.0.0-beta.27",
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": {