nitro-graphql 0.0.3 → 0.0.5
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/_virtual/rolldown_runtime.js +37 -0
- package/dist/client-codegen.js +50 -15
- package/dist/codegen.d.ts +2 -8
- package/dist/codegen.js +2 -1
- package/dist/ecosystem/nuxt.d.ts +7 -0
- package/dist/ecosystem/nuxt.js +29 -0
- package/dist/graphql.d.ts +13 -0
- package/dist/index.d.ts +2 -11
- package/dist/index.js +75 -128
- package/dist/internal/create-merged-schema.d.ts +7 -0
- package/dist/internal/create-merged-schema.js +23 -0
- package/dist/internal/index.d.ts +2 -0
- package/dist/internal/index.js +3 -0
- package/dist/node_modules/.pnpm/@graphql-codegen_add@3.2.3_graphql@16.11.0/node_modules/@graphql-codegen/add/esm/config.js +9 -0
- package/dist/node_modules/.pnpm/@graphql-codegen_add@3.2.3_graphql@16.11.0/node_modules/@graphql-codegen/add/esm/index.js +17 -0
- package/dist/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 +38 -0
- package/dist/node_modules/.pnpm/@graphql-codegen_plugin-helpers@3.1.2_graphql@16.11.0/node_modules/@graphql-codegen/plugin-helpers/esm/federation.js +22 -0
- package/dist/node_modules/.pnpm/@graphql-codegen_plugin-helpers@3.1.2_graphql@16.11.0/node_modules/@graphql-codegen/plugin-helpers/esm/getCachedDocumentNodeFromSchema.js +6 -0
- package/dist/node_modules/.pnpm/@graphql-codegen_plugin-helpers@3.1.2_graphql@16.11.0/node_modules/@graphql-codegen/plugin-helpers/esm/helpers.js +79 -0
- package/dist/node_modules/.pnpm/@graphql-codegen_plugin-helpers@3.1.2_graphql@16.11.0/node_modules/@graphql-codegen/plugin-helpers/esm/index.js +6 -0
- package/dist/node_modules/.pnpm/@graphql-codegen_plugin-helpers@3.1.2_graphql@16.11.0/node_modules/@graphql-codegen/plugin-helpers/esm/oldVisit.js +1 -0
- package/dist/node_modules/.pnpm/@graphql-codegen_plugin-helpers@3.1.2_graphql@16.11.0/node_modules/@graphql-codegen/plugin-helpers/esm/resolve-external-module-and-fn.js +7 -0
- package/dist/node_modules/.pnpm/@graphql-codegen_plugin-helpers@3.1.2_graphql@16.11.0/node_modules/@graphql-codegen/plugin-helpers/esm/utils.js +13 -0
- package/dist/node_modules/.pnpm/camel-case@4.1.2/node_modules/camel-case/dist/index.js +33 -0
- package/dist/node_modules/.pnpm/capital-case@1.0.4/node_modules/capital-case/dist/index.js +32 -0
- package/dist/node_modules/.pnpm/change-case-all@1.0.15/node_modules/change-case-all/dist/index.js +56 -0
- package/dist/node_modules/.pnpm/change-case@4.1.2/node_modules/change-case/dist/index.js +37 -0
- package/dist/node_modules/.pnpm/constant-case@3.0.4/node_modules/constant-case/dist/index.js +28 -0
- package/dist/node_modules/.pnpm/dot-case@3.0.4/node_modules/dot-case/dist/index.js +23 -0
- package/dist/node_modules/.pnpm/header-case@2.0.4/node_modules/header-case/dist/index.js +23 -0
- package/dist/node_modules/.pnpm/is-lower-case@2.0.2/node_modules/is-lower-case/dist/index.js +21 -0
- package/dist/node_modules/.pnpm/is-upper-case@2.0.2/node_modules/is-upper-case/dist/index.js +21 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_Hash.js +37 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_ListCache.js +37 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_Map.js +15 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_MapCache.js +37 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_Stack.js +34 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_Symbol.js +15 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_Uint8Array.js +15 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_apply.js +30 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_arrayLikeKeys.js +35 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_assignMergeValue.js +26 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_assignValue.js +32 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_assocIndexOf.js +26 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseAssignValue.js +31 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseCreate.js +34 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseFor.js +25 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseGetTag.js +30 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseIsArguments.js +26 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseIsNative.js +44 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseIsTypedArray.js +32 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseKeysIn.js +32 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseMerge.js +42 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseMergeDeep.js +75 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseRest.js +26 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseSetToString.js +31 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseTimes.js +25 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseUnary.js +23 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_cloneArrayBuffer.js +25 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_cloneBuffer.js +35 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_cloneTypedArray.js +25 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_copyArray.js +25 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_copyObject.js +37 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_coreJsData.js +15 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_createAssigner.js +37 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_createBaseFor.js +28 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_defineProperty.js +20 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_freeGlobal.js +13 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_getMapData.js +25 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_getNative.js +26 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_getPrototype.js +15 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_getRawTag.js +43 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_getValue.js +22 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_hashClear.js +24 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_hashDelete.js +26 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_hashGet.js +36 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_hashHas.js +30 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_hashSet.js +31 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_initCloneObject.js +25 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_isIndex.js +28 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_isIterateeCall.js +32 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_isKeyable.js +22 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_isMasked.js +28 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_isPrototype.js +24 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_listCacheClear.js +22 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_listCacheDelete.js +35 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_listCacheGet.js +26 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_listCacheHas.js +25 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_listCacheSet.js +31 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_mapCacheClear.js +30 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_mapCacheDelete.js +27 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_mapCacheGet.js +25 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_mapCacheHas.js +25 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_mapCacheSet.js +29 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_nativeCreate.js +14 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_nativeKeysIn.js +25 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_nodeUtil.js +29 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_objectToString.js +29 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_overArg.js +24 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_overRest.js +35 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_root.js +17 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_safeGet.js +24 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_setToString.js +23 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_shortOut.js +34 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_stackClear.js +24 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_stackDelete.js +25 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_stackGet.js +23 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_stackHas.js +23 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_stackSet.js +42 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_toSource.js +33 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/constant.js +35 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/eq.js +46 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/identity.js +30 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isArguments.js +43 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isArray.js +35 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isArrayLike.js +42 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isArrayLikeObject.js +42 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isBuffer.js +41 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isFunction.js +38 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isLength.js +42 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isObject.js +40 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isObjectLike.js +38 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isPlainObject.js +60 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isTypedArray.js +34 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/keysIn.js +41 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/merge.js +48 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/stubFalse.js +27 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/toPlainObject.js +41 -0
- package/dist/node_modules/.pnpm/lower-case-first@2.0.2/node_modules/lower-case-first/dist/index.js +21 -0
- package/dist/node_modules/.pnpm/lower-case@2.0.2/node_modules/lower-case/dist/index.js +64 -0
- package/dist/node_modules/.pnpm/no-case@3.0.4/node_modules/no-case/dist/index.js +41 -0
- package/dist/node_modules/.pnpm/param-case@3.0.4/node_modules/param-case/dist/index.js +23 -0
- package/dist/node_modules/.pnpm/pascal-case@3.1.2/node_modules/pascal-case/dist/index.js +37 -0
- package/dist/node_modules/.pnpm/path-case@3.0.4/node_modules/path-case/dist/index.js +23 -0
- package/dist/node_modules/.pnpm/sentence-case@3.0.4/node_modules/sentence-case/dist/index.js +34 -0
- package/dist/node_modules/.pnpm/snake-case@3.0.4/node_modules/snake-case/dist/index.js +23 -0
- package/dist/node_modules/.pnpm/sponge-case@1.0.1/node_modules/sponge-case/dist/index.js +20 -0
- package/dist/node_modules/.pnpm/swap-case@2.0.2/node_modules/swap-case/dist/index.js +23 -0
- package/dist/node_modules/.pnpm/title-case@3.0.3/node_modules/title-case/dist/index.js +35 -0
- package/dist/node_modules/.pnpm/tslib@2.8.1/node_modules/tslib/tslib.es6.js +547 -0
- package/dist/node_modules/.pnpm/upper-case-first@2.0.2/node_modules/upper-case-first/dist/index.js +21 -0
- package/dist/node_modules/.pnpm/upper-case@2.0.2/node_modules/upper-case/dist/index.js +56 -0
- package/dist/rollup.js +84 -0
- package/dist/routes/graphql.d.ts +6 -0
- package/dist/routes/graphql.js +54 -0
- package/dist/types.d.ts +37 -2
- package/dist/utils/index.d.ts +21 -0
- package/dist/utils/index.js +72 -0
- package/dist/utils/server-type-generation.js +52 -0
- package/package.json +20 -8
- package/dist/client-watcher.d.ts +0 -7
- package/dist/client-watcher.js +0 -100
- package/dist/dev.js +0 -95
- package/dist/prerender.js +0 -279
- package/dist/scanner.js +0 -118
- package/dist/utils.d.ts +0 -13
- package/dist/utils.js +0 -23
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { createSchema, createYoga } from "graphql-yoga";
|
|
2
|
+
import { mergeResolvers, mergeTypeDefs } from "@graphql-tools/merge";
|
|
3
|
+
import { defs } from "#nitro-internal-virtual/server-defs";
|
|
4
|
+
import { resolvers } from "#nitro-internal-virtual/server-resolvers";
|
|
5
|
+
import { defineEventHandler } from "h3";
|
|
6
|
+
|
|
7
|
+
//#region src/routes/graphql.ts
|
|
8
|
+
const apolloSandboxHtml = `<!DOCTYPE html>
|
|
9
|
+
<html lang="en">
|
|
10
|
+
<body style="margin: 0; overflow-x: hidden; overflow-y: hidden">
|
|
11
|
+
<div id="sandbox" style="height:100vh; width:100vw;"></div>
|
|
12
|
+
<script src="https://embeddable-sandbox.cdn.apollographql.com/02e2da0fccbe0240ef03d2396d6c98559bab5b06/embeddable-sandbox.umd.production.min.js"><\/script>
|
|
13
|
+
<script>
|
|
14
|
+
new window.EmbeddedSandbox({
|
|
15
|
+
target: "#sandbox",
|
|
16
|
+
initialEndpoint: window.location.href,
|
|
17
|
+
hideCookieToggle: false,
|
|
18
|
+
initialState: {
|
|
19
|
+
includeCookies: true
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
<\/script>
|
|
23
|
+
</body>
|
|
24
|
+
</html>`;
|
|
25
|
+
function createMergedSchema() {
|
|
26
|
+
try {
|
|
27
|
+
const mergedDefs = defs.map((schema) => schema.def).join("\n\n");
|
|
28
|
+
const typeDefs = mergeTypeDefs([mergedDefs]);
|
|
29
|
+
const mergedResolvers = mergeResolvers(resolvers.map((r) => r.resolver));
|
|
30
|
+
return createSchema({
|
|
31
|
+
typeDefs,
|
|
32
|
+
resolvers: mergedResolvers
|
|
33
|
+
});
|
|
34
|
+
} catch (error) {
|
|
35
|
+
console.error("Schema merge error:", error);
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
let yoga;
|
|
40
|
+
var graphql_default = defineEventHandler(async (event) => {
|
|
41
|
+
if (!yoga) {
|
|
42
|
+
const schema = createMergedSchema();
|
|
43
|
+
yoga = createYoga({
|
|
44
|
+
schema,
|
|
45
|
+
graphqlEndpoint: "/api/graphql",
|
|
46
|
+
landingPage: false,
|
|
47
|
+
renderGraphiQL: () => apolloSandboxHtml
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return yoga.handle(event.node.req, event.node.res);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
//#endregion
|
|
54
|
+
export { graphql_default as default };
|
package/dist/types.d.ts
CHANGED
|
@@ -1,9 +1,34 @@
|
|
|
1
1
|
import { TypeScriptPluginConfig } from "@graphql-codegen/typescript";
|
|
2
|
+
import { TypeScriptResolversPluginConfig } from "@graphql-codegen/typescript-resolvers";
|
|
3
|
+
import { IResolvers } from "@graphql-tools/utils";
|
|
2
4
|
import { TypeScriptDocumentsPluginConfig } from "@graphql-codegen/typescript-operations";
|
|
3
5
|
import { YogaServerOptions } from "graphql-yoga";
|
|
4
6
|
import { IncomingMessage, ServerResponse } from "node:http";
|
|
5
7
|
|
|
6
8
|
//#region src/types.d.ts
|
|
9
|
+
type CodegenServerConfig = TypeScriptPluginConfig & TypeScriptResolversPluginConfig;
|
|
10
|
+
declare module 'nitropack/types' {
|
|
11
|
+
interface Nitro {
|
|
12
|
+
scanDefs: string[];
|
|
13
|
+
scanResolvers: any;
|
|
14
|
+
graphql: {
|
|
15
|
+
buildDir: string;
|
|
16
|
+
watchDirs: string[];
|
|
17
|
+
clientDir: string;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
declare module 'nitropack' {
|
|
22
|
+
interface NitroOptions {
|
|
23
|
+
graphql?: NitroGraphQLOptions;
|
|
24
|
+
}
|
|
25
|
+
interface NitroRuntimeConfig {
|
|
26
|
+
graphql?: NitroGraphQLOptions;
|
|
27
|
+
}
|
|
28
|
+
interface NitroConfig {
|
|
29
|
+
graphql?: NitroGraphQLOptions;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
7
32
|
interface GraphQLSchemaConfig {
|
|
8
33
|
typeDefs: string | string[];
|
|
9
34
|
resolvers: any;
|
|
@@ -20,19 +45,29 @@ interface NitroGraphQLOptions {
|
|
|
20
45
|
req: IncomingMessage;
|
|
21
46
|
res: ServerResponse;
|
|
22
47
|
}, any>['cors'];
|
|
48
|
+
typedefs?: string[];
|
|
49
|
+
resolvers?: Array<IResolvers<any, any>>;
|
|
50
|
+
loader?: {
|
|
51
|
+
include?: RegExp;
|
|
52
|
+
exclude?: RegExp;
|
|
53
|
+
validate?: boolean;
|
|
54
|
+
};
|
|
23
55
|
cacheHeaders?: {
|
|
24
56
|
enabled?: boolean;
|
|
25
57
|
maxAge?: number;
|
|
26
58
|
};
|
|
59
|
+
codegen?: {
|
|
60
|
+
server?: CodegenServerConfig;
|
|
61
|
+
client?: CodegenClientConfig;
|
|
62
|
+
};
|
|
27
63
|
client?: {
|
|
28
64
|
enabled?: boolean;
|
|
29
65
|
outputPath?: string;
|
|
30
66
|
watchPatterns?: string[];
|
|
31
67
|
nuxtPatterns?: string[];
|
|
32
|
-
config?: CodegenClientConfig;
|
|
33
68
|
};
|
|
34
69
|
yogaConfig?: Partial<YogaServerOptions<any, any>>;
|
|
35
70
|
}
|
|
36
71
|
interface Resolvers {}
|
|
37
72
|
//#endregion
|
|
38
|
-
export { CodegenClientConfig, GraphQLSchemaConfig, NitroGraphQLOptions, Resolvers };
|
|
73
|
+
export { CodegenClientConfig, CodegenServerConfig, GraphQLSchemaConfig, NitroGraphQLOptions, Resolvers };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Nitro } from "nitropack";
|
|
2
|
+
import { YogaServerOptions } from "graphql-yoga";
|
|
3
|
+
import { GraphQLSchemaConfig, Resolvers } from "nitro-graphql/types";
|
|
4
|
+
|
|
5
|
+
//#region src/utils/index.d.ts
|
|
6
|
+
declare const GLOB_SCAN_PATTERN = "**/*.{graphql,gql,js,mjs,cjs,ts,mts,cts,tsx,jsx}";
|
|
7
|
+
declare function defineGraphQLSchema(config: GraphQLSchemaConfig): GraphQLSchemaConfig;
|
|
8
|
+
declare function defineResolver(resolvers: Resolvers): Resolvers;
|
|
9
|
+
/**
|
|
10
|
+
* Helper function to define GraphQL Yoga configuration with type safety
|
|
11
|
+
*/
|
|
12
|
+
declare function defineYogaConfig<TServerContext = any, TUserContext = any>(config: Partial<YogaServerOptions<TServerContext, TUserContext>>): Partial<YogaServerOptions<TServerContext, TUserContext>>;
|
|
13
|
+
declare function relativeWithDot(from: string, to: string): string;
|
|
14
|
+
declare function scanGraphql(nitro: Nitro): Promise<string[]>;
|
|
15
|
+
declare function scanResolvers(nitro: Nitro): Promise<string[]>;
|
|
16
|
+
declare function scanDirectives(nitro: Nitro): Promise<string[]>;
|
|
17
|
+
declare function scanTypeDefs(nitro: Nitro): Promise<string[]>;
|
|
18
|
+
declare function scanDefs(nitro: Nitro): Promise<string[]>;
|
|
19
|
+
declare function unique(arr: any[]): any[];
|
|
20
|
+
//#endregion
|
|
21
|
+
export { GLOB_SCAN_PATTERN, defineGraphQLSchema, defineResolver, defineYogaConfig, relativeWithDot, scanDefs, scanDirectives, scanGraphql, scanResolvers, scanTypeDefs, unique };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { join, relative } from "pathe";
|
|
2
|
+
import { glob } from "tinyglobby";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/index.ts
|
|
5
|
+
const GLOB_SCAN_PATTERN = "**/*.{graphql,gql,js,mjs,cjs,ts,mts,cts,tsx,jsx}";
|
|
6
|
+
function defineGraphQLSchema(config) {
|
|
7
|
+
return config;
|
|
8
|
+
}
|
|
9
|
+
function defineResolver(resolvers) {
|
|
10
|
+
return resolvers;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Helper function to define GraphQL Yoga configuration with type safety
|
|
14
|
+
*/
|
|
15
|
+
function defineYogaConfig(config) {
|
|
16
|
+
return config;
|
|
17
|
+
}
|
|
18
|
+
const RELATIVE_RE = /^\.{1,2}\//;
|
|
19
|
+
function relativeWithDot(from, to) {
|
|
20
|
+
const rel = relative(from, to);
|
|
21
|
+
return RELATIVE_RE.test(rel) ? rel : `./${rel}`;
|
|
22
|
+
}
|
|
23
|
+
async function scanGraphql(nitro) {
|
|
24
|
+
const files = await scanFiles(nitro, "graphql");
|
|
25
|
+
return files.map((f) => f.fullPath);
|
|
26
|
+
}
|
|
27
|
+
async function scanResolvers(nitro) {
|
|
28
|
+
const files = await scanFiles(nitro, "graphql", "**/*.resolver.{ts,js}");
|
|
29
|
+
return files.map((f) => f.fullPath);
|
|
30
|
+
}
|
|
31
|
+
async function scanDirectives(nitro) {
|
|
32
|
+
const files = await scanFiles(nitro, "graphql", "**/*.directive.{ts,js}");
|
|
33
|
+
return files.map((f) => f.fullPath);
|
|
34
|
+
}
|
|
35
|
+
async function scanTypeDefs(nitro) {
|
|
36
|
+
const files = await scanFiles(nitro, "graphql", "**/*.typedef.{ts,js}");
|
|
37
|
+
return files.map((f) => f.fullPath);
|
|
38
|
+
}
|
|
39
|
+
async function scanDefs(nitro) {
|
|
40
|
+
const files = await scanFiles(nitro, "graphql", "**/*.graphql");
|
|
41
|
+
return files.map((f) => f.fullPath);
|
|
42
|
+
}
|
|
43
|
+
async function scanFiles(nitro, name, globPattern = GLOB_SCAN_PATTERN) {
|
|
44
|
+
const files = await Promise.all(nitro.options.scanDirs.map((dir) => scanDir(nitro, dir, name, globPattern))).then((r) => r.flat());
|
|
45
|
+
return files;
|
|
46
|
+
}
|
|
47
|
+
async function scanDir(nitro, dir, name, globPattern = GLOB_SCAN_PATTERN) {
|
|
48
|
+
const fileNames = await glob(join(name, globPattern), {
|
|
49
|
+
cwd: dir,
|
|
50
|
+
dot: true,
|
|
51
|
+
ignore: nitro.options.ignore,
|
|
52
|
+
absolute: true
|
|
53
|
+
}).catch((error) => {
|
|
54
|
+
if (error?.code === "ENOTDIR") {
|
|
55
|
+
nitro.logger.warn(`Ignoring \`${join(dir, name)}\`. It must be a directory.`);
|
|
56
|
+
return [];
|
|
57
|
+
}
|
|
58
|
+
throw error;
|
|
59
|
+
});
|
|
60
|
+
return fileNames.map((fullPath) => {
|
|
61
|
+
return {
|
|
62
|
+
fullPath,
|
|
63
|
+
path: relative(join(dir, name), fullPath)
|
|
64
|
+
};
|
|
65
|
+
}).sort((a, b) => a.path.localeCompare(b.path));
|
|
66
|
+
}
|
|
67
|
+
function unique(arr) {
|
|
68
|
+
return [...new Set(arr)];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
//#endregion
|
|
72
|
+
export { GLOB_SCAN_PATTERN, defineGraphQLSchema, defineResolver, defineYogaConfig, relativeWithDot, scanDefs, scanDirectives, scanGraphql, scanResolvers, scanTypeDefs, unique };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { generateTypes } from "../codegen.js";
|
|
2
|
+
import { generateClientTypes, loadGraphQLDocuments } from "../client-codegen.js";
|
|
3
|
+
import { printSchemaWithDirectives } from "@graphql-tools/utils";
|
|
4
|
+
import consola from "consola";
|
|
5
|
+
import { buildASTSchema, buildSchema } from "graphql";
|
|
6
|
+
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
7
|
+
import { dirname, join, resolve } from "pathe";
|
|
8
|
+
import { loadFilesSync } from "@graphql-tools/load-files";
|
|
9
|
+
import { mergeTypeDefs } from "@graphql-tools/merge";
|
|
10
|
+
|
|
11
|
+
//#region src/utils/server-type-generation.ts
|
|
12
|
+
async function serverTypeGeneration(app) {
|
|
13
|
+
try {
|
|
14
|
+
const defs = app.scanDefs || [];
|
|
15
|
+
const loadDefs = loadFilesSync(defs);
|
|
16
|
+
const mergedDefs = mergeTypeDefs(loadDefs);
|
|
17
|
+
const schema = buildASTSchema(mergedDefs, {
|
|
18
|
+
assumeValidSDL: true,
|
|
19
|
+
assumeValid: true
|
|
20
|
+
});
|
|
21
|
+
const data = await generateTypes(schema, app.options.graphql?.codegen?.server ?? {});
|
|
22
|
+
const printSchema = printSchemaWithDirectives(schema);
|
|
23
|
+
const schemaPath = resolve(app.graphql.buildDir, "schema.graphql");
|
|
24
|
+
mkdirSync(dirname(schemaPath), { recursive: true });
|
|
25
|
+
writeFileSync(schemaPath, printSchema, "utf-8");
|
|
26
|
+
const serverTypesPath = resolve(app.options.buildDir, "types", "nitro-graphql-server.d.ts");
|
|
27
|
+
mkdirSync(dirname(serverTypesPath), { recursive: true });
|
|
28
|
+
writeFileSync(serverTypesPath, data, "utf-8");
|
|
29
|
+
} catch (error) {
|
|
30
|
+
consola.error("Server schema generation error:", error);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async function clientTypeGeneration(app, path) {
|
|
34
|
+
try {
|
|
35
|
+
const root = app.graphql.watchDirs.find((dir) => path.startsWith(dir)) || path;
|
|
36
|
+
if (!root) return;
|
|
37
|
+
const docs = await loadGraphQLDocuments(root);
|
|
38
|
+
const graphqlString = readFileSync(join(app.graphql.buildDir, "schema.graphql"), "utf-8");
|
|
39
|
+
const schema = buildSchema(graphqlString);
|
|
40
|
+
const types = await generateClientTypes(schema, docs);
|
|
41
|
+
if (types === false) return;
|
|
42
|
+
const clientTypesPath = resolve(app.options.buildDir, "types", "nitro-graphql-client.d.ts");
|
|
43
|
+
const sdkTypesPath = resolve(app.graphql.clientDir, "sdk.ts");
|
|
44
|
+
writeFileSync(clientTypesPath, types.types, "utf-8");
|
|
45
|
+
writeFileSync(sdkTypesPath, types.sdk, "utf-8");
|
|
46
|
+
} catch (error) {
|
|
47
|
+
consola.error("Client schema generation error:", error);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
//#endregion
|
|
52
|
+
export { clientTypeGeneration, serverTypeGeneration };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nitro-graphql",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.5",
|
|
5
5
|
"description": "GraphQL integration for Nitro",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"sideEffects": false,
|
|
@@ -27,25 +27,34 @@
|
|
|
27
27
|
"import": "./dist/context.js"
|
|
28
28
|
},
|
|
29
29
|
"./utils": {
|
|
30
|
-
"types": "./dist/utils.d.ts",
|
|
31
|
-
"import": "./dist/utils.js"
|
|
30
|
+
"types": "./dist/utils/index.d.ts",
|
|
31
|
+
"import": "./dist/utils/index.js"
|
|
32
32
|
},
|
|
33
33
|
"./types": {
|
|
34
34
|
"types": "./dist/types.d.ts",
|
|
35
35
|
"import": "./dist/types.js"
|
|
36
|
+
},
|
|
37
|
+
"./internal": {
|
|
38
|
+
"types": "./dist/internal/index.d.ts",
|
|
39
|
+
"import": "./dist/internal/index.js"
|
|
40
|
+
},
|
|
41
|
+
"./nuxt": {
|
|
42
|
+
"types": "./dist/ecosystem/nuxt.d.ts",
|
|
43
|
+
"import": "./dist/ecosystem/nuxt.js"
|
|
36
44
|
}
|
|
37
45
|
},
|
|
38
46
|
"main": "./dist/index.js",
|
|
47
|
+
"module": "./dist/index.js",
|
|
39
48
|
"types": "./dist/index.d.ts",
|
|
40
49
|
"files": [
|
|
41
50
|
"dist"
|
|
42
51
|
],
|
|
43
52
|
"peerDependencies": {
|
|
53
|
+
"graphql": "^16.11.0",
|
|
44
54
|
"nitropack": "^2.11.13"
|
|
45
55
|
},
|
|
46
56
|
"dependencies": {
|
|
47
57
|
"@graphql-codegen/core": "^4.0.2",
|
|
48
|
-
"@graphql-codegen/plugin-helpers": "^5.1.1",
|
|
49
58
|
"@graphql-codegen/typescript": "^4.1.6",
|
|
50
59
|
"@graphql-codegen/typescript-generic-sdk": "^4.0.2",
|
|
51
60
|
"@graphql-codegen/typescript-operations": "^4.6.1",
|
|
@@ -59,19 +68,22 @@
|
|
|
59
68
|
"chokidar": "^4.0.3",
|
|
60
69
|
"consola": "^3.4.2",
|
|
61
70
|
"defu": "^6.1.4",
|
|
62
|
-
"graphql": "^16.11.0",
|
|
63
71
|
"graphql-scalars": "^1.24.2",
|
|
64
|
-
"graphql-yoga": "^5.
|
|
72
|
+
"graphql-yoga": "^5.15.1",
|
|
73
|
+
"ohash": "^2.0.11",
|
|
65
74
|
"pathe": "^2.0.3",
|
|
66
|
-
"perfect-debounce": "^1.0.0",
|
|
67
75
|
"tinyglobby": "^0.2.14"
|
|
68
76
|
},
|
|
69
77
|
"devDependencies": {
|
|
70
78
|
"@antfu/eslint-config": "^4.16.2",
|
|
79
|
+
"@graphql-codegen/import-types-preset": "^3.0.1",
|
|
80
|
+
"@nuxt/kit": "4.0.0-rc.0",
|
|
81
|
+
"@nuxt/schema": "4.0.0-rc.0",
|
|
71
82
|
"@types/node": "^20.19.7",
|
|
72
83
|
"bumpp": "^10.2.0",
|
|
73
84
|
"changelogen": "^0.6.2",
|
|
74
|
-
"eslint": "^9.
|
|
85
|
+
"eslint": "^9.31.0",
|
|
86
|
+
"graphql": "^16.11.0",
|
|
75
87
|
"h3": "^1.15.3",
|
|
76
88
|
"nitropack": "^2.11.13",
|
|
77
89
|
"tsdown": "^0.12.9",
|
package/dist/client-watcher.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { NitroGraphQLOptions } from "./types.js";
|
|
2
|
-
import { Nitro } from "nitropack/types";
|
|
3
|
-
|
|
4
|
-
//#region src/client-watcher.d.ts
|
|
5
|
-
declare function setupClientWatcher(nitro: Nitro, options: NitroGraphQLOptions): Promise<void>;
|
|
6
|
-
//#endregion
|
|
7
|
-
export { setupClientWatcher };
|
package/dist/client-watcher.js
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { scanGraphQLFiles } from "./scanner.js";
|
|
2
|
-
import { mkdir, writeFile } from "node:fs/promises";
|
|
3
|
-
import { mergeTypeDefs } from "@graphql-tools/merge";
|
|
4
|
-
import { makeExecutableSchema } from "@graphql-tools/schema";
|
|
5
|
-
import { consola } from "consola";
|
|
6
|
-
import { join } from "pathe";
|
|
7
|
-
import { debounce } from "perfect-debounce";
|
|
8
|
-
|
|
9
|
-
//#region src/client-watcher.ts
|
|
10
|
-
const logger = consola.withTag("graphql");
|
|
11
|
-
async function regenerateClientTypes(nitro, options) {
|
|
12
|
-
try {
|
|
13
|
-
if (!options.client?.enabled) return;
|
|
14
|
-
const scanResult = await scanGraphQLFiles(nitro);
|
|
15
|
-
if (scanResult.typeDefs.length === 0) {
|
|
16
|
-
logger.warn("⚠️ No server schema found for client type generation");
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
const mergedTypeDefs = mergeTypeDefs(scanResult.typeDefs);
|
|
20
|
-
const schema = makeExecutableSchema({
|
|
21
|
-
typeDefs: mergedTypeDefs,
|
|
22
|
-
resolvers: {}
|
|
23
|
-
});
|
|
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");
|
|
37
|
-
const generatedTypes = await generateClientTypes(schema, clientPatterns, options.client.config, options.client.outputPath);
|
|
38
|
-
if (generatedTypes) {
|
|
39
|
-
const outputPath = options.client.outputPath || join(nitro.options.buildDir, "types", "graphql-client.generated.ts");
|
|
40
|
-
const typesDir = join(nitro.options.buildDir, "types");
|
|
41
|
-
await mkdir(typesDir, { recursive: true });
|
|
42
|
-
await writeFile(outputPath, generatedTypes);
|
|
43
|
-
logger.success("✨ Client types updated");
|
|
44
|
-
}
|
|
45
|
-
} catch (error) {
|
|
46
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
47
|
-
logger.error("❌ Client type generation failed:", errorMessage);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
async function setupClientWatcher(nitro, options) {
|
|
51
|
-
if (!options.client?.enabled) {
|
|
52
|
-
logger.info("🚫 Client type generation disabled");
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
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();
|
|
63
|
-
const generateClientTypesDebounced = debounce(async () => {
|
|
64
|
-
await regenerateClientTypes(nitro, options);
|
|
65
|
-
}, 300);
|
|
66
|
-
const { watch } = await import("chokidar");
|
|
67
|
-
const watcher = watch(clientPatterns, {
|
|
68
|
-
persistent: true,
|
|
69
|
-
ignoreInitial: true,
|
|
70
|
-
ignored: [/(^|[/\\])\.\.\./, join(nitro.options.srcDir, "graphql/**/*")],
|
|
71
|
-
followSymlinks: false,
|
|
72
|
-
usePolling: true,
|
|
73
|
-
interval: 500,
|
|
74
|
-
binaryInterval: 500
|
|
75
|
-
});
|
|
76
|
-
watcher.on("add", (path) => {
|
|
77
|
-
logger.info(`📁 Client file added: ${path}`);
|
|
78
|
-
generateClientTypesDebounced();
|
|
79
|
-
});
|
|
80
|
-
watcher.on("change", (path) => {
|
|
81
|
-
logger.info(`📝 Client file changed: ${path}`);
|
|
82
|
-
generateClientTypesDebounced();
|
|
83
|
-
});
|
|
84
|
-
watcher.on("unlink", (path) => {
|
|
85
|
-
logger.info(`🗑️ Client file removed: ${path}`);
|
|
86
|
-
generateClientTypesDebounced();
|
|
87
|
-
});
|
|
88
|
-
watcher.on("error", (error) => {
|
|
89
|
-
logger.error("❌ Client watcher error:", error);
|
|
90
|
-
});
|
|
91
|
-
nitro.hooks.hook("close", () => {
|
|
92
|
-
logger.info("🔒 Closing client watcher");
|
|
93
|
-
watcher.close();
|
|
94
|
-
});
|
|
95
|
-
await regenerateClientTypes(nitro, options);
|
|
96
|
-
logger.success("✅ Client watcher ready");
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
//#endregion
|
|
100
|
-
export { setupClientWatcher };
|
package/dist/dev.js
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
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 };
|