nitro-graphql 2.0.0-beta.7 → 2.0.0-beta.72
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 +31 -1196
- package/dist/cli/adapter.d.mts +13 -0
- package/dist/cli/adapter.mjs +67 -0
- package/dist/cli/commands/build.d.mts +21 -0
- package/dist/cli/commands/build.mjs +50 -0
- package/dist/cli/commands/dev.d.mts +40 -0
- package/dist/cli/commands/dev.mjs +74 -0
- package/dist/cli/commands/generate.d.mts +25 -0
- package/dist/cli/commands/generate.mjs +198 -0
- package/dist/cli/commands/index.d.mts +5 -0
- package/dist/cli/commands/index.mjs +5 -0
- package/dist/cli/commands/init.d.mts +45 -0
- package/dist/cli/commands/init.mjs +195 -0
- package/dist/cli/commands/validate.d.mts +9 -0
- package/dist/cli/commands/validate.mjs +65 -0
- package/dist/cli/completions.d.mts +6 -0
- package/dist/cli/completions.mjs +32 -0
- package/dist/cli/config.d.mts +18 -0
- package/dist/cli/config.mjs +19 -0
- package/dist/cli/index.d.mts +26 -0
- package/dist/cli/index.mjs +315 -0
- package/dist/cli/server/debug-handler.d.mts +9 -0
- package/dist/cli/server/debug-handler.mjs +68 -0
- package/dist/cli/server/dev-server.d.mts +29 -0
- package/dist/cli/server/dev-server.mjs +62 -0
- package/dist/cli/server/graphql-handler.d.mts +21 -0
- package/dist/cli/server/graphql-handler.mjs +43 -0
- package/dist/cli/server/health-handler.d.mts +12 -0
- package/dist/cli/server/health-handler.mjs +29 -0
- package/dist/cli/server/loader.d.mts +33 -0
- package/dist/cli/server/loader.mjs +144 -0
- package/dist/cli/server/sandbox-handler.d.mts +12 -0
- package/dist/cli/server/sandbox-handler.mjs +17 -0
- package/dist/cli/server/watcher.d.mts +20 -0
- package/dist/cli/server/watcher.mjs +64 -0
- package/dist/cli/server/ws-handler.d.mts +28 -0
- package/dist/cli/server/ws-handler.mjs +48 -0
- package/dist/config.d.mts +2 -0
- package/dist/config.mjs +2 -0
- package/dist/core/codegen/client.d.mts +42 -0
- package/dist/core/codegen/client.mjs +551 -0
- package/dist/core/codegen/document-loader.d.mts +9 -0
- package/dist/core/codegen/document-loader.mjs +16 -0
- package/dist/core/codegen/index.d.mts +8 -0
- package/dist/core/codegen/index.mjs +8 -0
- package/dist/core/codegen/plugin.d.mts +19 -0
- package/dist/core/codegen/plugin.mjs +29 -0
- package/dist/core/codegen/runtime.d.mts +17 -0
- package/dist/core/codegen/runtime.mjs +61 -0
- package/dist/core/codegen/schema-loader.d.mts +27 -0
- package/dist/core/codegen/schema-loader.mjs +126 -0
- package/dist/core/codegen/server.d.mts +27 -0
- package/dist/core/codegen/server.mjs +142 -0
- package/dist/core/codegen/validation.d.mts +17 -0
- package/dist/core/codegen/validation.mjs +33 -0
- package/dist/core/config.d.mts +45 -0
- package/dist/core/config.mjs +76 -0
- package/dist/core/constants.d.mts +188 -0
- package/dist/core/constants.mjs +208 -0
- package/dist/core/debug/index.d.mts +2 -0
- package/dist/core/debug/index.mjs +2 -0
- package/dist/core/debug/template.d.mts +52 -0
- package/dist/core/debug/template.mjs +384 -0
- package/dist/core/extend/index.d.mts +2 -0
- package/dist/core/extend/index.mjs +2 -0
- package/dist/core/extend/loader.d.mts +40 -0
- package/dist/core/extend/loader.mjs +196 -0
- package/dist/core/index.d.mts +33 -0
- package/dist/core/index.mjs +28 -0
- package/dist/core/manifest.d.mts +56 -0
- package/dist/core/manifest.mjs +100 -0
- package/dist/core/pubsub/index.d.mts +109 -0
- package/dist/core/pubsub/index.mjs +146 -0
- package/dist/core/scanning/ast-scanner.d.mts +27 -0
- package/dist/core/scanning/ast-scanner.mjs +114 -0
- package/dist/core/scanning/common.d.mts +25 -0
- package/dist/core/scanning/common.mjs +57 -0
- package/dist/core/scanning/directives.d.mts +13 -0
- package/dist/core/scanning/directives.mjs +28 -0
- package/dist/core/scanning/documents.d.mts +20 -0
- package/dist/core/scanning/documents.mjs +36 -0
- package/dist/core/scanning/index.d.mts +7 -0
- package/dist/core/scanning/index.mjs +7 -0
- package/dist/core/scanning/resolvers.d.mts +14 -0
- package/dist/core/scanning/resolvers.mjs +58 -0
- package/dist/core/scanning/schemas.d.mts +13 -0
- package/dist/core/scanning/schemas.mjs +50 -0
- package/dist/core/schema/builder.d.mts +59 -0
- package/dist/core/schema/builder.mjs +76 -0
- package/dist/core/schema/federation.d.mts +33 -0
- package/dist/core/schema/federation.mjs +38 -0
- package/dist/core/schema/index.d.mts +3 -0
- package/dist/core/schema/index.mjs +3 -0
- package/dist/core/server/index.d.mts +4 -0
- package/dist/core/server/index.mjs +3 -0
- package/dist/core/server/sandbox.d.mts +18 -0
- package/dist/core/server/sandbox.mjs +38 -0
- package/dist/core/server/types.d.mts +54 -0
- package/dist/core/server/types.mjs +1 -0
- package/dist/core/server/yoga.d.mts +42 -0
- package/dist/core/server/yoga.mjs +87 -0
- package/dist/core/types/adapter.d.mts +55 -0
- package/dist/core/types/adapter.mjs +1 -0
- package/dist/core/types/codegen.d.mts +136 -0
- package/dist/core/types/codegen.mjs +1 -0
- package/dist/core/types/config.d.mts +188 -0
- package/dist/core/types/config.mjs +1 -0
- package/dist/{utils/define.d.ts → core/types/define.d.mts} +2 -30
- package/dist/core/types/define.mjs +1 -0
- package/dist/core/types/index.d.mts +5 -0
- package/dist/core/types/index.mjs +1 -0
- package/dist/core/types/scanning.d.mts +64 -0
- package/dist/core/types/scanning.mjs +1 -0
- package/dist/{utils/directive-parser.d.ts → core/utils/directive-parser.d.mts} +18 -4
- package/dist/{utils/directive-parser.js → core/utils/directive-parser.mjs} +29 -36
- package/dist/core/utils/errors.d.mts +77 -0
- package/dist/core/utils/errors.mjs +91 -0
- package/dist/core/utils/file-io.d.mts +24 -0
- package/dist/core/utils/file-io.mjs +45 -0
- package/dist/core/utils/imports.d.mts +15 -0
- package/dist/core/utils/imports.mjs +24 -0
- package/dist/core/utils/index.d.mts +7 -0
- package/dist/core/utils/index.mjs +7 -0
- package/dist/core/utils/logger.d.mts +18 -0
- package/dist/core/utils/logger.mjs +36 -0
- package/dist/core/utils/ofetch-templates.d.mts +30 -0
- package/dist/core/utils/ofetch-templates.mjs +134 -0
- package/dist/core/utils/runtime.d.mts +74 -0
- package/dist/core/utils/runtime.mjs +109 -0
- package/dist/core/utils/subscribe-templates.d.mts +8 -0
- package/dist/core/utils/subscribe-templates.mjs +58 -0
- package/dist/core/validation/external-services.d.mts +11 -0
- package/dist/core/validation/external-services.mjs +33 -0
- package/dist/core/validation/index.d.mts +2 -0
- package/dist/core/validation/index.mjs +2 -0
- package/dist/core/watcher/index.d.mts +107 -0
- package/dist/core/watcher/index.mjs +140 -0
- package/dist/define.d.mts +294 -0
- package/dist/define.mjs +323 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.mjs +5 -0
- package/dist/nitro/adapter.d.mts +28 -0
- package/dist/nitro/adapter.mjs +90 -0
- package/dist/{utils/apollo.d.ts → nitro/apollo.d.mts} +3 -3
- package/dist/nitro/apollo.mjs +57 -0
- package/dist/nitro/codegen.d.mts +18 -0
- package/dist/nitro/codegen.mjs +171 -0
- package/dist/nitro/config.d.mts +50 -0
- package/dist/nitro/config.mjs +55 -0
- package/dist/nitro/index.d.mts +45 -0
- package/dist/nitro/index.mjs +63 -0
- package/dist/{utils/path-resolver.d.ts → nitro/paths.d.mts} +8 -25
- package/dist/nitro/paths.mjs +97 -0
- package/dist/nitro/rollup.d.mts +6 -0
- package/dist/nitro/rollup.mjs +52 -0
- package/dist/nitro/routes/apollo-sandbox-script.d.mts +6 -0
- package/dist/nitro/routes/apollo-sandbox-script.mjs +12 -0
- package/dist/nitro/routes/apollo-server-ws.d.mts +15 -0
- package/dist/nitro/routes/apollo-server-ws.mjs +50 -0
- package/dist/nitro/routes/apollo-server.d.mts +6 -0
- package/dist/nitro/routes/apollo-server.mjs +69 -0
- package/dist/{routes/debug.d.ts → nitro/routes/debug.d.mts} +12 -19
- package/dist/nitro/routes/debug.mjs +98 -0
- package/dist/nitro/routes/graphql-yoga-ws.d.mts +12 -0
- package/dist/nitro/routes/graphql-yoga-ws.mjs +50 -0
- package/dist/nitro/routes/graphql-yoga.d.mts +12 -0
- package/dist/nitro/routes/graphql-yoga.mjs +39 -0
- package/dist/nitro/routes/health.d.mts +10 -0
- package/dist/{routes/health.js → nitro/routes/health.mjs} +5 -6
- package/dist/nitro/setup/extend-loader.d.mts +16 -0
- package/dist/nitro/setup/extend-loader.mjs +80 -0
- package/dist/nitro/setup/file-watcher.d.mts +18 -0
- package/dist/nitro/setup/file-watcher.mjs +62 -0
- package/dist/nitro/setup/logging.d.mts +16 -0
- package/dist/nitro/setup/logging.mjs +64 -0
- package/dist/nitro/setup/rollup-integration.d.mts +24 -0
- package/dist/nitro/setup/rollup-integration.mjs +64 -0
- package/dist/nitro/setup/routes.d.mts +13 -0
- package/dist/nitro/setup/routes.mjs +69 -0
- package/dist/nitro/setup/scanner.d.mts +59 -0
- package/dist/nitro/setup/scanner.mjs +118 -0
- package/dist/nitro/setup/ts-config.d.mts +10 -0
- package/dist/nitro/setup/ts-config.mjs +67 -0
- package/dist/nitro/setup.d.mts +11 -0
- package/dist/nitro/setup.mjs +189 -0
- package/dist/nitro/types.d.mts +549 -0
- package/dist/nitro/types.mjs +1 -0
- package/dist/nitro/virtual/generators.d.mts +38 -0
- package/dist/nitro/virtual/generators.mjs +190 -0
- package/dist/nitro/virtual/stubs.d.mts +21 -0
- package/dist/nitro/virtual/stubs.mjs +31 -0
- package/dist/{ecosystem/nuxt.d.ts → nuxt.d.mts} +1 -1
- package/dist/nuxt.mjs +111 -0
- package/dist/{graphql/server.d.ts → stubs/index.d.mts} +5 -1
- package/dist/stubs/index.mjs +1 -0
- package/dist/subscribe/index.d.mts +78 -0
- package/dist/subscribe/index.mjs +205 -0
- package/native/index.d.ts +20 -0
- package/native/index.js +585 -0
- package/package.json +202 -112
- package/dist/ecosystem/nuxt.js +0 -67
- package/dist/graphql/index.d.ts +0 -5
- package/dist/graphql/index.js +0 -1
- package/dist/graphql/server.js +0 -1
- package/dist/index.d.ts +0 -8
- package/dist/index.js +0 -318
- package/dist/rollup.js +0 -277
- package/dist/routes/apollo-server.d.ts +0 -6
- package/dist/routes/apollo-server.js +0 -89
- package/dist/routes/debug.js +0 -449
- package/dist/routes/graphql-yoga.d.ts +0 -6
- package/dist/routes/graphql-yoga.js +0 -91
- package/dist/routes/health.d.ts +0 -10
- package/dist/types/index.d.ts +0 -246
- package/dist/types/standard-schema.d.ts +0 -59
- package/dist/utils/apollo.js +0 -61
- package/dist/utils/client-codegen.d.ts +0 -38
- package/dist/utils/client-codegen.js +0 -290
- package/dist/utils/define.js +0 -57
- package/dist/utils/file-generator.d.ts +0 -37
- package/dist/utils/file-generator.js +0 -72
- package/dist/utils/index.d.ts +0 -39
- package/dist/utils/index.js +0 -278
- package/dist/utils/path-resolver.js +0 -127
- package/dist/utils/server-codegen.d.ts +0 -7
- package/dist/utils/server-codegen.js +0 -136
- package/dist/utils/type-generation.d.ts +0 -7
- package/dist/utils/type-generation.js +0 -360
- package/dist/virtual/debug-info.d.ts +0 -9
- package/dist/virtual/debug-info.js +0 -26
- package/dist/virtual/graphql-config.d.ts +0 -9
- package/dist/virtual/graphql-config.js +0 -10
- package/dist/virtual/module-config.d.ts +0 -9
- package/dist/virtual/module-config.js +0 -10
- package/dist/virtual/server-directives.d.ts +0 -11
- package/dist/virtual/server-directives.js +0 -10
- package/dist/virtual/server-resolvers.d.ts +0 -11
- package/dist/virtual/server-resolvers.js +0 -10
- package/dist/virtual/server-schemas.d.ts +0 -11
- package/dist/virtual/server-schemas.js +0 -10
- package/dist/vite.d.ts +0 -25
- package/dist/vite.js +0 -40
package/dist/utils/define.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
//#region src/utils/define.ts
|
|
2
|
-
function defineSchema(config) {
|
|
3
|
-
return config;
|
|
4
|
-
}
|
|
5
|
-
function defineResolver(resolvers) {
|
|
6
|
-
return resolvers;
|
|
7
|
-
}
|
|
8
|
-
function defineQuery(resolvers = {}) {
|
|
9
|
-
return { Query: { ...resolvers } };
|
|
10
|
-
}
|
|
11
|
-
function defineMutation(resolvers = {}) {
|
|
12
|
-
return { Mutation: { ...resolvers } };
|
|
13
|
-
}
|
|
14
|
-
function defineSubscription(resolvers = {}) {
|
|
15
|
-
return { Subscription: { ...resolvers } };
|
|
16
|
-
}
|
|
17
|
-
function defineType(resolvers) {
|
|
18
|
-
return resolvers;
|
|
19
|
-
}
|
|
20
|
-
function defineGraphQLConfig(config) {
|
|
21
|
-
return config;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Helper function to create directive arguments with proper type inference
|
|
25
|
-
* @example
|
|
26
|
-
* args: {
|
|
27
|
-
* myArg: arg('String!', { defaultValue: 'hello' })
|
|
28
|
-
* }
|
|
29
|
-
*/
|
|
30
|
-
function arg(type, options) {
|
|
31
|
-
return {
|
|
32
|
-
type,
|
|
33
|
-
...options
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
function defineDirective(config) {
|
|
37
|
-
const args = config.args ? Object.entries(config.args).map(([name, arg$1]) => {
|
|
38
|
-
const defaultValue = arg$1.defaultValue !== void 0 ? ` = ${JSON.stringify(arg$1.defaultValue)}` : "";
|
|
39
|
-
return `${name}: ${arg$1.type}${defaultValue}`;
|
|
40
|
-
}).join(", ") : "";
|
|
41
|
-
const argsString = args ? `(${args})` : "";
|
|
42
|
-
const locations = config.locations.join(" | ");
|
|
43
|
-
const schemaDefinition = `directive @${config.name}${argsString} on ${locations}`;
|
|
44
|
-
Object.defineProperty(config, "__schema", {
|
|
45
|
-
value: schemaDefinition,
|
|
46
|
-
enumerable: false,
|
|
47
|
-
configurable: false,
|
|
48
|
-
writable: false
|
|
49
|
-
});
|
|
50
|
-
return {
|
|
51
|
-
...config,
|
|
52
|
-
locations: [...config.locations]
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
//#endregion
|
|
57
|
-
export { arg, defineDirective, defineGraphQLConfig, defineMutation, defineQuery, defineResolver, defineSchema, defineSubscription, defineType };
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { Nitro } from "nitropack/types";
|
|
2
|
-
|
|
3
|
-
//#region src/utils/file-generator.d.ts
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Safely write a file to disk, creating parent directories if needed
|
|
7
|
-
*/
|
|
8
|
-
declare function writeFile(filePath: string, content: string, description?: string): void;
|
|
9
|
-
/**
|
|
10
|
-
* Write a file only if it doesn't already exist
|
|
11
|
-
* Returns true if file was created, false if it already existed
|
|
12
|
-
*/
|
|
13
|
-
declare function writeFileIfNotExists(filePath: string, content: string, description?: string): boolean;
|
|
14
|
-
/**
|
|
15
|
-
* Write a file and always overwrite (used for generated files like SDK)
|
|
16
|
-
* This is for files that are auto-generated and should be updated on every build
|
|
17
|
-
*/
|
|
18
|
-
declare function writeGeneratedFile(filePath: string, content: string, description?: string): void;
|
|
19
|
-
/**
|
|
20
|
-
* Check if a path is configured and should be generated
|
|
21
|
-
* Returns the resolved path if should generate, null otherwise
|
|
22
|
-
*/
|
|
23
|
-
declare function getGenerationPath(resolvedPath: string | null, description?: string): string | null;
|
|
24
|
-
/**
|
|
25
|
-
* Log skipped file generation (helpful for debugging library mode)
|
|
26
|
-
*/
|
|
27
|
-
declare function logSkipped(fileName: string, reason?: string): void;
|
|
28
|
-
/**
|
|
29
|
-
* Log generated file path
|
|
30
|
-
*/
|
|
31
|
-
declare function logGenerated(fileName: string, path: string): void;
|
|
32
|
-
/**
|
|
33
|
-
* Validate that a Nitro instance has the required GraphQL configuration
|
|
34
|
-
*/
|
|
35
|
-
declare function validateGraphQLConfig(nitro: Nitro): boolean;
|
|
36
|
-
//#endregion
|
|
37
|
-
export { getGenerationPath, logGenerated, logSkipped, validateGraphQLConfig, writeFile, writeFileIfNotExists, writeGeneratedFile };
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
2
|
-
import consola from "consola";
|
|
3
|
-
import { dirname } from "pathe";
|
|
4
|
-
|
|
5
|
-
//#region src/utils/file-generator.ts
|
|
6
|
-
/**
|
|
7
|
-
* Safely write a file to disk, creating parent directories if needed
|
|
8
|
-
*/
|
|
9
|
-
function writeFile(filePath, content, description) {
|
|
10
|
-
try {
|
|
11
|
-
const dir = dirname(filePath);
|
|
12
|
-
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
|
13
|
-
writeFileSync(filePath, content, "utf-8");
|
|
14
|
-
if (description) consola.success(`[nitro-graphql] Generated: ${description}`);
|
|
15
|
-
} catch (error) {
|
|
16
|
-
consola.error(`[nitro-graphql] Failed to write file: ${filePath}`, error);
|
|
17
|
-
throw error;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Write a file only if it doesn't already exist
|
|
22
|
-
* Returns true if file was created, false if it already existed
|
|
23
|
-
*/
|
|
24
|
-
function writeFileIfNotExists(filePath, content, description) {
|
|
25
|
-
if (existsSync(filePath)) return false;
|
|
26
|
-
writeFile(filePath, content, description);
|
|
27
|
-
return true;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Write a file and always overwrite (used for generated files like SDK)
|
|
31
|
-
* This is for files that are auto-generated and should be updated on every build
|
|
32
|
-
*/
|
|
33
|
-
function writeGeneratedFile(filePath, content, description) {
|
|
34
|
-
writeFile(filePath, content, description);
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Check if a path is configured and should be generated
|
|
38
|
-
* Returns the resolved path if should generate, null otherwise
|
|
39
|
-
*/
|
|
40
|
-
function getGenerationPath(resolvedPath, description) {
|
|
41
|
-
if (!resolvedPath) {
|
|
42
|
-
if (description) consola.debug(`[nitro-graphql] Skipping generation: ${description} (disabled in config)`);
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
return resolvedPath;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Log skipped file generation (helpful for debugging library mode)
|
|
49
|
-
*/
|
|
50
|
-
function logSkipped(fileName, reason) {
|
|
51
|
-
const message = reason ? `Skipped ${fileName}: ${reason}` : `Skipped ${fileName}`;
|
|
52
|
-
consola.debug(`[nitro-graphql] ${message}`);
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Log generated file path
|
|
56
|
-
*/
|
|
57
|
-
function logGenerated(fileName, path) {
|
|
58
|
-
consola.info(`[nitro-graphql] Generated ${fileName} at: ${path}`);
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Validate that a Nitro instance has the required GraphQL configuration
|
|
62
|
-
*/
|
|
63
|
-
function validateGraphQLConfig(nitro) {
|
|
64
|
-
if (!nitro.options.graphql?.framework) {
|
|
65
|
-
consola.warn("[nitro-graphql] No GraphQL framework specified. Some features may not work correctly.");
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
return true;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
//#endregion
|
|
72
|
-
export { getGenerationPath, logGenerated, logSkipped, validateGraphQLConfig, writeFile, writeFileIfNotExists, writeGeneratedFile };
|
package/dist/utils/index.d.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { GenImport } from "../types/index.js";
|
|
2
|
-
import { directiveParser, generateDirectiveSchema, generateDirectiveSchemas } from "./directive-parser.js";
|
|
3
|
-
import { Nitro } from "nitro/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
|
-
/**
|
|
8
|
-
* Get all Nuxt layer directories from Nitro config
|
|
9
|
-
*/
|
|
10
|
-
declare function getLayerDirectories(nitro: Nitro): string[];
|
|
11
|
-
/**
|
|
12
|
-
* Get all Nuxt layer server directories from Nitro config
|
|
13
|
-
*/
|
|
14
|
-
declare function getLayerServerDirectories(nitro: Nitro): string[];
|
|
15
|
-
/**
|
|
16
|
-
* Get all Nuxt layer app directories from Nitro config
|
|
17
|
-
*/
|
|
18
|
-
declare function getLayerAppDirectories(nitro: Nitro): string[];
|
|
19
|
-
/**
|
|
20
|
-
* Generate layer-aware ignore patterns for auto-generated files
|
|
21
|
-
*/
|
|
22
|
-
declare function generateLayerIgnorePatterns(): string[];
|
|
23
|
-
declare function getImportId(p: string, lazy?: boolean): string;
|
|
24
|
-
declare function relativeWithDot(from: string, to: string): string;
|
|
25
|
-
declare function scanGraphql(nitro: Nitro): Promise<string[]>;
|
|
26
|
-
declare function scanResolvers(nitro: Nitro): Promise<GenImport[]>;
|
|
27
|
-
declare function scanDirectives(nitro: Nitro): Promise<GenImport[]>;
|
|
28
|
-
declare function scanSchemas(nitro: Nitro): Promise<string[]>;
|
|
29
|
-
declare function scanDocs(nitro: Nitro): Promise<string[]>;
|
|
30
|
-
/**
|
|
31
|
-
* Scan documents for a specific external service
|
|
32
|
-
*/
|
|
33
|
-
declare function scanExternalServiceDocs(nitro: Nitro, serviceName: string, patterns: string[]): Promise<string[]>;
|
|
34
|
-
/**
|
|
35
|
-
* Validate external GraphQL service configuration
|
|
36
|
-
*/
|
|
37
|
-
declare function validateExternalServices(services: unknown[]): string[];
|
|
38
|
-
//#endregion
|
|
39
|
-
export { GLOB_SCAN_PATTERN, directiveParser, generateDirectiveSchema, generateDirectiveSchemas, generateLayerIgnorePatterns, getImportId, getLayerAppDirectories, getLayerDirectories, getLayerServerDirectories, relativeWithDot, scanDirectives, scanDocs, scanExternalServiceDocs, scanGraphql, scanResolvers, scanSchemas, validateExternalServices };
|
package/dist/utils/index.js
DELETED
|
@@ -1,278 +0,0 @@
|
|
|
1
|
-
import { directiveParser, generateDirectiveSchema, generateDirectiveSchemas } from "./directive-parser.js";
|
|
2
|
-
import { join, relative } from "pathe";
|
|
3
|
-
import { readFile } from "node:fs/promises";
|
|
4
|
-
import { hash } from "ohash";
|
|
5
|
-
import { parseAsync } from "oxc-parser";
|
|
6
|
-
import { glob } from "tinyglobby";
|
|
7
|
-
|
|
8
|
-
//#region src/utils/index.ts
|
|
9
|
-
const GLOB_SCAN_PATTERN = "**/*.{graphql,gql,js,mjs,cjs,ts,mts,cts,tsx,jsx}";
|
|
10
|
-
/**
|
|
11
|
-
* Get all Nuxt layer directories from Nitro config
|
|
12
|
-
*/
|
|
13
|
-
function getLayerDirectories(nitro) {
|
|
14
|
-
return nitro.options.graphql?.layerDirectories || [];
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Get all Nuxt layer server directories from Nitro config
|
|
18
|
-
*/
|
|
19
|
-
function getLayerServerDirectories(nitro) {
|
|
20
|
-
return nitro.options.graphql?.layerServerDirs || [];
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Get all Nuxt layer app directories from Nitro config
|
|
24
|
-
*/
|
|
25
|
-
function getLayerAppDirectories(nitro) {
|
|
26
|
-
return nitro.options.graphql?.layerAppDirs || [];
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Generate layer-aware ignore patterns for auto-generated files
|
|
30
|
-
*/
|
|
31
|
-
function generateLayerIgnorePatterns() {
|
|
32
|
-
return [];
|
|
33
|
-
}
|
|
34
|
-
function getImportId(p, lazy) {
|
|
35
|
-
return (lazy ? "_lazy_" : "_") + hash(p).replace(/-/g, "").slice(0, 6);
|
|
36
|
-
}
|
|
37
|
-
const RELATIVE_RE = /^\.{1,2}\//;
|
|
38
|
-
function relativeWithDot(from, to) {
|
|
39
|
-
const rel = relative(from, to);
|
|
40
|
-
return RELATIVE_RE.test(rel) ? rel : `./${rel}`;
|
|
41
|
-
}
|
|
42
|
-
async function scanGraphql(nitro) {
|
|
43
|
-
const serverDirRelative = relative(nitro.options.rootDir, nitro.graphql.serverDir);
|
|
44
|
-
const files = await scanDir(nitro, nitro.options.rootDir, serverDirRelative, "**/*.{graphql,gql}");
|
|
45
|
-
const layerServerDirs = getLayerServerDirectories(nitro);
|
|
46
|
-
const layerFiles = await Promise.all(layerServerDirs.map((layerServerDir) => scanDir(nitro, layerServerDir, "graphql", "**/*.{graphql,gql}"))).then((r) => r.flat());
|
|
47
|
-
const allFiles = [...files, ...layerFiles];
|
|
48
|
-
const seenPaths = /* @__PURE__ */ new Set();
|
|
49
|
-
return allFiles.filter((file) => {
|
|
50
|
-
if (seenPaths.has(file.fullPath)) return false;
|
|
51
|
-
seenPaths.add(file.fullPath);
|
|
52
|
-
return true;
|
|
53
|
-
}).map((f) => f.fullPath);
|
|
54
|
-
}
|
|
55
|
-
async function scanResolvers(nitro) {
|
|
56
|
-
const serverDirRelative = relative(nitro.options.rootDir, nitro.graphql.serverDir);
|
|
57
|
-
const regularFiles = await scanDir(nitro, nitro.options.rootDir, serverDirRelative, "**/*.resolver.{ts,js}");
|
|
58
|
-
const layerServerDirs = getLayerServerDirectories(nitro);
|
|
59
|
-
const layerFiles = await Promise.all(layerServerDirs.map((layerServerDir) => scanDir(nitro, layerServerDir, "graphql", "**/*.resolver.{ts,js}"))).then((r) => r.flat());
|
|
60
|
-
const allFiles = [...regularFiles, ...layerFiles];
|
|
61
|
-
const seenPaths = /* @__PURE__ */ new Set();
|
|
62
|
-
const files = allFiles.filter((file) => {
|
|
63
|
-
if (seenPaths.has(file.fullPath)) return false;
|
|
64
|
-
seenPaths.add(file.fullPath);
|
|
65
|
-
return true;
|
|
66
|
-
});
|
|
67
|
-
const exportName = [];
|
|
68
|
-
const VALID_DEFINE_FUNCTIONS = [
|
|
69
|
-
"defineResolver",
|
|
70
|
-
"defineQuery",
|
|
71
|
-
"defineMutation",
|
|
72
|
-
"defineType",
|
|
73
|
-
"defineSubscription",
|
|
74
|
-
"defineDirective"
|
|
75
|
-
];
|
|
76
|
-
for (const file of files) try {
|
|
77
|
-
const fileContent = await readFile(file.fullPath, "utf-8");
|
|
78
|
-
const parsed = await parseAsync(file.fullPath, fileContent);
|
|
79
|
-
const exports = {
|
|
80
|
-
imports: [],
|
|
81
|
-
specifier: file.fullPath
|
|
82
|
-
};
|
|
83
|
-
let hasDefaultExport = false;
|
|
84
|
-
let hasNamedExport = false;
|
|
85
|
-
const namedExports = [];
|
|
86
|
-
for (const node of parsed.program.body) {
|
|
87
|
-
if (node.type === "ExportDefaultDeclaration") hasDefaultExport = true;
|
|
88
|
-
if (node.type === "ExportNamedDeclaration" && node.declaration && node.declaration.type === "VariableDeclaration") {
|
|
89
|
-
for (const decl of node.declaration.declarations) if (decl.type === "VariableDeclarator" && decl.init && decl.id.type === "Identifier") {
|
|
90
|
-
hasNamedExport = true;
|
|
91
|
-
namedExports.push(decl.id.name);
|
|
92
|
-
if (decl.init && decl.init.type === "CallExpression") {
|
|
93
|
-
if (decl.init.callee.type === "Identifier" && decl.init.callee.name === "defineResolver") exports.imports.push({
|
|
94
|
-
name: decl.id.name,
|
|
95
|
-
type: "resolver",
|
|
96
|
-
as: `_${hash(decl.id.name + file.fullPath).replace(/-/g, "").slice(0, 6)}`
|
|
97
|
-
});
|
|
98
|
-
if (decl.init.callee.type === "Identifier" && decl.init.callee.name === "defineQuery") exports.imports.push({
|
|
99
|
-
name: decl.id.name,
|
|
100
|
-
type: "query",
|
|
101
|
-
as: `_${hash(decl.id.name + file.fullPath).replace(/-/g, "").slice(0, 6)}`
|
|
102
|
-
});
|
|
103
|
-
if (decl.init.callee.type === "Identifier" && decl.init.callee.name === "defineMutation") exports.imports.push({
|
|
104
|
-
name: decl.id.name,
|
|
105
|
-
type: "mutation",
|
|
106
|
-
as: `_${hash(decl.id.name + file.fullPath).replace(/-/g, "").slice(0, 6)}`
|
|
107
|
-
});
|
|
108
|
-
if (decl.init.callee.type === "Identifier" && decl.init.callee.name === "defineType") exports.imports.push({
|
|
109
|
-
name: decl.id.name,
|
|
110
|
-
type: "type",
|
|
111
|
-
as: `_${hash(decl.id.name + file.fullPath).replace(/-/g, "").slice(0, 6)}`
|
|
112
|
-
});
|
|
113
|
-
if (decl.init.callee.type === "Identifier" && decl.init.callee.name === "defineSubscription") exports.imports.push({
|
|
114
|
-
name: decl.id.name,
|
|
115
|
-
type: "subscription",
|
|
116
|
-
as: `_${hash(decl.id.name + file.fullPath).replace(/-/g, "").slice(0, 6)}`
|
|
117
|
-
});
|
|
118
|
-
if (decl.init.callee.type === "Identifier" && decl.init.callee.name === "defineDirective") exports.imports.push({
|
|
119
|
-
name: decl.id.name,
|
|
120
|
-
type: "directive",
|
|
121
|
-
as: `_${hash(decl.id.name + file.fullPath).replace(/-/g, "").slice(0, 6)}`
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
if (nitro.options.dev) {
|
|
128
|
-
const relPath = relative(nitro.options.rootDir, file.fullPath);
|
|
129
|
-
if (hasDefaultExport && !hasNamedExport) nitro.logger.warn(`[nitro-graphql] ${relPath}: Using default export instead of named export. Resolvers must use named exports like "export const myResolver = defineQuery(...)". Default exports are not detected.`);
|
|
130
|
-
if (exports.imports.length === 0 && hasNamedExport) {
|
|
131
|
-
const validFunctions = VALID_DEFINE_FUNCTIONS.join(", ");
|
|
132
|
-
nitro.logger.warn(`[nitro-graphql] ${relPath}: File has named exports [${namedExports.join(", ")}] but none use the required define functions (${validFunctions}). Exports will not be registered.`);
|
|
133
|
-
}
|
|
134
|
-
if (!hasDefaultExport && !hasNamedExport) nitro.logger.warn(`[nitro-graphql] ${relPath}: No exports found. Resolver files must export resolvers using defineResolver, defineQuery, defineMutation, etc.`);
|
|
135
|
-
}
|
|
136
|
-
if (exports.imports.length > 0) exportName.push(exports);
|
|
137
|
-
} catch (error) {
|
|
138
|
-
const relPath = relative(nitro.options.rootDir, file.fullPath);
|
|
139
|
-
nitro.logger.error(`[nitro-graphql] Failed to parse resolver file ${relPath}:`, error);
|
|
140
|
-
}
|
|
141
|
-
return exportName;
|
|
142
|
-
}
|
|
143
|
-
async function scanDirectives(nitro) {
|
|
144
|
-
const serverDirRelative = relative(nitro.options.rootDir, nitro.graphql.serverDir);
|
|
145
|
-
const regularFiles = await scanDir(nitro, nitro.options.rootDir, serverDirRelative, "**/*.directive.{ts,js}");
|
|
146
|
-
const layerServerDirs = getLayerServerDirectories(nitro);
|
|
147
|
-
const layerFiles = await Promise.all(layerServerDirs.map((layerServerDir) => scanDir(nitro, layerServerDir, "graphql", "**/*.directive.{ts,js}"))).then((r) => r.flat());
|
|
148
|
-
const allFiles = [...regularFiles, ...layerFiles];
|
|
149
|
-
const seenPaths = /* @__PURE__ */ new Set();
|
|
150
|
-
const files = allFiles.filter((file) => {
|
|
151
|
-
if (seenPaths.has(file.fullPath)) return false;
|
|
152
|
-
seenPaths.add(file.fullPath);
|
|
153
|
-
return true;
|
|
154
|
-
});
|
|
155
|
-
const exportName = [];
|
|
156
|
-
for (const file of files) {
|
|
157
|
-
const fileContent = await readFile(file.fullPath, "utf-8");
|
|
158
|
-
const parsed = await parseAsync(file.fullPath, fileContent);
|
|
159
|
-
const exports = {
|
|
160
|
-
imports: [],
|
|
161
|
-
specifier: file.fullPath
|
|
162
|
-
};
|
|
163
|
-
for (const node of parsed.program.body) if (node.type === "ExportNamedDeclaration" && node.declaration && node.declaration.type === "VariableDeclaration") {
|
|
164
|
-
for (const decl of node.declaration.declarations) if (decl.type === "VariableDeclarator" && decl.init && decl.id.type === "Identifier") {
|
|
165
|
-
if (decl.init && decl.init.type === "CallExpression") {
|
|
166
|
-
if (decl.init.callee.type === "Identifier" && decl.init.callee.name === "defineDirective") exports.imports.push({
|
|
167
|
-
name: decl.id.name,
|
|
168
|
-
type: "directive",
|
|
169
|
-
as: `_${hash(decl.id.name + file.fullPath).replace(/-/g, "").slice(0, 6)}`
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
if (exports.imports.length > 0) exportName.push(exports);
|
|
175
|
-
}
|
|
176
|
-
return exportName;
|
|
177
|
-
}
|
|
178
|
-
async function scanSchemas(nitro) {
|
|
179
|
-
const serverDirRelative = relative(nitro.options.rootDir, nitro.graphql.serverDir);
|
|
180
|
-
const files = await scanDir(nitro, nitro.options.rootDir, serverDirRelative, "**/*.graphql");
|
|
181
|
-
const layerServerDirs = getLayerServerDirectories(nitro);
|
|
182
|
-
const layerFiles = await Promise.all(layerServerDirs.map((layerServerDir) => scanDir(nitro, layerServerDir, "graphql", "**/*.graphql"))).then((r) => r.flat());
|
|
183
|
-
const allFiles = [...files, ...layerFiles];
|
|
184
|
-
const seenPaths = /* @__PURE__ */ new Set();
|
|
185
|
-
return allFiles.filter((file) => {
|
|
186
|
-
if (seenPaths.has(file.fullPath)) return false;
|
|
187
|
-
seenPaths.add(file.fullPath);
|
|
188
|
-
return true;
|
|
189
|
-
}).map((f) => f.fullPath);
|
|
190
|
-
}
|
|
191
|
-
async function scanDocs(nitro) {
|
|
192
|
-
const files = await scanDir(nitro, nitro.options.rootDir, nitro.graphql.dir.client, "**/*.graphql");
|
|
193
|
-
const layerAppDirs = getLayerAppDirectories(nitro);
|
|
194
|
-
const layerFiles = await Promise.all(layerAppDirs.map((layerAppDir) => scanDir(nitro, layerAppDir, "graphql", "**/*.graphql"))).then((r) => r.flat());
|
|
195
|
-
const combinedFiles = [...files, ...layerFiles];
|
|
196
|
-
const seenPaths = /* @__PURE__ */ new Set();
|
|
197
|
-
const allFiles = combinedFiles.filter((file) => {
|
|
198
|
-
if (seenPaths.has(file.fullPath)) return false;
|
|
199
|
-
seenPaths.add(file.fullPath);
|
|
200
|
-
return true;
|
|
201
|
-
});
|
|
202
|
-
const externalPatterns = (nitro.options.graphql?.externalServices || []).flatMap((service) => service.documents || []);
|
|
203
|
-
return allFiles.filter((f) => !f.path.startsWith("external/")).filter((f) => {
|
|
204
|
-
const relativePath = f.path;
|
|
205
|
-
for (const pattern of externalPatterns) {
|
|
206
|
-
const clientDirPattern = `${nitro.graphql.dir.client}/`;
|
|
207
|
-
if (pattern.replace(/* @__PURE__ */ new RegExp(`^${clientDirPattern.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}`), "").split("/")[0] === relativePath.split("/")[0]) return false;
|
|
208
|
-
}
|
|
209
|
-
return true;
|
|
210
|
-
}).map((f) => f.fullPath);
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* Scan documents for a specific external service
|
|
214
|
-
*/
|
|
215
|
-
async function scanExternalServiceDocs(nitro, serviceName, patterns) {
|
|
216
|
-
if (!patterns.length) return [];
|
|
217
|
-
const files = [];
|
|
218
|
-
for (const pattern of patterns) try {
|
|
219
|
-
const serviceFiles = await glob(pattern, {
|
|
220
|
-
cwd: nitro.options.rootDir,
|
|
221
|
-
dot: true,
|
|
222
|
-
ignore: nitro.options.ignore,
|
|
223
|
-
absolute: true
|
|
224
|
-
});
|
|
225
|
-
files.push(...serviceFiles);
|
|
226
|
-
} catch (error) {
|
|
227
|
-
nitro.logger.warn(`[graphql:${serviceName}] Error scanning documents with pattern "${pattern}":`, error);
|
|
228
|
-
}
|
|
229
|
-
return files.filter((file, index, self) => self.indexOf(file) === index);
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* Validate external GraphQL service configuration
|
|
233
|
-
*/
|
|
234
|
-
function validateExternalServices(services) {
|
|
235
|
-
const errors = [];
|
|
236
|
-
const serviceNames = /* @__PURE__ */ new Set();
|
|
237
|
-
for (const [index, service] of services.entries()) {
|
|
238
|
-
const prefix = `externalServices[${index}]`;
|
|
239
|
-
if (!service || typeof service !== "object") {
|
|
240
|
-
errors.push(`${prefix} must be an object`);
|
|
241
|
-
continue;
|
|
242
|
-
}
|
|
243
|
-
if (!("name" in service) || typeof service.name !== "string") errors.push(`${prefix}.name is required and must be a string`);
|
|
244
|
-
else if (serviceNames.has(service.name)) errors.push(`${prefix}.name "${service.name}" must be unique`);
|
|
245
|
-
else serviceNames.add(service.name);
|
|
246
|
-
if (!("schema" in service) || !service.schema) errors.push(`${prefix}.schema is required`);
|
|
247
|
-
if (!("endpoint" in service) || typeof service.endpoint !== "string") errors.push(`${prefix}.endpoint is required and must be a string`);
|
|
248
|
-
else try {
|
|
249
|
-
new URL(service.endpoint);
|
|
250
|
-
} catch {
|
|
251
|
-
errors.push(`${prefix}.endpoint "${service.endpoint}" must be a valid URL`);
|
|
252
|
-
}
|
|
253
|
-
if ("name" in service && service.name && typeof service.name === "string" && !/^[a-z]\w*$/i.test(service.name)) errors.push(`${prefix}.name "${service.name}" must be a valid identifier (letters, numbers, underscore, starting with letter)`);
|
|
254
|
-
}
|
|
255
|
-
return errors;
|
|
256
|
-
}
|
|
257
|
-
async function scanDir(nitro, dir, name, globPattern = GLOB_SCAN_PATTERN) {
|
|
258
|
-
return (await glob(join(name, globPattern), {
|
|
259
|
-
cwd: dir,
|
|
260
|
-
dot: true,
|
|
261
|
-
ignore: nitro.options.ignore,
|
|
262
|
-
absolute: true
|
|
263
|
-
}).catch((error) => {
|
|
264
|
-
if (error?.code === "ENOTDIR") {
|
|
265
|
-
nitro.logger.warn(`Ignoring \`${join(dir, name)}\`. It must be a directory.`);
|
|
266
|
-
return [];
|
|
267
|
-
}
|
|
268
|
-
throw error;
|
|
269
|
-
})).map((fullPath) => {
|
|
270
|
-
return {
|
|
271
|
-
fullPath,
|
|
272
|
-
path: relative(join(dir, name), fullPath)
|
|
273
|
-
};
|
|
274
|
-
}).sort((a, b) => a.path.localeCompare(b.path));
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
//#endregion
|
|
278
|
-
export { GLOB_SCAN_PATTERN, directiveParser, generateDirectiveSchema, generateDirectiveSchemas, generateLayerIgnorePatterns, getImportId, getLayerAppDirectories, getLayerDirectories, getLayerServerDirectories, relativeWithDot, scanDirectives, scanDocs, scanExternalServiceDocs, scanGraphql, scanResolvers, scanSchemas, validateExternalServices };
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { resolve } from "pathe";
|
|
2
|
-
|
|
3
|
-
//#region src/utils/path-resolver.ts
|
|
4
|
-
/**
|
|
5
|
-
* Replace placeholders in a path string
|
|
6
|
-
* Supports: {serviceName}, {buildDir}, {rootDir}, {framework}, {typesDir}, {serverGraphql}, {clientGraphql}
|
|
7
|
-
*/
|
|
8
|
-
function replacePlaceholders(path, placeholders) {
|
|
9
|
-
return path.replace(/\{serviceName\}/g, placeholders.serviceName || "default").replace(/\{buildDir\}/g, placeholders.buildDir).replace(/\{rootDir\}/g, placeholders.rootDir).replace(/\{framework\}/g, placeholders.framework).replace(/\{typesDir\}/g, placeholders.typesDir).replace(/\{serverGraphql\}/g, placeholders.serverGraphql).replace(/\{clientGraphql\}/g, placeholders.clientGraphql);
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Get default paths based on framework and user configuration
|
|
13
|
-
*/
|
|
14
|
-
function getDefaultPaths(nitro) {
|
|
15
|
-
const isNuxt = nitro.options.framework?.name === "nuxt";
|
|
16
|
-
const rootDir = nitro.options.rootDir;
|
|
17
|
-
const buildDir = nitro.options.buildDir;
|
|
18
|
-
const pathsConfig = nitro.options.graphql?.paths || {};
|
|
19
|
-
const defaultServerGraphql = pathsConfig.serverGraphql || resolve(rootDir, "server", "graphql");
|
|
20
|
-
const defaultClientGraphql = pathsConfig.clientGraphql || resolve(rootDir, isNuxt ? "app/graphql" : "graphql");
|
|
21
|
-
const defaultBuildDir = pathsConfig.buildDir || buildDir;
|
|
22
|
-
const defaultTypesDir = pathsConfig.typesDir || resolve(defaultBuildDir, "types");
|
|
23
|
-
return {
|
|
24
|
-
serviceName: "default",
|
|
25
|
-
buildDir: defaultBuildDir,
|
|
26
|
-
rootDir,
|
|
27
|
-
framework: isNuxt ? "nuxt" : "nitro",
|
|
28
|
-
typesDir: defaultTypesDir,
|
|
29
|
-
serverGraphql: defaultServerGraphql,
|
|
30
|
-
clientGraphql: defaultClientGraphql
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Check if a file should be generated based on config
|
|
35
|
-
* Returns: true if should generate, false if should skip
|
|
36
|
-
*/
|
|
37
|
-
function shouldGenerateFile(config, categoryEnabled, topLevelEnabled) {
|
|
38
|
-
if (config === false) return false;
|
|
39
|
-
if (config === true || typeof config === "string") return true;
|
|
40
|
-
if (categoryEnabled === false) return false;
|
|
41
|
-
if (categoryEnabled === true) return true;
|
|
42
|
-
return topLevelEnabled;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Resolve the file path based on configuration
|
|
46
|
-
* Returns: resolved absolute path or null if file should not be generated
|
|
47
|
-
*/
|
|
48
|
-
function resolveFilePath(config, categoryEnabled, topLevelEnabled, defaultPath, placeholders) {
|
|
49
|
-
if (!shouldGenerateFile(config, categoryEnabled, topLevelEnabled)) return null;
|
|
50
|
-
if (typeof config === "string") {
|
|
51
|
-
const customPath = replacePlaceholders(config, placeholders);
|
|
52
|
-
return resolve(placeholders.rootDir, customPath);
|
|
53
|
-
}
|
|
54
|
-
const resolvedDefault = replacePlaceholders(defaultPath, placeholders);
|
|
55
|
-
return resolve(placeholders.rootDir, resolvedDefault);
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Check if scaffold files should be generated (category-level check)
|
|
59
|
-
*/
|
|
60
|
-
function shouldGenerateScaffold(nitro) {
|
|
61
|
-
const scaffoldConfig = nitro.options.graphql?.scaffold;
|
|
62
|
-
if (scaffoldConfig === false) return false;
|
|
63
|
-
if (scaffoldConfig && scaffoldConfig.enabled === false) return false;
|
|
64
|
-
return true;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Get scaffold configuration (handles false case)
|
|
68
|
-
*/
|
|
69
|
-
function getScaffoldConfig(nitro) {
|
|
70
|
-
const scaffoldConfig = nitro.options.graphql?.scaffold;
|
|
71
|
-
if (scaffoldConfig === false) return { enabled: false };
|
|
72
|
-
return scaffoldConfig || {};
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Check if client utilities should be generated (category-level check)
|
|
76
|
-
*/
|
|
77
|
-
function shouldGenerateClientUtils(nitro) {
|
|
78
|
-
const clientUtilsConfig = nitro.options.graphql?.clientUtils;
|
|
79
|
-
if (clientUtilsConfig === false) return false;
|
|
80
|
-
if (clientUtilsConfig && clientUtilsConfig.enabled === false) return false;
|
|
81
|
-
return nitro.options.framework?.name === "nuxt";
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Get client utilities configuration (handles false case)
|
|
85
|
-
*/
|
|
86
|
-
function getClientUtilsConfig(nitro) {
|
|
87
|
-
const clientUtilsConfig = nitro.options.graphql?.clientUtils;
|
|
88
|
-
if (clientUtilsConfig === false) return { enabled: false };
|
|
89
|
-
return clientUtilsConfig || {};
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Check if SDK files should be generated (category-level check)
|
|
93
|
-
*/
|
|
94
|
-
function shouldGenerateSDK(nitro) {
|
|
95
|
-
const sdkConfig = nitro.options.graphql?.sdk;
|
|
96
|
-
if (sdkConfig === false) return false;
|
|
97
|
-
if (sdkConfig && sdkConfig.enabled === false) return false;
|
|
98
|
-
return true;
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Get SDK configuration (handles false case)
|
|
102
|
-
*/
|
|
103
|
-
function getSdkConfig(nitro) {
|
|
104
|
-
const sdkConfig = nitro.options.graphql?.sdk;
|
|
105
|
-
if (sdkConfig === false) return { enabled: false };
|
|
106
|
-
return sdkConfig || {};
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Check if type files should be generated (category-level check)
|
|
110
|
-
*/
|
|
111
|
-
function shouldGenerateTypes(nitro) {
|
|
112
|
-
const typesConfig = nitro.options.graphql?.types;
|
|
113
|
-
if (typesConfig === false) return false;
|
|
114
|
-
if (typesConfig && typesConfig.enabled === false) return false;
|
|
115
|
-
return true;
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Get types configuration (handles false case)
|
|
119
|
-
*/
|
|
120
|
-
function getTypesConfig(nitro) {
|
|
121
|
-
const typesConfig = nitro.options.graphql?.types;
|
|
122
|
-
if (typesConfig === false) return { enabled: false };
|
|
123
|
-
return typesConfig || {};
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
//#endregion
|
|
127
|
-
export { getClientUtilsConfig, getDefaultPaths, getScaffoldConfig, getSdkConfig, getTypesConfig, replacePlaceholders, resolveFilePath, shouldGenerateClientUtils, shouldGenerateFile, shouldGenerateSDK, shouldGenerateScaffold, shouldGenerateTypes };
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { NitroGraphQLOptions } from "../types/index.js";
|
|
2
|
-
import { GraphQLSchema } from "graphql";
|
|
3
|
-
|
|
4
|
-
//#region src/utils/server-codegen.d.ts
|
|
5
|
-
declare function generateTypes(selectFremework: string, schema: GraphQLSchema, config?: Partial<NitroGraphQLOptions>, outputPath?: string): Promise<string>;
|
|
6
|
-
//#endregion
|
|
7
|
-
export { generateTypes };
|