nitro-graphql 2.0.0-beta.72 → 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 +6 -29
- package/dist/cli/commands/generate.mjs +2 -2
- package/dist/cli/config.d.mts +4 -5
- package/dist/cli/config.mjs +3 -1
- package/dist/cli/index.d.mts +3 -6
- package/dist/cli/index.mjs +1 -1
- package/dist/cli/server/graphql-handler.mjs +2 -1
- package/dist/cli/server/watcher.mjs +1 -1
- package/dist/core/codegen/client.d.mts +4 -27
- package/dist/core/codegen/client.mjs +26 -445
- 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 -5
- package/dist/core/codegen/{runtime.d.mts → runtime-generator.d.mts} +1 -1
- package/dist/core/codegen/{runtime.mjs → runtime-generator.mjs} +1 -1
- package/dist/core/codegen/schema-loader.d.mts +2 -7
- package/dist/core/codegen/schema-loader.mjs +65 -70
- 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 -105
- package/dist/core/codegen/subscription-extractor.d.mts +20 -0
- package/dist/core/codegen/subscription-extractor.mjs +30 -0
- 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 -54
- 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 -2
- package/dist/core/debug/template.d.mts +1 -5
- package/dist/core/debug/template.mjs +1 -1
- package/dist/core/extend/loader.d.mts +0 -1
- package/dist/core/extend/loader.mjs +59 -89
- package/dist/core/index.d.mts +22 -17
- package/dist/core/index.mjs +19 -15
- package/dist/core/manifest.mjs +3 -1
- package/dist/core/pubsub/index.d.mts +2 -109
- package/dist/core/pubsub/index.mjs +1 -145
- 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 +4 -2
- package/dist/core/scanning/directives.mjs +2 -3
- package/dist/core/scanning/documents.d.mts +4 -3
- package/dist/core/scanning/documents.mjs +1 -1
- package/dist/core/scanning/{common.d.mts → file-scanner.d.mts} +1 -1
- package/dist/core/scanning/{common.mjs → file-scanner.mjs} +2 -10
- package/dist/core/scanning/index.d.mts +3 -3
- package/dist/core/scanning/index.mjs +3 -3
- package/dist/core/scanning/resolvers.mjs +8 -9
- package/dist/core/scanning/schemas.d.mts +1 -5
- package/dist/core/scanning/schemas.mjs +2 -24
- package/dist/core/schema/builder.d.mts +4 -2
- package/dist/core/schema/builder.mjs +4 -2
- package/dist/core/schema/index.d.mts +2 -2
- package/dist/core/schema/index.mjs +2 -2
- 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 -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 -13
- package/dist/core/types/adapter.d.mts +4 -39
- package/dist/core/types/codegen.d.mts +22 -45
- package/dist/core/types/config.d.mts +33 -121
- package/dist/core/types/define.d.mts +8 -5
- package/dist/core/types/index.d.mts +5 -4
- package/dist/core/types/scanning.d.mts +4 -1
- package/dist/core/types/standard-schema.d.mts +64 -0
- package/dist/core/utils/directive-parser.d.mts +8 -63
- package/dist/core/utils/directive-parser.mjs +114 -166
- package/dist/core/utils/file-io.d.mts +1 -5
- package/dist/core/utils/file-io.mjs +1 -11
- package/dist/core/utils/index.d.mts +5 -4
- package/dist/core/utils/index.mjs +6 -5
- package/dist/core/utils/logger.d.mts +1 -10
- package/dist/core/utils/logger.mjs +1 -19
- package/dist/core/utils/ofetch-templates.mjs +3 -4
- package/dist/core/utils/runtime.d.mts +1 -30
- package/dist/core/utils/runtime.mjs +2 -44
- package/dist/core/utils/string.d.mts +10 -0
- package/dist/core/utils/string.mjs +12 -0
- 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 +1 -139
- package/dist/define.d.mts +4 -2
- package/dist/define.mjs +7 -6
- package/dist/index.d.mts +4 -3
- package/dist/index.mjs +1 -1
- package/dist/nitro/adapter.d.mts +6 -10
- package/dist/nitro/adapter.mjs +12 -42
- 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 +1 -1
- package/dist/nitro/paths.d.mts +3 -2
- package/dist/nitro/paths.mjs +13 -9
- package/dist/nitro/rollup.mjs +4 -3
- package/dist/nitro/routes/_ws-handler.d.mts +6 -0
- package/dist/nitro/routes/_ws-handler.mjs +49 -0
- package/dist/nitro/routes/apollo-server-ws.d.mts +1 -1
- package/dist/nitro/routes/apollo-server-ws.mjs +9 -44
- package/dist/nitro/routes/apollo-server.d.mts +1 -1
- package/dist/nitro/routes/apollo-server.mjs +16 -55
- package/dist/nitro/routes/debug.d.mts +1 -1
- package/dist/nitro/routes/debug.mjs +1 -0
- package/dist/nitro/routes/graphql-yoga-ws.d.mts +1 -1
- package/dist/nitro/routes/graphql-yoga-ws.mjs +6 -44
- package/dist/nitro/routes/graphql-yoga.mjs +7 -5
- package/dist/nitro/routes/health.mjs +22 -24
- package/dist/nitro/setup/extend-loader.d.mts +6 -5
- package/dist/nitro/setup/extend-loader.mjs +30 -58
- package/dist/nitro/setup/file-watcher.mjs +6 -4
- package/dist/nitro/setup/logging.d.mts +1 -8
- package/dist/nitro/setup/logging.mjs +7 -22
- package/dist/nitro/setup/rollup-integration.mjs +32 -1
- package/dist/nitro/setup/scanner.d.mts +8 -43
- package/dist/nitro/setup/scanner.mjs +56 -58
- package/dist/nitro/setup/security.d.mts +10 -0
- package/dist/nitro/setup/security.mjs +17 -0
- 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 +87 -74
- 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 +0 -5
- 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/native/index.js +52 -52
- package/package.json +15 -15
- package/dist/cli/commands/index.d.mts +0 -5
- package/dist/cli/commands/index.mjs +0 -5
- package/dist/core/codegen/plugin.d.mts +0 -19
- package/dist/core/codegen/plugin.mjs +0 -29
- package/dist/core/config.d.mts +0 -45
- package/dist/core/config.mjs +0 -76
- package/dist/nitro/codegen.d.mts +0 -18
- package/dist/nitro/codegen.mjs +0 -171
- package/dist/nitro/config.d.mts +0 -50
- package/dist/nitro/config.mjs +0 -55
- package/dist/nitro/types.d.mts +0 -549
- package/dist/nitro/virtual/generators.d.mts +0 -38
- package/dist/nitro/virtual/generators.mjs +0 -190
- /package/dist/{nitro/types.mjs → core/types/standard-schema.mjs} +0 -0
|
@@ -1,59 +1,24 @@
|
|
|
1
|
-
import { ExtendSource } from "../types.mjs";
|
|
1
|
+
import { ExtendSource } from "../types/config.mjs";
|
|
2
2
|
import { Nitro } from "nitro/types";
|
|
3
3
|
|
|
4
4
|
//#region src/nitro/setup/scanner.d.ts
|
|
5
5
|
interface ScanOptions {
|
|
6
|
-
/** Silent mode - suppress logging */
|
|
7
6
|
silent?: boolean;
|
|
8
|
-
/** Is this a rescan (dev mode hot reload) */
|
|
9
7
|
isRescan?: boolean;
|
|
10
8
|
}
|
|
11
|
-
interface ScanResult {
|
|
12
|
-
schemas: number;
|
|
13
|
-
resolvers: number;
|
|
14
|
-
directives: number;
|
|
15
|
-
documents: number;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Check if local file scanning should be performed
|
|
19
|
-
* Centralized helper to avoid scattered skipLocalScan checks
|
|
20
|
-
*/
|
|
21
9
|
declare function shouldScanLocalFiles(nitro: Nitro): boolean;
|
|
22
|
-
/**
|
|
23
|
-
* Check if server-side GraphQL is enabled
|
|
24
|
-
*/
|
|
25
10
|
declare function isServerEnabled(nitro: Nitro): boolean;
|
|
26
|
-
/**
|
|
27
|
-
* Get extend sources from config
|
|
28
|
-
*/
|
|
29
11
|
declare function getExtendSources(nitro: Nitro): ExtendSource[] | undefined;
|
|
30
12
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*/
|
|
34
|
-
declare function scanLocalFiles(nitro: Nitro): Promise<ScanResult>;
|
|
35
|
-
/**
|
|
36
|
-
* Scan only client documents (for external services or client-only mode)
|
|
37
|
-
*/
|
|
38
|
-
declare function scanDocumentsOnly(nitro: Nitro): Promise<number>;
|
|
39
|
-
/**
|
|
40
|
-
* Initialize empty scan results (for skipLocalScan mode)
|
|
41
|
-
*/
|
|
42
|
-
declare function initializeEmptyScanResults(nitro: Nitro): void;
|
|
43
|
-
/**
|
|
44
|
-
* Perform complete GraphQL scan workflow
|
|
45
|
-
* This is the main entry point for both initial setup and dev mode rescan
|
|
13
|
+
* Perform complete GraphQL scan workflow.
|
|
14
|
+
* Builds an immutable state snapshot and assigns it to nitro.graphql.state atomically.
|
|
46
15
|
*
|
|
47
|
-
*
|
|
48
|
-
* 1.
|
|
49
|
-
* 2.
|
|
50
|
-
* 3.
|
|
51
|
-
* 4. Log diagnostics if needed
|
|
16
|
+
* Flow:
|
|
17
|
+
* 1. Scan local files (or skip if skipLocalScan)
|
|
18
|
+
* 2. Merge extend sources into state
|
|
19
|
+
* 3. Assign frozen state to nitro.graphql.state (single atomic write)
|
|
52
20
|
*/
|
|
53
21
|
declare function performGraphQLScan(nitro: Nitro, options?: ScanOptions): Promise<void>;
|
|
54
|
-
/**
|
|
55
|
-
* Log resolver diagnostics for development
|
|
56
|
-
*/
|
|
57
22
|
declare function logResolverDiagnostics(nitro: Nitro): void;
|
|
58
23
|
//#endregion
|
|
59
|
-
export { ScanOptions,
|
|
24
|
+
export { ScanOptions, getExtendSources, isServerEnabled, logResolverDiagnostics, performGraphQLScan, shouldScanLocalFiles };
|
|
@@ -1,98 +1,96 @@
|
|
|
1
1
|
import { LOG_TAG } from "../../core/constants.mjs";
|
|
2
|
+
import { scanDirectivesCore } from "../../core/scanning/directives.mjs";
|
|
3
|
+
import { scanDocumentsCore } from "../../core/scanning/documents.mjs";
|
|
4
|
+
import { scanResolversCore } from "../../core/scanning/resolvers.mjs";
|
|
5
|
+
import { scanSchemasCore } from "../../core/scanning/schemas.mjs";
|
|
2
6
|
import { generateDirectiveSchemas } from "../../core/utils/directive-parser.mjs";
|
|
3
|
-
import {
|
|
7
|
+
import { createScanContextFromNitro } from "../adapter.mjs";
|
|
8
|
+
import { createScanState } from "../state.mjs";
|
|
4
9
|
import { resolveExtendConfig } from "./extend-loader.mjs";
|
|
5
10
|
import consola from "consola";
|
|
11
|
+
import { relative } from "pathe";
|
|
6
12
|
//#region src/nitro/setup/scanner.ts
|
|
7
13
|
const logger = consola.withTag(LOG_TAG);
|
|
8
|
-
/**
|
|
9
|
-
* Check if local file scanning should be performed
|
|
10
|
-
* Centralized helper to avoid scattered skipLocalScan checks
|
|
11
|
-
*/
|
|
12
14
|
function shouldScanLocalFiles(nitro) {
|
|
13
15
|
return nitro.options.graphql?.skipLocalScan !== true;
|
|
14
16
|
}
|
|
15
|
-
/**
|
|
16
|
-
* Check if server-side GraphQL is enabled
|
|
17
|
-
*/
|
|
18
17
|
function isServerEnabled(nitro) {
|
|
19
18
|
return nitro.options.graphql?.server !== false;
|
|
20
19
|
}
|
|
21
|
-
/**
|
|
22
|
-
* Get extend sources from config
|
|
23
|
-
*/
|
|
24
20
|
function getExtendSources(nitro) {
|
|
25
21
|
const extend = nitro.options.graphql?.extend;
|
|
26
22
|
return Array.isArray(extend) ? extend : void 0;
|
|
27
23
|
}
|
|
28
24
|
/**
|
|
29
|
-
* Scan local GraphQL files
|
|
30
|
-
*
|
|
25
|
+
* Scan local GraphQL files and return an immutable state snapshot.
|
|
26
|
+
* Does NOT mutate nitro — caller is responsible for assigning the state.
|
|
31
27
|
*/
|
|
32
28
|
async function scanLocalFiles(nitro) {
|
|
33
|
-
const
|
|
34
|
-
|
|
29
|
+
const ctx = createScanContextFromNitro(nitro);
|
|
30
|
+
const directivesResult = await scanDirectivesCore(ctx);
|
|
35
31
|
const directiveSchemas = await generateDirectiveSchemas(directivesResult.items, nitro.graphql.buildDir);
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
};
|
|
32
|
+
const schemasResult = await scanSchemasCore(ctx);
|
|
33
|
+
const [docsResult, resolversResult] = await Promise.all([scanDocumentsCore(ctx, {
|
|
34
|
+
externalServices: nitro.options.graphql?.externalServices,
|
|
35
|
+
clientDirRelative: relative(nitro.options.rootDir, nitro.graphql.clientDir)
|
|
36
|
+
}), scanResolversCore(ctx)]);
|
|
37
|
+
return createScanState({
|
|
38
|
+
schemas: schemasResult.items,
|
|
39
|
+
resolvers: resolversResult.items,
|
|
40
|
+
directives: directivesResult.items,
|
|
41
|
+
documents: docsResult.items,
|
|
42
|
+
directiveSchemas
|
|
43
|
+
});
|
|
49
44
|
}
|
|
50
45
|
/**
|
|
51
|
-
* Scan only client documents
|
|
46
|
+
* Scan only client documents, preserving existing state for other fields
|
|
52
47
|
*/
|
|
53
48
|
async function scanDocumentsOnly(nitro) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
49
|
+
return createScanState({
|
|
50
|
+
schemas: [],
|
|
51
|
+
resolvers: [],
|
|
52
|
+
directives: [],
|
|
53
|
+
documents: (await scanDocumentsCore(createScanContextFromNitro(nitro), {
|
|
54
|
+
externalServices: nitro.options.graphql?.externalServices,
|
|
55
|
+
clientDirRelative: relative(nitro.options.rootDir, nitro.graphql.clientDir)
|
|
56
|
+
})).items,
|
|
57
|
+
directiveSchemas: null
|
|
58
|
+
});
|
|
57
59
|
}
|
|
58
60
|
/**
|
|
59
|
-
*
|
|
60
|
-
|
|
61
|
-
function initializeEmptyScanResults(nitro) {
|
|
62
|
-
nitro.scanSchemas = [];
|
|
63
|
-
nitro.scanResolvers = [];
|
|
64
|
-
nitro.scanDirectives = [];
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Perform complete GraphQL scan workflow
|
|
68
|
-
* This is the main entry point for both initial setup and dev mode rescan
|
|
61
|
+
* Perform complete GraphQL scan workflow.
|
|
62
|
+
* Builds an immutable state snapshot and assigns it to nitro.graphql.state atomically.
|
|
69
63
|
*
|
|
70
|
-
*
|
|
71
|
-
* 1.
|
|
72
|
-
* 2.
|
|
73
|
-
* 3.
|
|
74
|
-
* 4. Log diagnostics if needed
|
|
64
|
+
* Flow:
|
|
65
|
+
* 1. Scan local files (or skip if skipLocalScan)
|
|
66
|
+
* 2. Merge extend sources into state
|
|
67
|
+
* 3. Assign frozen state to nitro.graphql.state (single atomic write)
|
|
75
68
|
*/
|
|
76
69
|
async function performGraphQLScan(nitro, options = {}) {
|
|
77
70
|
const { silent = false, isRescan = false } = options;
|
|
78
71
|
const serverEnabled = isServerEnabled(nitro);
|
|
79
72
|
const scanLocal = shouldScanLocalFiles(nitro);
|
|
80
73
|
const extendSources = getExtendSources(nitro);
|
|
81
|
-
if (isRescan &&
|
|
74
|
+
if (isRescan && extendSources?.length) return;
|
|
75
|
+
let state;
|
|
82
76
|
if (!scanLocal) {
|
|
83
77
|
if (!isRescan && !silent) if (extendSources?.length) logger.info(`Using ${extendSources.length} extend source(s), skipping local scanning`);
|
|
84
78
|
else logger.info("Skipping local scanning (skipLocalScan: true)");
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
79
|
+
state = await scanDocumentsOnly(nitro);
|
|
80
|
+
} else if (serverEnabled) state = await scanLocalFiles(nitro);
|
|
81
|
+
else state = await scanDocumentsOnly(nitro);
|
|
82
|
+
state = await resolveExtendConfig(nitro, state, { silent: silent || isRescan });
|
|
83
|
+
nitro.graphql.state = state;
|
|
84
|
+
nitro.scanSchemas = [...state.schemas];
|
|
85
|
+
nitro.scanResolvers = [...state.resolvers];
|
|
86
|
+
nitro.scanDirectives = [...state.directives];
|
|
87
|
+
nitro.scanDocuments = [...state.documents];
|
|
88
|
+
nitro.graphql.directiveSchemas = state.directiveSchemas;
|
|
89
|
+
nitro.graphql.extendConfigs = [...state.extendConfigs];
|
|
90
|
+
nitro.graphql.extendSchemas = [...state.extendSchemas];
|
|
90
91
|
}
|
|
91
|
-
/**
|
|
92
|
-
* Log resolver diagnostics for development
|
|
93
|
-
*/
|
|
94
92
|
function logResolverDiagnostics(nitro) {
|
|
95
|
-
const resolvers = nitro.
|
|
93
|
+
const resolvers = nitro.graphql.state.resolvers;
|
|
96
94
|
if (resolvers.length > 0) {
|
|
97
95
|
const totalExports = resolvers.reduce((sum, r) => sum + r.imports.length, 0);
|
|
98
96
|
const typeCount = {
|
|
@@ -115,4 +113,4 @@ function logResolverDiagnostics(nitro) {
|
|
|
115
113
|
} else logger.warn("No resolvers found. Check /_nitro/graphql/debug for details.");
|
|
116
114
|
}
|
|
117
115
|
//#endregion
|
|
118
|
-
export { getExtendSources,
|
|
116
|
+
export { getExtendSources, isServerEnabled, logResolverDiagnostics, performGraphQLScan, shouldScanLocalFiles };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CoreSecurityConfig } from "../../core/types/config.mjs";
|
|
2
|
+
//#region src/nitro/setup/security.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Resolves security configuration with environment-aware defaults
|
|
5
|
+
* In production: introspection off, playground off, errors masked, suggestions disabled
|
|
6
|
+
* In development: introspection on, playground on, errors shown, suggestions enabled
|
|
7
|
+
*/
|
|
8
|
+
declare function resolveSecurityConfig(config?: CoreSecurityConfig): Required<CoreSecurityConfig>;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { resolveSecurityConfig };
|
|
@@ -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 };
|
|
@@ -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,13 +1,15 @@
|
|
|
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_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";
|
|
@@ -18,40 +20,37 @@ import { relative, resolve } from "pathe";
|
|
|
18
20
|
const logger = consola.withTag(LOG_TAG);
|
|
19
21
|
/**
|
|
20
22
|
* Main setup function for nitro-graphql
|
|
21
|
-
*
|
|
23
|
+
* Executes setup resolvers in sequence
|
|
22
24
|
*/
|
|
23
25
|
async function setupNitroGraphQL(nitro) {
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (serverEnabled) registerRouteHandlers(nitro);
|
|
42
|
-
setupTypeScriptConfiguration(nitro);
|
|
43
|
-
setupNuxtIntegration(nitro);
|
|
44
|
-
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);
|
|
45
43
|
}
|
|
46
44
|
/**
|
|
47
|
-
*
|
|
45
|
+
* Resolve default configuration values and initialize Nitro GraphQL state
|
|
48
46
|
*/
|
|
49
|
-
function
|
|
47
|
+
function resolveConfiguration(nitro) {
|
|
50
48
|
nitro.options.graphql ||= {};
|
|
51
49
|
nitro.options.graphql.types = defu(nitro.options.graphql.types, DEFAULT_TYPES_CONFIG);
|
|
52
|
-
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\".");
|
|
53
51
|
const defaultPaths = getDefaultPaths(nitro);
|
|
54
52
|
nitro.graphql ||= {
|
|
53
|
+
state: emptyScanState(),
|
|
55
54
|
buildDir: "",
|
|
56
55
|
watchDirs: [],
|
|
57
56
|
clientDir: defaultPaths.clientDir,
|
|
@@ -75,9 +74,9 @@ function initializeConfiguration(nitro, serverEnabled) {
|
|
|
75
74
|
};
|
|
76
75
|
}
|
|
77
76
|
/**
|
|
78
|
-
* Validate external services configuration
|
|
77
|
+
* Validate external services and federation configuration
|
|
79
78
|
*/
|
|
80
|
-
function
|
|
79
|
+
function resolveValidation(nitro) {
|
|
81
80
|
if (nitro.options.graphql?.externalServices?.length) {
|
|
82
81
|
const validationErrors = validateExternalServices(nitro.options.graphql.externalServices);
|
|
83
82
|
if (validationErrors.length > 0) {
|
|
@@ -90,27 +89,26 @@ function validateConfiguration(nitro) {
|
|
|
90
89
|
if (nitro.options.graphql?.federation?.enabled) logger.info(`Apollo Federation enabled for service: ${nitro.options.graphql.federation.serviceName || "unnamed"}`);
|
|
91
90
|
}
|
|
92
91
|
/**
|
|
93
|
-
*
|
|
92
|
+
* Resolve build directories and relative paths
|
|
94
93
|
*/
|
|
95
|
-
function
|
|
96
|
-
|
|
97
|
-
nitro.graphql.
|
|
98
|
-
|
|
99
|
-
case FRAMEWORK_NUXT:
|
|
100
|
-
nitro.graphql.dir.client = relative(nitro.options.rootDir, nitro.graphql.clientDir);
|
|
101
|
-
nitro.graphql.dir.server = relative(nitro.options.rootDir, nitro.graphql.serverDir);
|
|
102
|
-
break;
|
|
103
|
-
case FRAMEWORK_NITRO:
|
|
104
|
-
nitro.graphql.dir.client = relative(nitro.options.rootDir, nitro.graphql.clientDir);
|
|
105
|
-
nitro.graphql.dir.server = relative(nitro.options.rootDir, nitro.graphql.serverDir);
|
|
106
|
-
break;
|
|
107
|
-
default: break;
|
|
108
|
-
}
|
|
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);
|
|
109
98
|
}
|
|
110
99
|
/**
|
|
111
|
-
*
|
|
100
|
+
* Resolve Rollup/Rolldown integration (externals, chunking, noExternals)
|
|
112
101
|
*/
|
|
113
|
-
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) {
|
|
114
112
|
const securityConfig = resolveSecurityConfig(nitro.options.graphql?.security);
|
|
115
113
|
nitro.options.runtimeConfig.graphql = defu(nitro.options.runtimeConfig.graphql || {}, {
|
|
116
114
|
...DEFAULT_RUNTIME_CONFIG,
|
|
@@ -118,20 +116,28 @@ function initializeRuntimeConfig(nitro) {
|
|
|
118
116
|
});
|
|
119
117
|
}
|
|
120
118
|
/**
|
|
121
|
-
*
|
|
119
|
+
* Resolve file watching for development mode
|
|
122
120
|
*/
|
|
123
|
-
function
|
|
121
|
+
async function resolveFileWatching(nitro) {
|
|
122
|
+
if (!nitro.options.dev) return;
|
|
123
|
+
const serverEnabled = isServerEnabled(nitro);
|
|
124
|
+
const extendDirs = await resolveExtendDirs(nitro);
|
|
124
125
|
const watchDirs = serverEnabled ? getWatchDirectories(nitro, extendDirs) : [nitro.graphql.clientDir].filter(Boolean);
|
|
125
126
|
nitro.graphql.watchDirs = watchDirs;
|
|
126
127
|
const watcher = setupFileWatcher(nitro, watchDirs);
|
|
127
|
-
nitro.hooks.hook("close", () =>
|
|
128
|
-
watcher.close();
|
|
129
|
-
});
|
|
128
|
+
nitro.hooks.hook("close", () => watcher.close());
|
|
130
129
|
}
|
|
131
130
|
/**
|
|
132
|
-
*
|
|
131
|
+
* Resolve initial GraphQL file scanning
|
|
133
132
|
*/
|
|
134
|
-
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;
|
|
135
141
|
let hasShownInitialLogs = false;
|
|
136
142
|
let lastDevStart = 0;
|
|
137
143
|
const DEBOUNCE_MS = 500;
|
|
@@ -150,40 +156,47 @@ function setupDevHooks(nitro) {
|
|
|
150
156
|
});
|
|
151
157
|
}
|
|
152
158
|
/**
|
|
153
|
-
*
|
|
159
|
+
* Resolve virtual modules registration via Rollup config
|
|
154
160
|
*/
|
|
155
|
-
async function
|
|
156
|
-
if (
|
|
157
|
-
|
|
158
|
-
await generateClientTypes(nitro, { isInitial: true });
|
|
159
|
-
} else await generateClientTypes(nitro, { isInitial: true });
|
|
161
|
+
async function resolveVirtualModules(nitro) {
|
|
162
|
+
if (!isServerEnabled(nitro)) return;
|
|
163
|
+
await rollupConfig(nitro);
|
|
160
164
|
}
|
|
161
165
|
/**
|
|
162
|
-
*
|
|
166
|
+
* Resolve initial type generation
|
|
163
167
|
*/
|
|
164
|
-
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) {
|
|
165
175
|
nitro.hooks.hook("close", async () => {
|
|
166
|
-
|
|
167
|
-
await generateClientTypes(nitro, { silent: true });
|
|
176
|
+
await regenerateTypes(nitro, { silent: true });
|
|
168
177
|
});
|
|
169
178
|
}
|
|
170
179
|
/**
|
|
171
|
-
*
|
|
180
|
+
* Resolve route handler registration
|
|
172
181
|
*/
|
|
173
|
-
function
|
|
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) {
|
|
174
190
|
nitro.options.typescript.strict = true;
|
|
175
191
|
nitro.hooks.hook("types:extend", (types) => {
|
|
176
192
|
setupTypeScriptPaths(nitro, types);
|
|
177
193
|
});
|
|
178
194
|
}
|
|
179
195
|
/**
|
|
180
|
-
*
|
|
196
|
+
* Resolve startup logging
|
|
181
197
|
*/
|
|
182
|
-
function
|
|
183
|
-
|
|
184
|
-
const nuxtOptions = nitro._nuxt?.options;
|
|
185
|
-
if (nuxtOptions) nuxtOptions.nitroGraphqlExternalServices = nitro.options.graphql?.externalServices || [];
|
|
186
|
-
});
|
|
198
|
+
function resolveStartupLogging(nitro) {
|
|
199
|
+
logStartupInfo(nitro, isServerEnabled(nitro));
|
|
187
200
|
}
|
|
188
201
|
//#endregion
|
|
189
|
-
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 };
|