nitro-graphql 2.0.0-beta.70 → 2.0.0-beta.73
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 +1 -1
- package/dist/cli/adapter.d.mts +0 -3
- package/dist/cli/adapter.mjs +7 -32
- package/dist/cli/commands/build.d.mts +2 -2
- package/dist/cli/commands/build.mjs +1 -3
- package/dist/cli/commands/dev.d.mts +2 -2
- package/dist/cli/commands/dev.mjs +1 -3
- package/dist/cli/commands/generate.mjs +10 -10
- package/dist/cli/commands/init.mjs +4 -4
- package/dist/cli/commands/validate.mjs +1 -3
- package/dist/cli/completions.mjs +1 -3
- package/dist/cli/config.d.mts +4 -5
- package/dist/cli/config.mjs +4 -3
- package/dist/cli/index.d.mts +3 -6
- package/dist/cli/index.mjs +2 -4
- package/dist/cli/server/debug-handler.mjs +2 -5
- package/dist/cli/server/dev-server.mjs +1 -3
- package/dist/cli/server/graphql-handler.mjs +3 -4
- package/dist/cli/server/health-handler.mjs +1 -2
- package/dist/cli/server/loader.mjs +1 -3
- package/dist/cli/server/sandbox-handler.mjs +1 -3
- package/dist/cli/server/watcher.mjs +2 -4
- package/dist/cli/server/ws-handler.mjs +1 -3
- package/dist/config.mjs +1 -2
- package/dist/core/codegen/client.d.mts +4 -27
- package/dist/core/codegen/client.mjs +26 -447
- package/dist/core/codegen/document-loader.mjs +1 -3
- package/dist/core/codegen/file-header.d.mts +7 -0
- package/dist/core/codegen/file-header.mjs +12 -0
- package/dist/core/codegen/index.d.mts +7 -5
- package/dist/core/codegen/index.mjs +7 -6
- package/dist/core/codegen/{runtime.d.mts → runtime-generator.d.mts} +1 -3
- package/dist/core/codegen/{runtime.mjs → runtime-generator.mjs} +7 -6
- package/dist/core/codegen/schema-loader.d.mts +2 -7
- package/dist/core/codegen/schema-loader.mjs +66 -73
- package/dist/core/codegen/server-type-helpers.d.mts +14 -0
- package/dist/core/codegen/server-type-helpers.mjs +76 -0
- package/dist/core/codegen/server.d.mts +1 -15
- package/dist/core/codegen/server.mjs +15 -107
- package/dist/core/codegen/subscription-extractor.d.mts +20 -0
- package/dist/core/codegen/subscription-extractor.mjs +30 -0
- package/dist/core/codegen/validation.mjs +1 -3
- package/dist/core/codegen/vue-subscription-builder.d.mts +10 -0
- package/dist/core/codegen/vue-subscription-builder.mjs +351 -0
- package/dist/core/constants.d.mts +5 -53
- package/dist/core/constants.mjs +13 -56
- package/dist/core/create-config.d.mts +31 -0
- package/dist/core/create-config.mjs +42 -0
- package/dist/core/debug/index.d.mts +2 -2
- package/dist/core/debug/index.mjs +2 -3
- package/dist/core/debug/template.d.mts +1 -5
- package/dist/core/debug/template.mjs +5 -4
- package/dist/core/extend/index.mjs +1 -2
- package/dist/core/extend/loader.d.mts +0 -1
- package/dist/core/extend/loader.mjs +60 -92
- package/dist/core/index.d.mts +22 -21
- package/dist/core/index.mjs +19 -16
- package/dist/core/manifest.mjs +4 -4
- package/dist/core/pubsub/index.d.mts +2 -109
- package/dist/core/pubsub/index.mjs +2 -148
- package/dist/core/pubsub/memory-pubsub.d.mts +109 -0
- package/dist/core/pubsub/memory-pubsub.mjs +146 -0
- package/dist/core/scanning/ast-scanner.mjs +5 -5
- package/dist/core/scanning/directives.mjs +3 -5
- package/dist/core/scanning/documents.d.mts +4 -3
- package/dist/core/scanning/documents.mjs +4 -5
- package/dist/core/scanning/{common.d.mts → file-scanner.d.mts} +1 -1
- package/dist/core/scanning/{common.mjs → file-scanner.mjs} +3 -13
- package/dist/core/scanning/index.d.mts +3 -3
- package/dist/core/scanning/index.mjs +3 -4
- package/dist/core/scanning/resolvers.mjs +9 -11
- package/dist/core/scanning/schemas.d.mts +1 -5
- package/dist/core/scanning/schemas.mjs +2 -26
- package/dist/core/schema/builder.d.mts +4 -2
- package/dist/core/schema/builder.mjs +4 -4
- package/dist/core/schema/federation.mjs +1 -3
- package/dist/core/schema/index.d.mts +2 -2
- package/dist/core/schema/index.mjs +2 -3
- package/dist/core/server/apollo.d.mts +20 -0
- package/dist/core/server/apollo.mjs +54 -0
- package/dist/core/server/index.d.mts +4 -2
- package/dist/core/server/index.mjs +3 -3
- package/dist/core/server/sandbox.mjs +1 -2
- package/dist/core/server/types.d.mts +7 -14
- package/dist/core/server/types.mjs +15 -1
- package/dist/core/server/yoga.d.mts +1 -7
- package/dist/core/server/yoga.mjs +4 -15
- package/dist/core/types/adapter.d.mts +3 -40
- package/dist/core/types/adapter.mjs +1 -1
- package/dist/core/types/codegen.d.mts +22 -45
- package/dist/core/types/codegen.mjs +1 -1
- package/dist/core/types/config.d.mts +33 -121
- package/dist/core/types/config.mjs +1 -1
- package/dist/core/types/define.d.mts +8 -5
- package/dist/core/types/define.mjs +1 -1
- package/dist/core/types/index.d.mts +5 -4
- package/dist/core/types/index.mjs +1 -1
- package/dist/core/types/scanning.d.mts +4 -1
- package/dist/core/types/scanning.mjs +1 -1
- package/dist/core/types/standard-schema.d.mts +64 -0
- package/dist/core/types/standard-schema.mjs +1 -0
- package/dist/core/utils/directive-parser.d.mts +8 -63
- package/dist/core/utils/directive-parser.mjs +114 -167
- package/dist/core/utils/errors.mjs +1 -3
- package/dist/core/utils/file-io.d.mts +1 -5
- package/dist/core/utils/file-io.mjs +1 -13
- package/dist/core/utils/imports.mjs +3 -4
- package/dist/core/utils/index.d.mts +5 -4
- package/dist/core/utils/index.mjs +6 -6
- package/dist/core/utils/logger.d.mts +1 -10
- package/dist/core/utils/logger.mjs +1 -21
- package/dist/core/utils/ofetch-templates.mjs +4 -6
- package/dist/core/utils/runtime.d.mts +1 -30
- package/dist/core/utils/runtime.mjs +2 -46
- package/dist/core/utils/string.d.mts +10 -0
- package/dist/core/utils/string.mjs +12 -0
- package/dist/core/utils/subscribe-templates.mjs +1 -2
- package/dist/core/validation/external-services.mjs +3 -3
- package/dist/core/validation/index.mjs +1 -2
- package/dist/core/watcher/create-watcher.d.mts +103 -0
- package/dist/core/watcher/create-watcher.mjs +143 -0
- package/dist/core/watcher/index.d.mts +2 -107
- package/dist/core/watcher/index.mjs +2 -141
- package/dist/define.d.mts +4 -2
- package/dist/define.mjs +8 -9
- package/dist/index.d.mts +4 -3
- package/dist/index.mjs +3 -4
- package/dist/nitro/adapter.d.mts +6 -11
- package/dist/nitro/adapter.mjs +12 -45
- package/dist/nitro/apollo.mjs +1 -3
- package/dist/nitro/codegen/client-types.d.mts +12 -0
- package/dist/nitro/codegen/client-types.mjs +73 -0
- package/dist/nitro/codegen/external-types.d.mts +8 -0
- package/dist/nitro/codegen/external-types.mjs +47 -0
- package/dist/nitro/codegen/index.d.mts +4 -0
- package/dist/nitro/codegen/index.mjs +4 -0
- package/dist/nitro/codegen/server-types.d.mts +12 -0
- package/dist/nitro/codegen/server-types.mjs +81 -0
- package/dist/nitro/defaults.d.mts +28 -0
- package/dist/nitro/defaults.mjs +34 -0
- package/dist/nitro/index.d.mts +11 -3
- package/dist/nitro/index.mjs +4 -6
- package/dist/nitro/paths.d.mts +3 -2
- package/dist/nitro/paths.mjs +14 -5
- package/dist/nitro/rollup.mjs +8 -8
- package/dist/nitro/routes/_ws-handler.d.mts +6 -0
- package/dist/nitro/routes/_ws-handler.mjs +49 -0
- package/dist/nitro/routes/apollo-sandbox-script.d.mts +2 -2
- package/dist/nitro/routes/apollo-sandbox-script.mjs +1 -3
- package/dist/nitro/routes/apollo-server-ws.d.mts +1 -1
- package/dist/nitro/routes/apollo-server-ws.mjs +10 -48
- package/dist/nitro/routes/apollo-server.d.mts +2 -2
- package/dist/nitro/routes/apollo-server.mjs +17 -58
- package/dist/nitro/routes/debug.d.mts +2 -2
- package/dist/nitro/routes/debug.mjs +4 -7
- package/dist/nitro/routes/graphql-yoga-ws.d.mts +3 -3
- package/dist/nitro/routes/graphql-yoga-ws.mjs +7 -48
- package/dist/nitro/routes/graphql-yoga.d.mts +2 -2
- package/dist/nitro/routes/graphql-yoga.mjs +8 -8
- package/dist/nitro/routes/health.d.mts +2 -2
- package/dist/nitro/routes/health.mjs +23 -27
- package/dist/nitro/setup/extend-loader.d.mts +6 -5
- package/dist/nitro/setup/extend-loader.mjs +31 -61
- package/dist/nitro/setup/file-watcher.mjs +9 -8
- package/dist/nitro/setup/logging.d.mts +1 -8
- package/dist/nitro/setup/logging.mjs +7 -24
- package/dist/nitro/setup/rollup-integration.mjs +36 -4
- package/dist/nitro/setup/routes.mjs +1 -3
- package/dist/nitro/setup/scanner.d.mts +8 -43
- package/dist/nitro/setup/scanner.mjs +56 -60
- package/dist/nitro/setup/security.d.mts +10 -0
- package/dist/nitro/setup/security.mjs +17 -0
- package/dist/nitro/setup/ts-config.mjs +1 -3
- package/dist/nitro/setup/type-generation.d.mts +13 -0
- package/dist/nitro/setup/type-generation.mjs +16 -0
- package/dist/nitro/setup.d.mts +4 -3
- package/dist/nitro/setup.mjs +88 -77
- package/dist/nitro/state.d.mts +32 -0
- package/dist/nitro/state.mjs +58 -0
- package/dist/nitro/types/augmentation.d.mts +59 -0
- package/dist/nitro/types/augmentation.mjs +1 -0
- package/dist/nitro/types/config.d.mts +327 -0
- package/dist/nitro/types/config.mjs +1 -0
- package/dist/nitro/types/define.d.mts +13 -0
- package/dist/nitro/types/define.mjs +1 -0
- package/dist/nitro/types/index.d.mts +10 -0
- package/dist/nitro/types/index.mjs +1 -0
- package/dist/nitro/virtual/debug-info.d.mts +9 -0
- package/dist/nitro/virtual/debug-info.mjs +35 -0
- package/dist/nitro/virtual/graphql-config.d.mts +9 -0
- package/dist/nitro/virtual/graphql-config.mjs +33 -0
- package/dist/nitro/virtual/index.d.mts +25 -0
- package/dist/nitro/virtual/index.mjs +45 -0
- package/dist/nitro/virtual/module-config.d.mts +9 -0
- package/dist/nitro/virtual/module-config.mjs +10 -0
- package/dist/nitro/virtual/pubsub.d.mts +9 -0
- package/dist/nitro/virtual/pubsub.mjs +17 -0
- package/dist/nitro/virtual/server-directives.d.mts +9 -0
- package/dist/nitro/virtual/server-directives.mjs +12 -0
- package/dist/nitro/virtual/server-resolvers.d.mts +9 -0
- package/dist/nitro/virtual/server-resolvers.mjs +17 -0
- package/dist/nitro/virtual/server-schemas.d.mts +9 -0
- package/dist/nitro/virtual/server-schemas.mjs +31 -0
- package/dist/nitro/virtual/stubs.d.mts +42 -10
- package/dist/nitro/virtual/stubs.mjs +1 -7
- package/dist/nitro/virtual/utils.d.mts +15 -0
- package/dist/nitro/virtual/utils.mjs +26 -0
- package/dist/nitro/virtual/validation-schemas.d.mts +9 -0
- package/dist/nitro/virtual/validation-schemas.mjs +33 -0
- package/dist/nuxt.mjs +4 -5
- package/dist/stubs/index.mjs +1 -1
- package/dist/subscribe/index.mjs +3 -4
- package/native/index.js +52 -52
- package/package.json +41 -41
- package/dist/cli/commands/index.d.mts +0 -5
- package/dist/cli/commands/index.mjs +0 -6
- package/dist/core/codegen/plugin.d.mts +0 -19
- package/dist/core/codegen/plugin.mjs +0 -30
- package/dist/core/config.d.mts +0 -45
- package/dist/core/config.mjs +0 -78
- package/dist/nitro/codegen.d.mts +0 -18
- package/dist/nitro/codegen.mjs +0 -173
- package/dist/nitro/config.d.mts +0 -50
- package/dist/nitro/config.mjs +0 -57
- package/dist/nitro/types.d.mts +0 -549
- package/dist/nitro/types.mjs +0 -1
- package/dist/nitro/virtual/generators.d.mts +0 -38
- package/dist/nitro/virtual/generators.mjs +0 -192
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/nitro/setup/security.ts
|
|
2
|
+
/**
|
|
3
|
+
* Resolves security configuration with environment-aware defaults
|
|
4
|
+
* In production: introspection off, playground off, errors masked, suggestions disabled
|
|
5
|
+
* In development: introspection on, playground on, errors shown, suggestions enabled
|
|
6
|
+
*/
|
|
7
|
+
function resolveSecurityConfig(config) {
|
|
8
|
+
const isProd = process.env.NODE_ENV === "production";
|
|
9
|
+
return {
|
|
10
|
+
introspection: config?.introspection ?? !isProd,
|
|
11
|
+
playground: config?.playground ?? !isProd,
|
|
12
|
+
maskErrors: config?.maskErrors ?? isProd,
|
|
13
|
+
disableSuggestions: config?.disableSuggestions ?? isProd
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
export { resolveSecurityConfig };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { relativeWithDot } from "../../core/utils/imports.mjs";
|
|
2
2
|
import { getDefaultPaths, getTypesConfig, resolveFilePath } from "../paths.mjs";
|
|
3
3
|
import { dirname, join, resolve } from "pathe";
|
|
4
|
-
|
|
5
4
|
//#region src/nitro/setup/ts-config.ts
|
|
6
5
|
/**
|
|
7
6
|
* Setup TypeScript path aliases for GraphQL types
|
|
@@ -64,6 +63,5 @@ function setupExternalServicePaths(nitro, types, tsconfigDir, placeholders, type
|
|
|
64
63
|
}
|
|
65
64
|
}
|
|
66
65
|
}
|
|
67
|
-
|
|
68
66
|
//#endregion
|
|
69
|
-
export { setupTypeScriptPaths };
|
|
67
|
+
export { setupTypeScriptPaths };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Nitro } from "nitro/types";
|
|
2
|
+
|
|
3
|
+
//#region src/nitro/setup/type-generation.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Regenerate all types (server + client)
|
|
6
|
+
* Shared helper that passes schema string directly to avoid disk round-trip
|
|
7
|
+
*/
|
|
8
|
+
declare function regenerateTypes(nitro: Nitro, options?: {
|
|
9
|
+
serverEnabled?: boolean;
|
|
10
|
+
silent?: boolean;
|
|
11
|
+
}): Promise<void>;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { regenerateTypes };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { generateClientTypes } from "../codegen/client-types.mjs";
|
|
2
|
+
import { generateServerTypes } from "../codegen/server-types.mjs";
|
|
3
|
+
import { isServerEnabled } from "./scanner.mjs";
|
|
4
|
+
//#region src/nitro/setup/type-generation.ts
|
|
5
|
+
/**
|
|
6
|
+
* Regenerate all types (server + client)
|
|
7
|
+
* Shared helper that passes schema string directly to avoid disk round-trip
|
|
8
|
+
*/
|
|
9
|
+
async function regenerateTypes(nitro, options = {}) {
|
|
10
|
+
const { serverEnabled = isServerEnabled(nitro), silent = false } = options;
|
|
11
|
+
const opts = silent ? { silent: true } : void 0;
|
|
12
|
+
if (serverEnabled) await generateClientTypes(nitro, opts, await generateServerTypes(nitro, opts));
|
|
13
|
+
else await generateClientTypes(nitro, opts);
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
export { regenerateTypes };
|
package/dist/nitro/setup.d.mts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { resolveSecurityConfig } from "./setup/
|
|
1
|
+
import { resolveSecurityConfig } from "./setup/security.mjs";
|
|
2
|
+
import { regenerateTypes } from "./setup/type-generation.mjs";
|
|
2
3
|
import { Nitro } from "nitro/types";
|
|
3
4
|
|
|
4
5
|
//#region src/nitro/setup.d.ts
|
|
5
6
|
/**
|
|
6
7
|
* Main setup function for nitro-graphql
|
|
7
|
-
*
|
|
8
|
+
* Executes setup resolvers in sequence
|
|
8
9
|
*/
|
|
9
10
|
declare function setupNitroGraphQL(nitro: Nitro): Promise<void>;
|
|
10
11
|
//#endregion
|
|
11
|
-
export { resolveSecurityConfig, setupNitroGraphQL };
|
|
12
|
+
export { regenerateTypes, resolveSecurityConfig, setupNitroGraphQL };
|
package/dist/nitro/setup.mjs
CHANGED
|
@@ -1,58 +1,56 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LOG_TAG } from "../core/constants.mjs";
|
|
2
2
|
import { validateExternalServices } from "../core/validation/external-services.mjs";
|
|
3
|
+
import { DEFAULT_RUNTIME_CONFIG, DEFAULT_TYPES_CONFIG } from "./defaults.mjs";
|
|
3
4
|
import { getDefaultPaths } from "./paths.mjs";
|
|
4
|
-
import { generateClientTypes, generateServerTypes } from "./codegen.mjs";
|
|
5
|
-
import { DEFAULT_RUNTIME_CONFIG, DEFAULT_TYPESCRIPT_STRICT, DEFAULT_TYPES_CONFIG } from "./config.mjs";
|
|
6
5
|
import { rollupConfig } from "./rollup.mjs";
|
|
6
|
+
import { emptyScanState } from "./state.mjs";
|
|
7
7
|
import { resolveExtendDirs } from "./setup/extend-loader.mjs";
|
|
8
8
|
import { isServerEnabled, logResolverDiagnostics, performGraphQLScan } from "./setup/scanner.mjs";
|
|
9
|
+
import { regenerateTypes } from "./setup/type-generation.mjs";
|
|
9
10
|
import { getWatchDirectories, setupFileWatcher } from "./setup/file-watcher.mjs";
|
|
10
|
-
import {
|
|
11
|
+
import { resolveSecurityConfig } from "./setup/security.mjs";
|
|
12
|
+
import { logStartupInfo } from "./setup/logging.mjs";
|
|
11
13
|
import { setupNoExternals, setupRollupChunking, setupRollupExternals } from "./setup/rollup-integration.mjs";
|
|
12
14
|
import { registerRouteHandlers } from "./setup/routes.mjs";
|
|
13
15
|
import { setupTypeScriptPaths } from "./setup/ts-config.mjs";
|
|
14
16
|
import defu from "defu";
|
|
15
17
|
import consola from "consola";
|
|
16
18
|
import { relative, resolve } from "pathe";
|
|
17
|
-
|
|
18
19
|
//#region src/nitro/setup.ts
|
|
19
20
|
const logger = consola.withTag(LOG_TAG);
|
|
20
21
|
/**
|
|
21
22
|
* Main setup function for nitro-graphql
|
|
22
|
-
*
|
|
23
|
+
* Executes setup resolvers in sequence
|
|
23
24
|
*/
|
|
24
25
|
async function setupNitroGraphQL(nitro) {
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (serverEnabled) registerRouteHandlers(nitro);
|
|
43
|
-
setupTypeScriptConfiguration(nitro);
|
|
44
|
-
setupNuxtIntegration(nitro);
|
|
45
|
-
logStartupInfo(nitro, serverEnabled);
|
|
26
|
+
const resolvers = [
|
|
27
|
+
resolveConfiguration,
|
|
28
|
+
resolveValidation,
|
|
29
|
+
resolveBuildDirectories,
|
|
30
|
+
resolveRollupIntegration,
|
|
31
|
+
resolveRuntimeConfig,
|
|
32
|
+
resolveFileWatching,
|
|
33
|
+
resolveGraphQLScan,
|
|
34
|
+
resolveDevHooks,
|
|
35
|
+
resolveVirtualModules,
|
|
36
|
+
resolveTypeGeneration,
|
|
37
|
+
resolveCloseHooks,
|
|
38
|
+
resolveRouteHandlers,
|
|
39
|
+
resolveTypeScriptConfig,
|
|
40
|
+
resolveStartupLogging
|
|
41
|
+
];
|
|
42
|
+
for (const resolver of resolvers) await resolver(nitro);
|
|
46
43
|
}
|
|
47
44
|
/**
|
|
48
|
-
*
|
|
45
|
+
* Resolve default configuration values and initialize Nitro GraphQL state
|
|
49
46
|
*/
|
|
50
|
-
function
|
|
47
|
+
function resolveConfiguration(nitro) {
|
|
51
48
|
nitro.options.graphql ||= {};
|
|
52
49
|
nitro.options.graphql.types = defu(nitro.options.graphql.types, DEFAULT_TYPES_CONFIG);
|
|
53
|
-
if (
|
|
50
|
+
if (isServerEnabled(nitro) && !nitro.options.graphql?.framework) logger.warn("No GraphQL framework specified. Please set graphql.framework to \"graphql-yoga\" or \"apollo-server\".");
|
|
54
51
|
const defaultPaths = getDefaultPaths(nitro);
|
|
55
52
|
nitro.graphql ||= {
|
|
53
|
+
state: emptyScanState(),
|
|
56
54
|
buildDir: "",
|
|
57
55
|
watchDirs: [],
|
|
58
56
|
clientDir: defaultPaths.clientDir,
|
|
@@ -76,9 +74,9 @@ function initializeConfiguration(nitro, serverEnabled) {
|
|
|
76
74
|
};
|
|
77
75
|
}
|
|
78
76
|
/**
|
|
79
|
-
* Validate external services configuration
|
|
77
|
+
* Validate external services and federation configuration
|
|
80
78
|
*/
|
|
81
|
-
function
|
|
79
|
+
function resolveValidation(nitro) {
|
|
82
80
|
if (nitro.options.graphql?.externalServices?.length) {
|
|
83
81
|
const validationErrors = validateExternalServices(nitro.options.graphql.externalServices);
|
|
84
82
|
if (validationErrors.length > 0) {
|
|
@@ -91,27 +89,26 @@ function validateConfiguration(nitro) {
|
|
|
91
89
|
if (nitro.options.graphql?.federation?.enabled) logger.info(`Apollo Federation enabled for service: ${nitro.options.graphql.federation.serviceName || "unnamed"}`);
|
|
92
90
|
}
|
|
93
91
|
/**
|
|
94
|
-
*
|
|
92
|
+
* Resolve build directories and relative paths
|
|
95
93
|
*/
|
|
96
|
-
function
|
|
97
|
-
|
|
98
|
-
nitro.graphql.
|
|
99
|
-
|
|
100
|
-
case FRAMEWORK_NUXT:
|
|
101
|
-
nitro.graphql.dir.client = relative(nitro.options.rootDir, nitro.graphql.clientDir);
|
|
102
|
-
nitro.graphql.dir.server = relative(nitro.options.rootDir, nitro.graphql.serverDir);
|
|
103
|
-
break;
|
|
104
|
-
case FRAMEWORK_NITRO:
|
|
105
|
-
nitro.graphql.dir.client = relative(nitro.options.rootDir, nitro.graphql.clientDir);
|
|
106
|
-
nitro.graphql.dir.server = relative(nitro.options.rootDir, nitro.graphql.serverDir);
|
|
107
|
-
break;
|
|
108
|
-
default: break;
|
|
109
|
-
}
|
|
94
|
+
function resolveBuildDirectories(nitro) {
|
|
95
|
+
nitro.graphql.buildDir = resolve(nitro.options.rootDir, ".graphql");
|
|
96
|
+
nitro.graphql.dir.client = relative(nitro.options.rootDir, nitro.graphql.clientDir);
|
|
97
|
+
nitro.graphql.dir.server = relative(nitro.options.rootDir, nitro.graphql.serverDir);
|
|
110
98
|
}
|
|
111
99
|
/**
|
|
112
|
-
*
|
|
100
|
+
* Resolve Rollup/Rolldown integration (externals, chunking, noExternals)
|
|
113
101
|
*/
|
|
114
|
-
function
|
|
102
|
+
function resolveRollupIntegration(nitro) {
|
|
103
|
+
if (!isServerEnabled(nitro)) return;
|
|
104
|
+
setupNoExternals(nitro);
|
|
105
|
+
setupRollupExternals(nitro);
|
|
106
|
+
setupRollupChunking(nitro);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Resolve runtime configuration with security defaults
|
|
110
|
+
*/
|
|
111
|
+
function resolveRuntimeConfig(nitro) {
|
|
115
112
|
const securityConfig = resolveSecurityConfig(nitro.options.graphql?.security);
|
|
116
113
|
nitro.options.runtimeConfig.graphql = defu(nitro.options.runtimeConfig.graphql || {}, {
|
|
117
114
|
...DEFAULT_RUNTIME_CONFIG,
|
|
@@ -119,20 +116,28 @@ function initializeRuntimeConfig(nitro) {
|
|
|
119
116
|
});
|
|
120
117
|
}
|
|
121
118
|
/**
|
|
122
|
-
*
|
|
119
|
+
* Resolve file watching for development mode
|
|
123
120
|
*/
|
|
124
|
-
function
|
|
121
|
+
async function resolveFileWatching(nitro) {
|
|
122
|
+
if (!nitro.options.dev) return;
|
|
123
|
+
const serverEnabled = isServerEnabled(nitro);
|
|
124
|
+
const extendDirs = await resolveExtendDirs(nitro);
|
|
125
125
|
const watchDirs = serverEnabled ? getWatchDirectories(nitro, extendDirs) : [nitro.graphql.clientDir].filter(Boolean);
|
|
126
126
|
nitro.graphql.watchDirs = watchDirs;
|
|
127
127
|
const watcher = setupFileWatcher(nitro, watchDirs);
|
|
128
|
-
nitro.hooks.hook("close", () =>
|
|
129
|
-
watcher.close();
|
|
130
|
-
});
|
|
128
|
+
nitro.hooks.hook("close", () => watcher.close());
|
|
131
129
|
}
|
|
132
130
|
/**
|
|
133
|
-
*
|
|
131
|
+
* Resolve initial GraphQL file scanning
|
|
134
132
|
*/
|
|
135
|
-
function
|
|
133
|
+
async function resolveGraphQLScan(nitro) {
|
|
134
|
+
await performGraphQLScan(nitro);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Resolve dev mode hooks for rescanning and diagnostics
|
|
138
|
+
*/
|
|
139
|
+
function resolveDevHooks(nitro) {
|
|
140
|
+
if (!isServerEnabled(nitro)) return;
|
|
136
141
|
let hasShownInitialLogs = false;
|
|
137
142
|
let lastDevStart = 0;
|
|
138
143
|
const DEBOUNCE_MS = 500;
|
|
@@ -151,41 +156,47 @@ function setupDevHooks(nitro) {
|
|
|
151
156
|
});
|
|
152
157
|
}
|
|
153
158
|
/**
|
|
154
|
-
*
|
|
159
|
+
* Resolve virtual modules registration via Rollup config
|
|
155
160
|
*/
|
|
156
|
-
async function
|
|
157
|
-
if (
|
|
158
|
-
|
|
159
|
-
await generateClientTypes(nitro, { isInitial: true });
|
|
160
|
-
} else await generateClientTypes(nitro, { isInitial: true });
|
|
161
|
+
async function resolveVirtualModules(nitro) {
|
|
162
|
+
if (!isServerEnabled(nitro)) return;
|
|
163
|
+
await rollupConfig(nitro);
|
|
161
164
|
}
|
|
162
165
|
/**
|
|
163
|
-
*
|
|
166
|
+
* Resolve initial type generation
|
|
164
167
|
*/
|
|
165
|
-
function
|
|
168
|
+
async function resolveTypeGeneration(nitro) {
|
|
169
|
+
await regenerateTypes(nitro, { serverEnabled: isServerEnabled(nitro) });
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Resolve close hooks for final type generation
|
|
173
|
+
*/
|
|
174
|
+
function resolveCloseHooks(nitro) {
|
|
166
175
|
nitro.hooks.hook("close", async () => {
|
|
167
|
-
|
|
168
|
-
await generateClientTypes(nitro, { silent: true });
|
|
176
|
+
await regenerateTypes(nitro, { silent: true });
|
|
169
177
|
});
|
|
170
178
|
}
|
|
171
179
|
/**
|
|
172
|
-
*
|
|
180
|
+
* Resolve route handler registration
|
|
173
181
|
*/
|
|
174
|
-
function
|
|
175
|
-
nitro
|
|
182
|
+
function resolveRouteHandlers(nitro) {
|
|
183
|
+
if (!isServerEnabled(nitro)) return;
|
|
184
|
+
registerRouteHandlers(nitro);
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Resolve TypeScript configuration and path aliases
|
|
188
|
+
*/
|
|
189
|
+
function resolveTypeScriptConfig(nitro) {
|
|
190
|
+
nitro.options.typescript.strict = true;
|
|
176
191
|
nitro.hooks.hook("types:extend", (types) => {
|
|
177
192
|
setupTypeScriptPaths(nitro, types);
|
|
178
193
|
});
|
|
179
194
|
}
|
|
180
195
|
/**
|
|
181
|
-
*
|
|
196
|
+
* Resolve startup logging
|
|
182
197
|
*/
|
|
183
|
-
function
|
|
184
|
-
|
|
185
|
-
const nuxtOptions = nitro._nuxt?.options;
|
|
186
|
-
if (nuxtOptions) nuxtOptions.nitroGraphqlExternalServices = nitro.options.graphql?.externalServices || [];
|
|
187
|
-
});
|
|
198
|
+
function resolveStartupLogging(nitro) {
|
|
199
|
+
logStartupInfo(nitro, isServerEnabled(nitro));
|
|
188
200
|
}
|
|
189
|
-
|
|
190
201
|
//#endregion
|
|
191
|
-
export { resolveSecurityConfig, setupNitroGraphQL };
|
|
202
|
+
export { regenerateTypes, resolveSecurityConfig, setupNitroGraphQL };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ScannedResolver } from "../core/types/scanning.mjs";
|
|
2
|
+
import { GraphQLScanState } from "./types/augmentation.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/nitro/state.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Create an empty scan state
|
|
7
|
+
*/
|
|
8
|
+
declare function emptyScanState(): GraphQLScanState;
|
|
9
|
+
/**
|
|
10
|
+
* Create a scan state from local scan results
|
|
11
|
+
*/
|
|
12
|
+
declare function createScanState(result: {
|
|
13
|
+
schemas: string[];
|
|
14
|
+
resolvers: ScannedResolver[];
|
|
15
|
+
directives: ScannedResolver[];
|
|
16
|
+
documents: string[];
|
|
17
|
+
directiveSchemas: string | null;
|
|
18
|
+
}): GraphQLScanState;
|
|
19
|
+
/**
|
|
20
|
+
* Merge extend results into an existing state, producing a new frozen snapshot.
|
|
21
|
+
* Deduplicates by path/specifier to prevent double-counting.
|
|
22
|
+
*/
|
|
23
|
+
declare function mergeScanState(base: GraphQLScanState, extend: {
|
|
24
|
+
schemas?: string[];
|
|
25
|
+
resolvers?: ScannedResolver[];
|
|
26
|
+
directives?: ScannedResolver[];
|
|
27
|
+
documents?: string[];
|
|
28
|
+
configPath?: string;
|
|
29
|
+
schemaPath?: string;
|
|
30
|
+
}): GraphQLScanState;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { createScanState, emptyScanState, mergeScanState };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
//#region src/nitro/state.ts
|
|
2
|
+
/**
|
|
3
|
+
* Create an empty scan state
|
|
4
|
+
*/
|
|
5
|
+
function emptyScanState() {
|
|
6
|
+
return Object.freeze({
|
|
7
|
+
schemas: [],
|
|
8
|
+
resolvers: [],
|
|
9
|
+
directives: [],
|
|
10
|
+
documents: [],
|
|
11
|
+
directiveSchemas: null,
|
|
12
|
+
extendConfigs: [],
|
|
13
|
+
extendSchemas: []
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Create a scan state from local scan results
|
|
18
|
+
*/
|
|
19
|
+
function createScanState(result) {
|
|
20
|
+
return Object.freeze({
|
|
21
|
+
schemas: [...result.schemas],
|
|
22
|
+
resolvers: [...result.resolvers],
|
|
23
|
+
directives: [...result.directives],
|
|
24
|
+
documents: [...result.documents],
|
|
25
|
+
directiveSchemas: result.directiveSchemas,
|
|
26
|
+
extendConfigs: [],
|
|
27
|
+
extendSchemas: []
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Merge extend results into an existing state, producing a new frozen snapshot.
|
|
32
|
+
* Deduplicates by path/specifier to prevent double-counting.
|
|
33
|
+
*/
|
|
34
|
+
function mergeScanState(base, extend) {
|
|
35
|
+
const schemas = [...base.schemas];
|
|
36
|
+
const resolvers = [...base.resolvers];
|
|
37
|
+
const directives = [...base.directives];
|
|
38
|
+
const documents = [...base.documents];
|
|
39
|
+
const extendConfigs = [...base.extendConfigs];
|
|
40
|
+
const extendSchemas = [...base.extendSchemas];
|
|
41
|
+
for (const s of extend.schemas || []) if (!schemas.includes(s)) schemas.push(s);
|
|
42
|
+
for (const r of extend.resolvers || []) if (!resolvers.some((existing) => existing.specifier === r.specifier)) resolvers.push(r);
|
|
43
|
+
for (const d of extend.directives || []) if (!directives.some((existing) => existing.specifier === d.specifier)) directives.push(d);
|
|
44
|
+
for (const doc of extend.documents || []) if (!documents.includes(doc)) documents.push(doc);
|
|
45
|
+
if (extend.configPath && !extendConfigs.includes(extend.configPath)) extendConfigs.push(extend.configPath);
|
|
46
|
+
if (extend.schemaPath && !extendSchemas.includes(extend.schemaPath)) extendSchemas.push(extend.schemaPath);
|
|
47
|
+
return Object.freeze({
|
|
48
|
+
schemas,
|
|
49
|
+
resolvers,
|
|
50
|
+
directives,
|
|
51
|
+
documents,
|
|
52
|
+
directiveSchemas: base.directiveSchemas,
|
|
53
|
+
extendConfigs,
|
|
54
|
+
extendSchemas
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
//#endregion
|
|
58
|
+
export { createScanState, emptyScanState, mergeScanState };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { ScannedResolver } from "../../core/types/scanning.mjs";
|
|
2
|
+
import { NitroGraphQLOptions } from "./config.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/nitro/types/augmentation.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Immutable scan state snapshot
|
|
7
|
+
* Built atomically from local scan + extend results.
|
|
8
|
+
* All consumers (virtual modules, codegen, logging) read from this single snapshot.
|
|
9
|
+
* Never mutate — replace the entire object for updates.
|
|
10
|
+
*/
|
|
11
|
+
interface GraphQLScanState {
|
|
12
|
+
readonly schemas: readonly string[];
|
|
13
|
+
readonly resolvers: readonly ScannedResolver[];
|
|
14
|
+
readonly directives: readonly ScannedResolver[];
|
|
15
|
+
readonly documents: readonly string[];
|
|
16
|
+
readonly directiveSchemas: string | null;
|
|
17
|
+
readonly extendConfigs: readonly string[];
|
|
18
|
+
readonly extendSchemas: readonly string[];
|
|
19
|
+
}
|
|
20
|
+
declare module 'nitro/types' {
|
|
21
|
+
interface Nitro {
|
|
22
|
+
/** @deprecated Use nitro.graphql.state.schemas — kept for backward compatibility */
|
|
23
|
+
scanSchemas: string[];
|
|
24
|
+
/** @deprecated Use nitro.graphql.state.documents */
|
|
25
|
+
scanDocuments: string[];
|
|
26
|
+
/** @deprecated Use nitro.graphql.state.resolvers */
|
|
27
|
+
scanResolvers: ScannedResolver[];
|
|
28
|
+
/** @deprecated Use nitro.graphql.state.directives */
|
|
29
|
+
scanDirectives: ScannedResolver[];
|
|
30
|
+
graphql: {
|
|
31
|
+
/** Immutable scan state — the single source of truth for all scanned files */state: GraphQLScanState; /** Absolute path to GraphQL build directory (e.g. /project/.graphql) */
|
|
32
|
+
buildDir: string; /** Directories watched for file changes in dev mode */
|
|
33
|
+
watchDirs: string[]; /** Absolute path to client GraphQL directory (e.g. /project/graphql) */
|
|
34
|
+
clientDir: string; /** Absolute path to server GraphQL directory (e.g. /project/server/graphql) */
|
|
35
|
+
serverDir: string; /** Relative paths (from rootDir) — used for display and config resolution */
|
|
36
|
+
dir: {
|
|
37
|
+
build: string;
|
|
38
|
+
client: string;
|
|
39
|
+
server: string;
|
|
40
|
+
}; /** @deprecated Use nitro.graphql.state.directiveSchemas */
|
|
41
|
+
directiveSchemas: string | null; /** @deprecated Use nitro.graphql.state.extendConfigs */
|
|
42
|
+
extendConfigs: string[]; /** @deprecated Use nitro.graphql.state.extendSchemas */
|
|
43
|
+
extendSchemas: string[];
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
declare module 'nitro/types' {
|
|
48
|
+
interface NitroOptions {
|
|
49
|
+
graphql?: NitroGraphQLOptions;
|
|
50
|
+
}
|
|
51
|
+
interface NitroRuntimeConfig {
|
|
52
|
+
graphql?: NitroGraphQLOptions;
|
|
53
|
+
}
|
|
54
|
+
interface NitroConfig {
|
|
55
|
+
graphql?: NitroGraphQLOptions;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
//#endregion
|
|
59
|
+
export { GraphQLScanState };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|