nitro-graphql 0.0.7 → 0.0.9

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.
@@ -1,7 +1,7 @@
1
- import * as _nuxt_schema1 from "@nuxt/schema";
1
+ import * as _nuxt_schema5 from "@nuxt/schema";
2
2
 
3
3
  //#region src/ecosystem/nuxt.d.ts
4
4
  interface ModuleOptions {}
5
- declare const _default: _nuxt_schema1.NuxtModule<ModuleOptions, ModuleOptions, false>;
5
+ declare const _default: _nuxt_schema5.NuxtModule<ModuleOptions, ModuleOptions, false>;
6
6
  //#endregion
7
7
  export { ModuleOptions, _default as default };
package/dist/index.js CHANGED
@@ -5,6 +5,7 @@ import { defineGraphQLConfig, defineMutation, defineQuery, defineResolver, defin
5
5
  import { writeFileSync } from "node:fs";
6
6
  import { fileURLToPath } from "node:url";
7
7
  import { watch } from "chokidar";
8
+ import consola from "consola";
8
9
  import defu from "defu";
9
10
  import { defineNitroModule } from "nitropack/kit";
10
11
  import { dirname, join, resolve } from "pathe";
@@ -13,6 +14,10 @@ import { dirname, join, resolve } from "pathe";
13
14
  var src_default = defineNitroModule({
14
15
  name: "nitro-graphql",
15
16
  async setup(nitro) {
17
+ if (!nitro.options.graphql?.framework) {
18
+ consola.warn("No GraphQL framework specified. Please set graphql.framework to \"graphql-yoga\" or \"apollo-server\".");
19
+ return;
20
+ }
16
21
  nitro.graphql ||= {
17
22
  buildDir: "",
18
23
  watchDirs: [],
@@ -1,6 +1,6 @@
1
- import * as h34 from "h3";
1
+ import * as h33 from "h3";
2
2
 
3
3
  //#region src/routes/apollo-server.d.ts
4
- declare const _default: h34.EventHandler<h34.EventHandlerRequest, any>;
4
+ declare const _default: h33.EventHandler<h33.EventHandlerRequest, any>;
5
5
  //#endregion
6
6
  export { _default as default };
@@ -1,6 +1,6 @@
1
- import * as h32 from "h3";
1
+ import * as h31 from "h3";
2
2
 
3
3
  //#region src/routes/graphql-yoga.d.ts
4
- declare const _default: h32.EventHandler<h32.EventHandlerRequest, Promise<Response>>;
4
+ declare const _default: h31.EventHandler<h31.EventHandlerRequest, Promise<Response>>;
5
5
  //#endregion
6
6
  export { _default as default };
@@ -1,8 +1,8 @@
1
1
  import { preset } from "../node_modules/.pnpm/@graphql-codegen_import-types-preset@3.0.1_graphql@16.11.0/node_modules/@graphql-codegen/import-types-preset/esm/index.js";
2
+ import { consola as consola$1 } from "consola";
2
3
  import { defu as defu$1 } from "defu";
3
4
  import { parse } from "graphql";
4
5
  import { printSchemaWithDirectives } from "@graphql-tools/utils";
5
- import { consola as consola$1 } from "consola";
6
6
  import { codegen } from "@graphql-codegen/core";
7
7
  import { plugin } from "@graphql-codegen/typescript";
8
8
  import { plugin as plugin$1 } from "@graphql-codegen/typescript-generic-sdk";
@@ -1,7 +1,7 @@
1
+ import consola from "consola";
1
2
  import { defu as defu$1 } from "defu";
2
3
  import { parse } from "graphql";
3
4
  import { printSchemaWithDirectives } from "@graphql-tools/utils";
4
- import consola from "consola";
5
5
  import { codegen } from "@graphql-codegen/core";
6
6
  import * as typescriptPlugin from "@graphql-codegen/typescript";
7
7
  import * as typescriptResolversPlugin from "@graphql-codegen/typescript-resolvers";
@@ -1,17 +1,21 @@
1
1
  import { generateClientTypes, loadGraphQLDocuments } from "./client-codegen.js";
2
2
  import { generateTypes } from "./server-codegen.js";
3
- import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
3
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
4
+ import consola from "consola";
4
5
  import { dirname, join, resolve } from "pathe";
5
6
  import { buildASTSchema, buildSchema } from "graphql";
6
7
  import { loadFilesSync } from "@graphql-tools/load-files";
7
8
  import { mergeTypeDefs } from "@graphql-tools/merge";
8
9
  import { printSchemaWithDirectives } from "@graphql-tools/utils";
9
- import consola from "consola";
10
10
 
11
11
  //#region src/utils/server-type-generation.ts
12
12
  async function serverTypeGeneration(app) {
13
13
  try {
14
14
  const defs = app.scanDefs || [];
15
+ if (!defs.length) {
16
+ consola.info("No GraphQL definitions found for server type generation.");
17
+ return;
18
+ }
15
19
  const loadDefs = loadFilesSync(defs);
16
20
  const mergedDefs = mergeTypeDefs(loadDefs);
17
21
  const schema = buildASTSchema(mergedDefs, {
@@ -35,7 +39,12 @@ async function clientTypeGeneration(app, path) {
35
39
  const root = app.graphql.watchDirs.find((dir) => path.startsWith(dir)) || path;
36
40
  if (!root) return;
37
41
  const docs = await loadGraphQLDocuments(root);
38
- const graphqlString = readFileSync(join(app.graphql.buildDir, "schema.graphql"), "utf-8");
42
+ const schemaFilePath = join(app.graphql.buildDir, "schema.graphql");
43
+ if (!existsSync(schemaFilePath)) {
44
+ consola.info("Schema file not ready yet for client type generation. Server types need to be generated first.");
45
+ return;
46
+ }
47
+ const graphqlString = readFileSync(schemaFilePath, "utf-8");
39
48
  const schema = buildSchema(graphqlString);
40
49
  const types = await generateClientTypes(schema, docs);
41
50
  if (types === false) return;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nitro-graphql",
3
3
  "type": "module",
4
- "version": "0.0.7",
4
+ "version": "0.0.9",
5
5
  "description": "GraphQL integration for Nitro",
6
6
  "license": "MIT",
7
7
  "sideEffects": false,