nitro-graphql 2.0.0-beta.20 → 2.0.0-beta.21

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/index.d.mts CHANGED
@@ -1,12 +1,43 @@
1
- import { StandardSchemaV1 } from "./types/standard-schema.mjs";
2
- import { ClientUtilsConfig, CodegenClientConfig, CodegenServerConfig, ExternalGraphQLService, ExternalServicePaths, FederationConfig, FileGenerationConfig, GenImport, GenericSdkConfig, NitroGraphQLOptions, PathsConfig, ScaffoldConfig, SdkConfig, TypesConfig } from "./types/index.mjs";
3
- import * as nitro_types0 from "nitro/types";
1
+ import { NitroGraphQLOptions } from "./types/index.mjs";
2
+ import { NitroModule } from "nitro/types";
3
+ import { Plugin } from "vite";
4
4
 
5
5
  //#region src/index.d.ts
6
+
6
7
  /**
7
- * Nitro GraphQL module
8
- * Can be used via modules array in nitro.config.ts
8
+ * Vite plugin to load GraphQL files as strings AND auto-register Nitro module
9
+ * This prevents Vite from trying to parse .graphql/.gql files as JavaScript
10
+ * and automatically sets up the nitro-graphql module via the nitro: hook
11
+ *
12
+ * @example - Vite usage
13
+ * ```ts
14
+ * import { defineConfig } from 'vite'
15
+ * import { nitro } from 'nitro/vite'
16
+ * import graphql from 'nitro-graphql'
17
+ *
18
+ * export default defineConfig({
19
+ * plugins: [
20
+ * graphql({ framework: 'graphql-yoga' }), // Auto-registers Nitro module
21
+ * nitro()
22
+ * ]
23
+ * })
24
+ * ```
25
+ *
26
+ *
27
+ * @example - Nitro direct usage
28
+ * ```ts
29
+ *
30
+ * import graphql from 'nitro-graphql'
31
+ *
32
+ * export default defineConfig({
33
+ * modules: [
34
+ * graphql({ framework: 'graphql-yoga' }) // Auto-registers Nitro module
35
+ * ]
36
+ * })
37
+ * ```
9
38
  */
10
- declare const _default: nitro_types0.NitroModule;
39
+ declare function graphqlModule(options?: NitroGraphQLOptions): Plugin & {
40
+ nitro?: NitroModule;
41
+ };
11
42
  //#endregion
12
- export { ClientUtilsConfig, CodegenClientConfig, CodegenServerConfig, ExternalGraphQLService, ExternalServicePaths, FederationConfig, FileGenerationConfig, GenImport, GenericSdkConfig, NitroGraphQLOptions, PathsConfig, ScaffoldConfig, SdkConfig, StandardSchemaV1, TypesConfig, _default as default };
43
+ export { graphqlModule as default };
package/dist/index.mjs CHANGED
@@ -1,16 +1,63 @@
1
1
  import { setupNitroGraphQL } from "./setup.mjs";
2
+ import { readFile } from "node:fs/promises";
3
+ import defu from "defu";
2
4
 
3
5
  //#region src/index.ts
4
6
  /**
5
- * Nitro GraphQL module
6
- * Can be used via modules array in nitro.config.ts
7
+ * Vite plugin to load GraphQL files as strings AND auto-register Nitro module
8
+ * This prevents Vite from trying to parse .graphql/.gql files as JavaScript
9
+ * and automatically sets up the nitro-graphql module via the nitro: hook
10
+ *
11
+ * @example - Vite usage
12
+ * ```ts
13
+ * import { defineConfig } from 'vite'
14
+ * import { nitro } from 'nitro/vite'
15
+ * import graphql from 'nitro-graphql'
16
+ *
17
+ * export default defineConfig({
18
+ * plugins: [
19
+ * graphql({ framework: 'graphql-yoga' }), // Auto-registers Nitro module
20
+ * nitro()
21
+ * ]
22
+ * })
23
+ * ```
24
+ *
25
+ *
26
+ * @example - Nitro direct usage
27
+ * ```ts
28
+ *
29
+ * import graphql from 'nitro-graphql'
30
+ *
31
+ * export default defineConfig({
32
+ * modules: [
33
+ * graphql({ framework: 'graphql-yoga' }) // Auto-registers Nitro module
34
+ * ]
35
+ * })
36
+ * ```
7
37
  */
8
- var src_default = defineNitroModule({
9
- name: "nitro-graphql",
10
- async setup(nitro) {
11
- await setupNitroGraphQL(nitro);
12
- }
13
- });
38
+ function graphqlModule(options) {
39
+ return {
40
+ name: "nitro-graphql",
41
+ enforce: "pre",
42
+ async load(id) {
43
+ if (!/\.(?:graphql|gql)$/i.test(id)) return null;
44
+ try {
45
+ const content = await readFile(id, "utf-8");
46
+ return `export default ${JSON.stringify(content)}`;
47
+ } catch (error) {
48
+ if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") return null;
49
+ throw error;
50
+ }
51
+ },
52
+ nitro: { async setup(nitro) {
53
+ if (options) nitro.options.graphql = defu(nitro.options.graphql || {}, options);
54
+ nitro.options.graphql = nitro.options.graphql || {};
55
+ nitro.options.graphql._vitePlugin = true;
56
+ await setupNitroGraphQL(nitro);
57
+ } }
58
+ };
59
+ }
60
+ var src_default = graphqlModule;
14
61
 
15
62
  //#endregion
16
63
  export { src_default as default };
package/dist/rollup.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  import { getImportId, scanGraphql } from "./utils/index.mjs";
2
2
  import { clientTypeGeneration, serverTypeGeneration } from "./utils/type-generation.mjs";
3
+ import { readFile } from "node:fs/promises";
3
4
  import { fileURLToPath } from "node:url";
4
5
  import { resolve } from "pathe";
5
- import { readFile } from "node:fs/promises";
6
6
  import { parse } from "graphql";
7
7
  import { genImport } from "knitwork";
8
8
 
@@ -1,6 +1,6 @@
1
- import * as h35 from "h3";
1
+ import * as h33 from "h3";
2
2
 
3
3
  //#region src/routes/apollo-server.d.ts
4
- declare const _default: h35.EventHandlerWithFetch<h35.EventHandlerRequest, Promise<any>>;
4
+ declare const _default: h33.EventHandlerWithFetch<h33.EventHandlerRequest, Promise<any>>;
5
5
  //#endregion
6
6
  export { _default as default };
@@ -1,5 +1,5 @@
1
- import { consola as consola$1 } from "consola";
2
1
  import defu from "defu";
2
+ import { consola as consola$1 } from "consola";
3
3
  import { parse } from "graphql";
4
4
  import { mergeResolvers, mergeTypeDefs } from "@graphql-tools/merge";
5
5
  import { importedConfig } from "#nitro-graphql/graphql-config";
@@ -1,4 +1,4 @@
1
- import * as h31 from "h3";
1
+ import * as h35 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: h35.EventHandlerWithFetch<h35.EventHandlerRequest, Promise<string | {
14
14
  timestamp: string;
15
15
  environment: {
16
16
  dev: any;
@@ -1,6 +1,6 @@
1
- import * as h33 from "h3";
1
+ import * as h31 from "h3";
2
2
 
3
3
  //#region src/routes/graphql-yoga.d.ts
4
- declare const _default: h33.EventHandlerWithFetch<h33.EventHandlerRequest, Promise<Response>>;
4
+ declare const _default: h31.EventHandlerWithFetch<h31.EventHandlerRequest, Promise<Response>>;
5
5
  //#endregion
6
6
  export { _default as default };
@@ -1,5 +1,5 @@
1
- import { consola as consola$1 } from "consola";
2
1
  import defu from "defu";
2
+ import { consola as consola$1 } from "consola";
3
3
  import { parse } from "graphql";
4
4
  import { mergeResolvers, mergeTypeDefs } from "@graphql-tools/merge";
5
5
  import { importedConfig } from "#nitro-graphql/graphql-config";
@@ -1,6 +1,6 @@
1
1
  import { defineEventHandler } from "h3";
2
2
  import { $fetch } from "nitro/deps/ofetch";
3
- import { useRuntimeConfig } from "nitro/runtime";
3
+ import { useRuntimeConfig } from "nitro/runtime-config";
4
4
 
5
5
  //#region src/routes/health.ts
6
6
  var health_default = defineEventHandler(async (event) => {
package/dist/setup.mjs CHANGED
@@ -4,11 +4,11 @@ import { writeFileIfNotExists } from "./utils/file-generator.mjs";
4
4
  import { getScaffoldConfig, getTypesConfig, resolveFilePath, shouldGenerateScaffold } from "./utils/path-resolver.mjs";
5
5
  import { clientTypeGeneration, serverTypeGeneration } from "./utils/type-generation.mjs";
6
6
  import { rollupConfig } from "./rollup.mjs";
7
+ import defu from "defu";
7
8
  import { existsSync, mkdirSync } from "node:fs";
8
9
  import { fileURLToPath } from "node:url";
9
10
  import { watch } from "chokidar";
10
11
  import consola from "consola";
11
- import defu from "defu";
12
12
  import { dirname, join, relative, resolve } from "pathe";
13
13
 
14
14
  //#region src/setup.ts
@@ -243,4 +243,4 @@ interface NitroGraphQLOptions {
243
243
  paths?: PathsConfig;
244
244
  }
245
245
  //#endregion
246
- export { ClientUtilsConfig, CodegenClientConfig, CodegenServerConfig, ExternalGraphQLService, ExternalServicePaths, FederationConfig, FileGenerationConfig, GenImport, GenericSdkConfig, NitroGraphQLOptions, PathsConfig, ScaffoldConfig, SdkConfig, TypesConfig };
246
+ export { ClientUtilsConfig, CodegenClientConfig, ExternalGraphQLService, FileGenerationConfig, GenImport, GenericSdkConfig, NitroGraphQLOptions, ScaffoldConfig, SdkConfig, TypesConfig };
@@ -1,6 +1,6 @@
1
+ import { defu as defu$1 } from "defu";
1
2
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
3
  import { consola as consola$1 } from "consola";
3
- import { defu as defu$1 } from "defu";
4
4
  import { dirname, resolve } from "pathe";
5
5
  import { parse } from "graphql";
6
6
  import { printSchemaWithDirectives } from "@graphql-tools/utils";
@@ -1,9 +1,10 @@
1
+ import { StandardSchemaV1 } from "../types/standard-schema.mjs";
2
+ import "../types/index.mjs";
1
3
  import { GraphQLSchema } from "graphql";
2
4
  import { ApolloServerOptions } from "@apollo/server";
3
5
  import { H3Event } from "h3";
4
6
  import { YogaServerOptions } from "graphql-yoga";
5
7
  import { NPMConfig, Resolvers, ResolversTypes } from "#graphql/server";
6
- import { StandardSchemaV1 } from "nitro-graphql";
7
8
 
8
9
  //#region src/utils/define.d.ts
9
10
  type Flatten<T> = T extends infer U ? { [K in keyof U]: U[K] } : never;
@@ -1,6 +1,6 @@
1
1
  import { directiveParser, generateDirectiveSchema, generateDirectiveSchemas } from "./directive-parser.mjs";
2
- import { join, relative } from "pathe";
3
2
  import { readFile } from "node:fs/promises";
3
+ import { join, relative } from "pathe";
4
4
  import { hash } from "ohash";
5
5
  import { parseAsync } from "oxc-parser";
6
6
  import { glob } from "tinyglobby";
@@ -1,5 +1,5 @@
1
- import consola from "consola";
2
1
  import { defu as defu$1 } from "defu";
2
+ import consola from "consola";
3
3
  import { parse } from "graphql";
4
4
  import { printSchemaWithDirectives } from "@graphql-tools/utils";
5
5
  import { codegen } from "@graphql-codegen/core";
package/dist/vite.d.mts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { NitroGraphQLOptions } from "./types/index.mjs";
2
+ import { NitroModule } from "nitro/types";
2
3
  import { Plugin } from "vite";
3
4
 
4
5
  //#region src/vite.d.ts
@@ -22,6 +23,8 @@ import { Plugin } from "vite";
22
23
  * })
23
24
  * ```
24
25
  */
25
- declare function graphql(options?: NitroGraphQLOptions): Plugin;
26
+ declare function graphql(options?: NitroGraphQLOptions): Plugin & {
27
+ nitro?: NitroModule;
28
+ };
26
29
  //#endregion
27
30
  export { graphql };
package/dist/vite.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { setupNitroGraphQL } from "./setup.mjs";
2
- import defu from "defu";
3
2
  import { readFile } from "node:fs/promises";
3
+ import defu from "defu";
4
4
 
5
5
  //#region src/vite.ts
6
6
  /**
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.20",
4
+ "version": "2.0.0-beta.21",
5
5
  "description": "GraphQL integration for Nitro",
6
6
  "license": "MIT",
7
7
  "sideEffects": false,
@@ -123,7 +123,7 @@
123
123
  "graphql": "16.11.0",
124
124
  "graphql-yoga": "^5.16.2",
125
125
  "h3": "^2.0.1-rc.5",
126
- "nitro": "^3.0.1-alpha.0",
126
+ "nitro": "npm:nitro-nightly@latest",
127
127
  "tsdown": "^0.16.1",
128
128
  "typescript": "^5.9.3",
129
129
  "vite": "^7.2.2",