nitro-graphql 0.0.1 → 0.0.3
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 +14 -14
- package/dist/{client-codegen-DM2n5Gt2.js → client-codegen.js} +1 -2
- package/dist/client-watcher.d.ts +2 -5
- package/dist/client-watcher.js +36 -28
- package/dist/codegen.d.ts +12 -1
- package/dist/codegen.js +107 -1
- package/dist/context.d.ts +9 -1
- package/dist/context.js +0 -1
- package/dist/dev.js +95 -0
- package/dist/index.d.ts +12 -8
- package/dist/index.js +67 -329
- package/dist/prerender.js +279 -0
- package/dist/{scanner-BdcKEPQk.js → scanner.js} +4 -5
- package/dist/{types-D_NqyCcy.d.ts → types.d.ts} +2 -11
- package/dist/utils.d.ts +13 -3
- package/dist/utils.js +22 -2
- package/package.json +9 -4
- package/dist/client-codegen-DM2n5Gt2.js.map +0 -1
- package/dist/client-watcher.d.ts.map +0 -1
- package/dist/client-watcher.js.map +0 -1
- package/dist/codegen-DWJuLowd.d.ts +0 -16
- package/dist/codegen-DWJuLowd.d.ts.map +0 -1
- package/dist/codegen-Dbw6gEZt.js +0 -110
- package/dist/codegen-Dbw6gEZt.js.map +0 -1
- package/dist/context-BgqNJFCT.d.ts +0 -13
- package/dist/context-BgqNJFCT.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/scanner-BdcKEPQk.js.map +0 -1
- package/dist/types-D_NqyCcy.d.ts.map +0 -1
- package/dist/utils-87_22aIA.js +0 -41
- package/dist/utils-87_22aIA.js.map +0 -1
- package/dist/utils-BuYDOLIi.d.ts +0 -22
- package/dist/utils-BuYDOLIi.d.ts.map +0 -1
- package/dist/watcher.d.ts +0 -9
- package/dist/watcher.d.ts.map +0 -1
- package/dist/watcher.js +0 -96
- package/dist/watcher.js.map +0 -1
- /package/dist/{context-CZdhkJYD.js → types.js} +0 -0
package/README.md
CHANGED
|
@@ -111,9 +111,9 @@ extend type Mutation {
|
|
|
111
111
|
#### Domain-based Resolver Files
|
|
112
112
|
```ts
|
|
113
113
|
// server/graphql/users/user-queries.ts
|
|
114
|
-
import {
|
|
114
|
+
import { defineResolver } from 'nitro-graphql'
|
|
115
115
|
|
|
116
|
-
export default
|
|
116
|
+
export default defineResolver({
|
|
117
117
|
Query: {
|
|
118
118
|
users: async (_, __, { storage }) => {
|
|
119
119
|
return await storage.getItem('users') || []
|
|
@@ -128,9 +128,9 @@ export default createResolver({
|
|
|
128
128
|
|
|
129
129
|
```ts
|
|
130
130
|
// server/graphql/users/create-user.ts
|
|
131
|
-
import {
|
|
131
|
+
import { defineResolver } from 'nitro-graphql'
|
|
132
132
|
|
|
133
|
-
export default
|
|
133
|
+
export default defineResolver({
|
|
134
134
|
Mutation: {
|
|
135
135
|
createUser: async (_, { input }, { storage }) => {
|
|
136
136
|
const users = await storage.getItem('users') || []
|
|
@@ -153,9 +153,9 @@ The module provides utilities for better developer experience:
|
|
|
153
153
|
|
|
154
154
|
```ts
|
|
155
155
|
// server/graphql/hello.ts
|
|
156
|
-
import {
|
|
156
|
+
import { defineResolver } from 'nitro-graphql'
|
|
157
157
|
|
|
158
|
-
export default
|
|
158
|
+
export default defineResolver({
|
|
159
159
|
Query: {
|
|
160
160
|
hello: () => 'Hello World!',
|
|
161
161
|
greeting: (_, { name }) => `Hello ${name}!`
|
|
@@ -175,9 +175,9 @@ These types are automatically available in your resolvers:
|
|
|
175
175
|
```ts
|
|
176
176
|
import type { QueryResolvers } from '#build/graphql-types.generated'
|
|
177
177
|
// server/graphql/users/user-queries.ts
|
|
178
|
-
import {
|
|
178
|
+
import { defineResolver } from 'nitro-graphql'
|
|
179
179
|
|
|
180
|
-
export default
|
|
180
|
+
export default defineResolver({
|
|
181
181
|
Query: {
|
|
182
182
|
users: async (_, __, { storage }): Promise<User[]> => {
|
|
183
183
|
return await storage.getItem('users') || []
|
|
@@ -222,9 +222,9 @@ The GraphQL context includes:
|
|
|
222
222
|
|
|
223
223
|
```ts
|
|
224
224
|
// Example resolver with full context usage
|
|
225
|
-
import {
|
|
225
|
+
import { defineResolver } from 'nitro-graphql'
|
|
226
226
|
|
|
227
|
-
export default
|
|
227
|
+
export default defineResolver({
|
|
228
228
|
Query: {
|
|
229
229
|
currentUser: async (_, __, { event, request, storage }) => {
|
|
230
230
|
const token = getCookie(event, 'auth-token')
|
|
@@ -380,9 +380,9 @@ export default defineNitroConfig({
|
|
|
380
380
|
import { GraphQLScalarType } from 'graphql'
|
|
381
381
|
import { Kind } from 'graphql/language'
|
|
382
382
|
// server/graphql/scalars/DateTime.ts
|
|
383
|
-
import {
|
|
383
|
+
import { defineResolver } from 'nitro-graphql'
|
|
384
384
|
|
|
385
|
-
export default
|
|
385
|
+
export default defineResolver({
|
|
386
386
|
DateTime: new GraphQLScalarType({
|
|
387
387
|
name: 'DateTime',
|
|
388
388
|
serialize: (value: Date) => value.toISOString(),
|
|
@@ -401,9 +401,9 @@ export default createResolver({
|
|
|
401
401
|
|
|
402
402
|
```ts
|
|
403
403
|
// server/graphql/users/user-queries.ts
|
|
404
|
-
import {
|
|
404
|
+
import { defineResolver } from 'nitro-graphql'
|
|
405
405
|
|
|
406
|
-
export default
|
|
406
|
+
export default defineResolver({
|
|
407
407
|
Query: {
|
|
408
408
|
user: async (_, { id }, { storage }) => {
|
|
409
409
|
try {
|
package/dist/client-watcher.d.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import { NitroGraphQLOptions } from "./types
|
|
1
|
+
import { NitroGraphQLOptions } from "./types.js";
|
|
2
2
|
import { Nitro } from "nitropack/types";
|
|
3
3
|
|
|
4
4
|
//#region src/client-watcher.d.ts
|
|
5
5
|
declare function setupClientWatcher(nitro: Nitro, options: NitroGraphQLOptions): Promise<void>;
|
|
6
|
-
//# sourceMappingURL=client-watcher.d.ts.map
|
|
7
|
-
|
|
8
6
|
//#endregion
|
|
9
|
-
export { setupClientWatcher };
|
|
10
|
-
//# sourceMappingURL=client-watcher.d.ts.map
|
|
7
|
+
export { setupClientWatcher };
|
package/dist/client-watcher.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { scanGraphQLFiles } from "./scanner
|
|
2
|
-
import { debounce } from "./utils-87_22aIA.js";
|
|
1
|
+
import { scanGraphQLFiles } from "./scanner.js";
|
|
3
2
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
4
3
|
import { mergeTypeDefs } from "@graphql-tools/merge";
|
|
5
4
|
import { makeExecutableSchema } from "@graphql-tools/schema";
|
|
6
5
|
import { consola } from "consola";
|
|
7
6
|
import { join } from "pathe";
|
|
7
|
+
import { debounce } from "perfect-debounce";
|
|
8
8
|
|
|
9
9
|
//#region src/client-watcher.ts
|
|
10
10
|
const logger = consola.withTag("graphql");
|
|
@@ -21,12 +21,19 @@ async function regenerateClientTypes(nitro, options) {
|
|
|
21
21
|
typeDefs: mergedTypeDefs,
|
|
22
22
|
resolvers: {}
|
|
23
23
|
});
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
const getClientPatterns = () => {
|
|
25
|
+
if (options.client?.watchPatterns) return options.client.watchPatterns;
|
|
26
|
+
const basePatterns = [
|
|
27
|
+
join(nitro.options.srcDir, "**/*.graphql"),
|
|
28
|
+
join(nitro.options.srcDir, "**/*.gql"),
|
|
29
|
+
`!${join(nitro.options.srcDir, "graphql/**/*")}`
|
|
30
|
+
];
|
|
31
|
+
if (nitro.options.framework?.name === "nuxt") if (options.client?.nuxtPatterns) basePatterns.unshift(...options.client.nuxtPatterns);
|
|
32
|
+
else basePatterns.unshift(join(nitro.options.srcDir, "app/graphql/**/*.graphql"), join(nitro.options.srcDir, "app/graphql/**/*.gql"));
|
|
33
|
+
return basePatterns;
|
|
34
|
+
};
|
|
35
|
+
const clientPatterns = getClientPatterns();
|
|
36
|
+
const { generateClientTypes } = await import("./client-codegen.js");
|
|
30
37
|
const generatedTypes = await generateClientTypes(schema, clientPatterns, options.client.config, options.client.outputPath);
|
|
31
38
|
if (generatedTypes) {
|
|
32
39
|
const outputPath = options.client.outputPath || join(nitro.options.buildDir, "types", "graphql-client.generated.ts");
|
|
@@ -45,48 +52,49 @@ async function setupClientWatcher(nitro, options) {
|
|
|
45
52
|
logger.info("🚫 Client type generation disabled");
|
|
46
53
|
return;
|
|
47
54
|
}
|
|
48
|
-
const
|
|
55
|
+
const getClientPatterns = () => {
|
|
56
|
+
if (options.client?.watchPatterns) return options.client.watchPatterns;
|
|
57
|
+
const basePatterns = [join(nitro.options.srcDir, "**/*.graphql"), join(nitro.options.srcDir, "**/*.gql")];
|
|
58
|
+
if (nitro.options.framework?.name === "nuxt") if (options.client?.nuxtPatterns) basePatterns.unshift(...options.client.nuxtPatterns);
|
|
59
|
+
else basePatterns.unshift(join(nitro.options.srcDir, "app/graphql/**/*.graphql"), join(nitro.options.srcDir, "app/graphql/**/*.gql"));
|
|
60
|
+
return basePatterns;
|
|
61
|
+
};
|
|
62
|
+
const clientPatterns = getClientPatterns();
|
|
49
63
|
const generateClientTypesDebounced = debounce(async () => {
|
|
50
64
|
await regenerateClientTypes(nitro, options);
|
|
51
65
|
}, 300);
|
|
52
66
|
const { watch } = await import("chokidar");
|
|
53
|
-
const
|
|
54
|
-
const existingClientFiles = await globby(clientPatterns, {
|
|
55
|
-
absolute: true,
|
|
56
|
-
ignore: [join(nitro.options.srcDir, "graphql/**/*")]
|
|
57
|
-
});
|
|
58
|
-
const watchPatterns = existingClientFiles.length > 0 ? existingClientFiles : clientPatterns;
|
|
59
|
-
const watcher = watch(watchPatterns, {
|
|
67
|
+
const watcher = watch(clientPatterns, {
|
|
60
68
|
persistent: true,
|
|
61
69
|
ignoreInitial: true,
|
|
62
|
-
ignored: /(^|[/\\])
|
|
70
|
+
ignored: [/(^|[/\\])\.\.\./, join(nitro.options.srcDir, "graphql/**/*")],
|
|
63
71
|
followSymlinks: false,
|
|
64
|
-
depth: 10,
|
|
65
72
|
usePolling: true,
|
|
66
|
-
interval:
|
|
67
|
-
binaryInterval:
|
|
73
|
+
interval: 500,
|
|
74
|
+
binaryInterval: 500
|
|
68
75
|
});
|
|
69
|
-
watcher.on("
|
|
76
|
+
watcher.on("add", (path) => {
|
|
77
|
+
logger.info(`📁 Client file added: ${path}`);
|
|
70
78
|
generateClientTypesDebounced();
|
|
71
79
|
});
|
|
72
|
-
watcher.on("
|
|
80
|
+
watcher.on("change", (path) => {
|
|
81
|
+
logger.info(`📝 Client file changed: ${path}`);
|
|
73
82
|
generateClientTypesDebounced();
|
|
74
83
|
});
|
|
75
|
-
watcher.on("unlink", (
|
|
84
|
+
watcher.on("unlink", (path) => {
|
|
85
|
+
logger.info(`🗑️ Client file removed: ${path}`);
|
|
76
86
|
generateClientTypesDebounced();
|
|
77
87
|
});
|
|
78
88
|
watcher.on("error", (error) => {
|
|
79
|
-
|
|
80
|
-
logger.error("❌ Client watcher error:", errorMessage);
|
|
89
|
+
logger.error("❌ Client watcher error:", error);
|
|
81
90
|
});
|
|
82
91
|
nitro.hooks.hook("close", () => {
|
|
83
92
|
logger.info("🔒 Closing client watcher");
|
|
84
93
|
watcher.close();
|
|
85
94
|
});
|
|
86
|
-
await
|
|
95
|
+
await regenerateClientTypes(nitro, options);
|
|
87
96
|
logger.success("✅ Client watcher ready");
|
|
88
97
|
}
|
|
89
98
|
|
|
90
99
|
//#endregion
|
|
91
|
-
export { setupClientWatcher };
|
|
92
|
-
//# sourceMappingURL=client-watcher.js.map
|
|
100
|
+
export { setupClientWatcher };
|
package/dist/codegen.d.ts
CHANGED
|
@@ -1,2 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GraphQLSchema } from "graphql";
|
|
2
|
+
|
|
3
|
+
//#region src/codegen.d.ts
|
|
4
|
+
interface CodegenServerConfig {
|
|
5
|
+
contextType?: string;
|
|
6
|
+
scalars?: Record<string, any>;
|
|
7
|
+
defaultMapper?: string;
|
|
8
|
+
mapperTypeSuffix?: string;
|
|
9
|
+
[key: string]: any;
|
|
10
|
+
}
|
|
11
|
+
declare function generateTypes(schema: GraphQLSchema, config?: CodegenServerConfig, outputPath?: string): Promise<string>;
|
|
12
|
+
//#endregion
|
|
2
13
|
export { CodegenServerConfig, generateTypes };
|
package/dist/codegen.js
CHANGED
|
@@ -1,3 +1,109 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { codegen } from "@graphql-codegen/core";
|
|
2
|
+
import * as typescriptPlugin from "@graphql-codegen/typescript";
|
|
3
|
+
import * as typescriptResolversPlugin from "@graphql-codegen/typescript-resolvers";
|
|
4
|
+
import { printSchemaWithDirectives } from "@graphql-tools/utils";
|
|
5
|
+
import { defu } from "defu";
|
|
6
|
+
import { parse } from "graphql";
|
|
7
|
+
import { CurrencyResolver, DateTimeResolver, JSONResolver, NonEmptyStringResolver, UUIDResolver } from "graphql-scalars";
|
|
2
8
|
|
|
9
|
+
//#region src/codegen.ts
|
|
10
|
+
function pluginContent(_schema, _documents, _config, _info) {
|
|
11
|
+
return {
|
|
12
|
+
prepend: [
|
|
13
|
+
"// THIS FILE IS GENERATED, DO NOT EDIT!",
|
|
14
|
+
"/* eslint-disable eslint-comments/no-unlimited-disable */",
|
|
15
|
+
"/* tslint:disable */",
|
|
16
|
+
"/* eslint-disable */",
|
|
17
|
+
"/* prettier-ignore */"
|
|
18
|
+
],
|
|
19
|
+
content: ""
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
async function generateTypes(schema, config = {}, outputPath) {
|
|
23
|
+
const defaultConfig = {
|
|
24
|
+
scalars: {
|
|
25
|
+
Boolean: {
|
|
26
|
+
input: "boolean",
|
|
27
|
+
output: "boolean"
|
|
28
|
+
},
|
|
29
|
+
DateTime: DateTimeResolver.extensions.codegenScalarType,
|
|
30
|
+
DateTimeISO: DateTimeResolver.extensions.codegenScalarType,
|
|
31
|
+
UUID: UUIDResolver.extensions.codegenScalarType,
|
|
32
|
+
JSON: JSONResolver.extensions.codegenScalarType,
|
|
33
|
+
JSONObject: JSONResolver.extensions.codegenScalarType,
|
|
34
|
+
NonEmptyString: NonEmptyStringResolver.extensions.codegenScalarType,
|
|
35
|
+
Currency: CurrencyResolver.extensions.codegenScalarType,
|
|
36
|
+
File: {
|
|
37
|
+
input: "File",
|
|
38
|
+
output: "File"
|
|
39
|
+
},
|
|
40
|
+
Cursor: {
|
|
41
|
+
input: "number",
|
|
42
|
+
output: "number"
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
defaultScalarType: "unknown",
|
|
46
|
+
defaultMapper: `ResolverReturnType<{T}>`,
|
|
47
|
+
contextType: "./context#GraphQLContext",
|
|
48
|
+
maybeValue: "T | null | undefined",
|
|
49
|
+
inputMaybeValue: "T | undefined",
|
|
50
|
+
enumsAsTypes: true,
|
|
51
|
+
useTypeImports: true,
|
|
52
|
+
strictScalars: true,
|
|
53
|
+
emitLegacyCommonJSImports: false
|
|
54
|
+
};
|
|
55
|
+
const mergedConfig = defu(config, defaultConfig);
|
|
56
|
+
const output = await codegen({
|
|
57
|
+
filename: outputPath || "types.generated.ts",
|
|
58
|
+
schema: parse(printSchemaWithDirectives(schema)),
|
|
59
|
+
documents: [],
|
|
60
|
+
config: mergedConfig,
|
|
61
|
+
plugins: [
|
|
62
|
+
{ imports: {} },
|
|
63
|
+
{ pluginContent: {} },
|
|
64
|
+
{ typescript: {} },
|
|
65
|
+
{ typescriptResolvers: {} }
|
|
66
|
+
],
|
|
67
|
+
pluginMap: {
|
|
68
|
+
pluginContent: { plugin: pluginContent },
|
|
69
|
+
imports: { plugin: () => ({
|
|
70
|
+
prepend: [`type Primitive =
|
|
71
|
+
| null
|
|
72
|
+
| undefined
|
|
73
|
+
| string
|
|
74
|
+
| number
|
|
75
|
+
| boolean
|
|
76
|
+
| symbol
|
|
77
|
+
| bigint;
|
|
78
|
+
|
|
79
|
+
type BuiltIns = Primitive | void | Date | RegExp;
|
|
80
|
+
|
|
81
|
+
type ResolverReturnType<T> = T extends BuiltIns
|
|
82
|
+
? T
|
|
83
|
+
: T extends (...args: any[]) => unknown
|
|
84
|
+
? T | undefined
|
|
85
|
+
: T extends object
|
|
86
|
+
? T extends Array<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
|
|
87
|
+
? ItemType[] extends T // Test for arrays (non-tuples) specifically
|
|
88
|
+
? Array<ResolverReturnType<ItemType>>
|
|
89
|
+
: ResolverReturnTypeObject<T> // Tuples behave properly
|
|
90
|
+
: ResolverReturnTypeObject<T>
|
|
91
|
+
: unknown;
|
|
92
|
+
|
|
93
|
+
type ResolverReturnTypeObject<T extends object> = {
|
|
94
|
+
[K in keyof T]: ResolverReturnType<T[K]>
|
|
95
|
+
};`, ""],
|
|
96
|
+
content: ""
|
|
97
|
+
}) },
|
|
98
|
+
typescript: typescriptPlugin,
|
|
99
|
+
typescriptResolvers: typescriptResolversPlugin
|
|
100
|
+
}
|
|
101
|
+
}).catch((e) => {
|
|
102
|
+
console.warn("[nitro-graphql] Code generation error:", e);
|
|
103
|
+
return "";
|
|
104
|
+
});
|
|
105
|
+
return output;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
//#endregion
|
|
3
109
|
export { generateTypes };
|
package/dist/context.d.ts
CHANGED
|
@@ -1,2 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { YogaInitialContext } from "graphql-yoga";
|
|
2
|
+
import { H3Event } from "h3";
|
|
3
|
+
|
|
4
|
+
//#region src/context.d.ts
|
|
5
|
+
interface GraphQLContext extends YogaInitialContext {
|
|
6
|
+
event: H3Event;
|
|
7
|
+
storage: any;
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
2
10
|
export { GraphQLContext };
|
package/dist/context.js
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "./context-CZdhkJYD.js";
|
package/dist/dev.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { scanGraphQLFiles } from "./scanner.js";
|
|
2
|
+
import { setupClientWatcher } from "./client-watcher.js";
|
|
3
|
+
import { generateTypes } from "./codegen.js";
|
|
4
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
5
|
+
import { mergeTypeDefs } from "@graphql-tools/merge";
|
|
6
|
+
import { makeExecutableSchema } from "@graphql-tools/schema";
|
|
7
|
+
import { consola } from "consola";
|
|
8
|
+
import { join } from "pathe";
|
|
9
|
+
import { debounce } from "perfect-debounce";
|
|
10
|
+
import { existsSync } from "node:fs";
|
|
11
|
+
import { watch } from "chokidar";
|
|
12
|
+
|
|
13
|
+
//#region src/dev.ts
|
|
14
|
+
const logger = consola.withTag("graphql");
|
|
15
|
+
async function regenerateGraphQLTypes(nitro) {
|
|
16
|
+
try {
|
|
17
|
+
const scanResult = await scanGraphQLFiles(nitro);
|
|
18
|
+
if (scanResult.typeDefs.length === 0) {
|
|
19
|
+
logger.warn("⚠️ No schema files found");
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const mergedTypeDefs = mergeTypeDefs(scanResult.typeDefs);
|
|
23
|
+
const schema = makeExecutableSchema({
|
|
24
|
+
typeDefs: mergedTypeDefs,
|
|
25
|
+
resolvers: {}
|
|
26
|
+
});
|
|
27
|
+
const generatedTypes = await generateTypes(schema);
|
|
28
|
+
const outputPath = join(nitro.options.buildDir, "types", "graphql-types.generated.ts");
|
|
29
|
+
const typesDir = join(nitro.options.buildDir, "types");
|
|
30
|
+
await mkdir(typesDir, { recursive: true });
|
|
31
|
+
await writeFile(outputPath, generatedTypes);
|
|
32
|
+
logger.success("✨ Types regenerated");
|
|
33
|
+
} catch (error) {
|
|
34
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
35
|
+
logger.error("❌ Type generation failed:", errorMessage);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function devmode(nitro, options) {
|
|
39
|
+
if (nitro.options.dev) {
|
|
40
|
+
const generateTypesDebounced = debounce(async () => {
|
|
41
|
+
await regenerateGraphQLTypes(nitro);
|
|
42
|
+
}, 100);
|
|
43
|
+
const graphqlDir = join(nitro.options.srcDir, "graphql");
|
|
44
|
+
logger.info("🔍 Setting up independent GraphQL watcher for directory:", graphqlDir);
|
|
45
|
+
try {
|
|
46
|
+
if (!existsSync(graphqlDir)) {
|
|
47
|
+
logger.warn(`⚠️ GraphQL directory not found: ${graphqlDir}`);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
} catch (error) {
|
|
51
|
+
logger.warn("⚠️ Could not check GraphQL directory:", error);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const graphqlWatcher = watch(graphqlDir, {
|
|
55
|
+
ignoreInitial: true,
|
|
56
|
+
persistent: true,
|
|
57
|
+
usePolling: true,
|
|
58
|
+
interval: 500,
|
|
59
|
+
depth: 10
|
|
60
|
+
});
|
|
61
|
+
graphqlWatcher.on("add", (path) => {
|
|
62
|
+
logger.info("📁 GraphQL file added:", path);
|
|
63
|
+
generateTypesDebounced();
|
|
64
|
+
});
|
|
65
|
+
graphqlWatcher.on("change", (path) => {
|
|
66
|
+
logger.info("📝 GraphQL file changed:", path);
|
|
67
|
+
generateTypesDebounced();
|
|
68
|
+
});
|
|
69
|
+
graphqlWatcher.on("unlink", (path) => {
|
|
70
|
+
logger.info("🗑️ GraphQL file deleted:", path);
|
|
71
|
+
generateTypesDebounced();
|
|
72
|
+
});
|
|
73
|
+
graphqlWatcher.on("error", (error) => {
|
|
74
|
+
logger.error("❌ GraphQL watcher error:", error);
|
|
75
|
+
});
|
|
76
|
+
graphqlWatcher.on("raw", (event, path) => {
|
|
77
|
+
if (event === "change" && path && path.endsWith("graphql")) {
|
|
78
|
+
logger.info("📝 GraphQL directory change detected, regenerating types");
|
|
79
|
+
generateTypesDebounced();
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
graphqlWatcher.on("ready", () => {
|
|
83
|
+
logger.success("✅ GraphQL file watcher ready");
|
|
84
|
+
});
|
|
85
|
+
nitro.hooks.hook("close", async () => {
|
|
86
|
+
await graphqlWatcher.close();
|
|
87
|
+
logger.info("🔒 GraphQL watcher closed");
|
|
88
|
+
});
|
|
89
|
+
setupClientWatcher(nitro, options);
|
|
90
|
+
logger.success("✅ Independent GraphQL watcher set up");
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
//#endregion
|
|
95
|
+
export { devmode };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import { GraphQLContext } from "./context-BgqNJFCT.js";
|
|
4
|
-
import { createResolver, defineGraphQLResolver, defineYogaConfig } from "./utils-BuYDOLIi.js";
|
|
5
|
-
import * as nitropack0 from "nitropack";
|
|
1
|
+
import { NitroGraphQLOptions } from "./types.js";
|
|
2
|
+
import * as nitropack1 from "nitropack";
|
|
6
3
|
|
|
7
4
|
//#region src/index.d.ts
|
|
8
|
-
declare
|
|
5
|
+
declare module 'nitropack' {
|
|
6
|
+
interface NitroOptions {
|
|
7
|
+
graphqlYoga?: NitroGraphQLOptions;
|
|
8
|
+
}
|
|
9
|
+
interface NitroRuntimeConfig {
|
|
10
|
+
graphqlYoga?: NitroGraphQLOptions;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
declare const _default: nitropack1.NitroModule;
|
|
9
14
|
//#endregion
|
|
10
|
-
export {
|
|
11
|
-
//# sourceMappingURL=index.d.ts.map
|
|
15
|
+
export { _default as default };
|