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,29 +0,0 @@
|
|
|
1
|
-
//#region src/core/codegen/plugin.ts
|
|
2
|
-
/**
|
|
3
|
-
* Plugin to add prepend comments to generated files
|
|
4
|
-
* Used by both server and client codegen
|
|
5
|
-
*/
|
|
6
|
-
function pluginContent(_schema, _documents, _config, _info) {
|
|
7
|
-
return {
|
|
8
|
-
prepend: [
|
|
9
|
-
"// THIS FILE IS GENERATED, DO NOT EDIT!",
|
|
10
|
-
"/* eslint-disable eslint-comments/no-unlimited-disable */",
|
|
11
|
-
"/* tslint:disable */",
|
|
12
|
-
"/* eslint-disable */",
|
|
13
|
-
"/* prettier-ignore */"
|
|
14
|
-
],
|
|
15
|
-
content: ""
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Generate the prepend header for generated files
|
|
20
|
-
* Can be used when creating files manually without codegen
|
|
21
|
-
*/
|
|
22
|
-
const GENERATED_FILE_HEADER = `// THIS FILE IS GENERATED, DO NOT EDIT!
|
|
23
|
-
/* eslint-disable eslint-comments/no-unlimited-disable */
|
|
24
|
-
/* tslint:disable */
|
|
25
|
-
/* eslint-disable */
|
|
26
|
-
/* prettier-ignore */
|
|
27
|
-
`;
|
|
28
|
-
//#endregion
|
|
29
|
-
export { GENERATED_FILE_HEADER, pluginContent };
|
package/dist/core/config.d.mts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { CoreConfig, CoreContext, CoreGraphQLOptions, CoreLogger } from "./types/config.mjs";
|
|
2
|
-
import { ScanContext } from "./types/scanning.mjs";
|
|
3
|
-
|
|
4
|
-
//#region src/core/config.d.ts
|
|
5
|
-
/**
|
|
6
|
-
* Options for creating a CoreConfig
|
|
7
|
-
*/
|
|
8
|
-
interface CreateCoreConfigOptions {
|
|
9
|
-
/** Root directory of the project */
|
|
10
|
-
rootDir: string;
|
|
11
|
-
/** Build directory (optional, defaults based on framework) */
|
|
12
|
-
buildDir?: string;
|
|
13
|
-
/** Server GraphQL directory (optional) */
|
|
14
|
-
serverDir?: string;
|
|
15
|
-
/** Client GraphQL directory (optional) */
|
|
16
|
-
clientDir?: string;
|
|
17
|
-
/** Whether running in Nuxt context */
|
|
18
|
-
isNuxt?: boolean;
|
|
19
|
-
/** Whether running in development mode */
|
|
20
|
-
isDev?: boolean;
|
|
21
|
-
/** GraphQL options */
|
|
22
|
-
graphqlOptions?: CoreGraphQLOptions;
|
|
23
|
-
/** Custom logger */
|
|
24
|
-
logger?: CoreLogger;
|
|
25
|
-
/** Patterns to ignore */
|
|
26
|
-
ignorePatterns?: string[];
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Create a CoreConfig with sensible defaults
|
|
30
|
-
*/
|
|
31
|
-
declare function createCoreConfig(options: CreateCoreConfigOptions): CoreConfig;
|
|
32
|
-
/**
|
|
33
|
-
* Create a CoreContext from CoreConfig
|
|
34
|
-
*/
|
|
35
|
-
declare function createCoreContext(config: CoreConfig): CoreContext;
|
|
36
|
-
/**
|
|
37
|
-
* Create a ScanContext from CoreConfig
|
|
38
|
-
*/
|
|
39
|
-
declare function createScanContext(config: CoreConfig): ScanContext;
|
|
40
|
-
/**
|
|
41
|
-
* Merge GraphQL options with defaults
|
|
42
|
-
*/
|
|
43
|
-
declare function mergeGraphQLOptions(options: Partial<CoreGraphQLOptions>, defaults?: Partial<CoreGraphQLOptions>): CoreGraphQLOptions;
|
|
44
|
-
//#endregion
|
|
45
|
-
export { CreateCoreConfigOptions, createCoreConfig, createCoreContext, createScanContext, mergeGraphQLOptions };
|
package/dist/core/config.mjs
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import "./constants.mjs";
|
|
2
|
-
import { createLogger } from "./utils/logger.mjs";
|
|
3
|
-
import { relative, resolve } from "pathe";
|
|
4
|
-
//#region src/core/config.ts
|
|
5
|
-
/**
|
|
6
|
-
* Create a CoreConfig with sensible defaults
|
|
7
|
-
*/
|
|
8
|
-
function createCoreConfig(options) {
|
|
9
|
-
const { rootDir, isNuxt = false, isDev = process.env.NODE_ENV !== "production", graphqlOptions = {}, logger = createLogger(), ignorePatterns = [] } = options;
|
|
10
|
-
const framework = graphqlOptions.framework || "graphql-yoga";
|
|
11
|
-
const buildDir = options.buildDir || resolve(rootDir, isNuxt ? ".nuxt" : ".nitro");
|
|
12
|
-
return {
|
|
13
|
-
rootDir,
|
|
14
|
-
buildDir,
|
|
15
|
-
serverDir: options.serverDir || resolve(rootDir, "server/graphql"),
|
|
16
|
-
clientDir: options.clientDir || resolve(rootDir, isNuxt ? "app/graphql" : "graphql"),
|
|
17
|
-
typesDir: resolve(buildDir, "types"),
|
|
18
|
-
framework,
|
|
19
|
-
isNuxt,
|
|
20
|
-
isDev,
|
|
21
|
-
graphqlOptions,
|
|
22
|
-
logger,
|
|
23
|
-
ignorePatterns
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Create a CoreContext from CoreConfig
|
|
28
|
-
*/
|
|
29
|
-
function createCoreContext(config) {
|
|
30
|
-
return {
|
|
31
|
-
config,
|
|
32
|
-
graphqlBuildDir: resolve(config.buildDir, "graphql"),
|
|
33
|
-
watchDirs: [],
|
|
34
|
-
dir: {
|
|
35
|
-
build: relative(config.rootDir, config.buildDir),
|
|
36
|
-
client: relative(config.rootDir, config.clientDir),
|
|
37
|
-
server: relative(config.rootDir, config.serverDir)
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Create a ScanContext from CoreConfig
|
|
43
|
-
*/
|
|
44
|
-
function createScanContext(config) {
|
|
45
|
-
return {
|
|
46
|
-
rootDir: config.rootDir,
|
|
47
|
-
serverDir: config.serverDir,
|
|
48
|
-
clientDir: config.clientDir,
|
|
49
|
-
ignorePatterns: config.ignorePatterns,
|
|
50
|
-
isDev: config.isDev,
|
|
51
|
-
logger: config.logger
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Merge GraphQL options with defaults
|
|
56
|
-
*/
|
|
57
|
-
function mergeGraphQLOptions(options, defaults = {}) {
|
|
58
|
-
return {
|
|
59
|
-
...defaults,
|
|
60
|
-
...options,
|
|
61
|
-
codegen: {
|
|
62
|
-
...defaults.codegen,
|
|
63
|
-
...options.codegen
|
|
64
|
-
},
|
|
65
|
-
security: {
|
|
66
|
-
...defaults.security,
|
|
67
|
-
...options.security
|
|
68
|
-
},
|
|
69
|
-
paths: {
|
|
70
|
-
...defaults.paths,
|
|
71
|
-
...options.paths
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
//#endregion
|
|
76
|
-
export { createCoreConfig, createCoreContext, createScanContext, mergeGraphQLOptions };
|
package/dist/nitro/codegen.d.mts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Nitro } from "nitro/types";
|
|
2
|
-
|
|
3
|
-
//#region src/nitro/codegen.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* Generate server-side resolver types
|
|
6
|
-
*/
|
|
7
|
-
declare function generateServerTypes(nitro: Nitro, options?: {
|
|
8
|
-
silent?: boolean;
|
|
9
|
-
}): Promise<void>;
|
|
10
|
-
/**
|
|
11
|
-
* Generate client-side operation types
|
|
12
|
-
*/
|
|
13
|
-
declare function generateClientTypes(nitro: Nitro, options?: {
|
|
14
|
-
silent?: boolean;
|
|
15
|
-
isInitial?: boolean;
|
|
16
|
-
}): Promise<void>;
|
|
17
|
-
//#endregion
|
|
18
|
-
export { generateClientTypes, generateServerTypes };
|
package/dist/nitro/codegen.mjs
DELETED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import { LOG_TAG } from "../core/constants.mjs";
|
|
2
|
-
import { loadGraphQLDocuments } from "../core/codegen/document-loader.mjs";
|
|
3
|
-
import { writeFile } from "../core/utils/file-io.mjs";
|
|
4
|
-
import { downloadAndSaveSchema, loadExternalSchema } from "../core/codegen/schema-loader.mjs";
|
|
5
|
-
import { generateClientTypesCore, generateExternalClientTypesCore, generateSubscriptionBuilder } from "../core/codegen/client.mjs";
|
|
6
|
-
import { generateServerTypesCore } from "../core/codegen/server.mjs";
|
|
7
|
-
import { validateNoDuplicateTypes } from "../core/codegen/validation.mjs";
|
|
8
|
-
import { loadFederationSupport } from "../core/schema/federation.mjs";
|
|
9
|
-
import { subscribeClientTemplate } from "../core/utils/subscribe-templates.mjs";
|
|
10
|
-
import { getDefaultPaths, getSdkConfig, getTypesConfig, resolveFilePath, shouldGenerateTypes } from "./paths.mjs";
|
|
11
|
-
import consola from "consola";
|
|
12
|
-
import { join, resolve } from "pathe";
|
|
13
|
-
import { printSchemaWithDirectives } from "@graphql-tools/utils";
|
|
14
|
-
import { parse, print } from "graphql";
|
|
15
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
16
|
-
import { mergeTypeDefs } from "@graphql-tools/merge";
|
|
17
|
-
import { makeExecutableSchema } from "@graphql-tools/schema";
|
|
18
|
-
import { loadFilesSync } from "@graphql-tools/load-files";
|
|
19
|
-
//#region src/nitro/codegen.ts
|
|
20
|
-
const logger = consola.withTag(LOG_TAG);
|
|
21
|
-
async function buildSchemaFromString(source, federation) {
|
|
22
|
-
if (federation) {
|
|
23
|
-
const buildSubgraph = await loadFederationSupport();
|
|
24
|
-
if (!buildSubgraph) throw new Error("Federation enabled but @apollo/subgraph not installed");
|
|
25
|
-
return buildSubgraph([{ typeDefs: parse(source) }]);
|
|
26
|
-
}
|
|
27
|
-
return makeExecutableSchema({ typeDefs: source });
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Generate server-side resolver types
|
|
31
|
-
*/
|
|
32
|
-
async function generateServerTypes(nitro, options = {}) {
|
|
33
|
-
if (!shouldGenerateTypes(nitro)) return;
|
|
34
|
-
const schemas = nitro.scanSchemas || [];
|
|
35
|
-
if (!schemas.length) {
|
|
36
|
-
if (!options.silent) consola.info("No GraphQL schemas found");
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
try {
|
|
40
|
-
const allStrings = loadFilesSync(schemas).map((s) => typeof s === "string" ? s : s.loc?.source?.body || "");
|
|
41
|
-
const validSchemas = [];
|
|
42
|
-
const strings = [];
|
|
43
|
-
schemas.forEach((schema, i) => {
|
|
44
|
-
if (allStrings[i]) {
|
|
45
|
-
validSchemas.push(schema);
|
|
46
|
-
strings.push(allStrings[i]);
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
const directiveSchemas = nitro.graphql.directiveSchemas;
|
|
50
|
-
if (directiveSchemas) {
|
|
51
|
-
validSchemas.push("<directives>");
|
|
52
|
-
strings.push(directiveSchemas);
|
|
53
|
-
}
|
|
54
|
-
if (!validateNoDuplicateTypes(validSchemas, strings)) return;
|
|
55
|
-
const mergedSchemaString = print(mergeTypeDefs([strings.join("\n\n")], {
|
|
56
|
-
throwOnConflict: true,
|
|
57
|
-
sort: true
|
|
58
|
-
}));
|
|
59
|
-
const federation = nitro.options.graphql?.federation?.enabled === true;
|
|
60
|
-
const sortedSchemaString = printSchemaWithDirectives(await buildSchemaFromString(mergedSchemaString, federation));
|
|
61
|
-
const result = await generateServerTypesCore({
|
|
62
|
-
framework: nitro.options.graphql?.framework || "graphql-yoga",
|
|
63
|
-
schemaString: sortedSchemaString,
|
|
64
|
-
config: nitro.options.graphql?.codegen?.server,
|
|
65
|
-
federationEnabled: federation
|
|
66
|
-
});
|
|
67
|
-
writeFile(resolve(nitro.graphql.buildDir, "schema.graphql"), sortedSchemaString);
|
|
68
|
-
const placeholders = getDefaultPaths(nitro);
|
|
69
|
-
const typesConfig = getTypesConfig(nitro);
|
|
70
|
-
const typesPath = resolveFilePath(typesConfig.server, typesConfig.enabled, true, "{typesDir}/nitro-graphql-server.d.ts", placeholders);
|
|
71
|
-
if (typesPath) {
|
|
72
|
-
writeFile(typesPath, result.types);
|
|
73
|
-
if (!options.silent) logger.success(`Server types: ${typesPath}`);
|
|
74
|
-
}
|
|
75
|
-
} catch (error) {
|
|
76
|
-
logger.error("Server type generation failed:", error);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Generate client-side operation types
|
|
81
|
-
*/
|
|
82
|
-
async function generateClientTypes(nitro, options = {}) {
|
|
83
|
-
try {
|
|
84
|
-
if (nitro.scanSchemas?.length) await generateMainClientTypes(nitro, options);
|
|
85
|
-
if (nitro.options.graphql?.externalServices?.length) await generateExternalTypes(nitro, options);
|
|
86
|
-
} catch (error) {
|
|
87
|
-
logger.error("Client type generation failed:", error);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
async function generateMainClientTypes(nitro, options = {}) {
|
|
91
|
-
const schemaPath = join(nitro.graphql.buildDir, "schema.graphql");
|
|
92
|
-
if (!existsSync(schemaPath)) {
|
|
93
|
-
if (!options.silent) consola.info("Schema not ready for client types");
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
const docs = await loadGraphQLDocuments(nitro.scanDocuments);
|
|
97
|
-
const schemaString = readFileSync(schemaPath, "utf-8");
|
|
98
|
-
const serverScalars = nitro.options.graphql?.codegen?.server?.scalars;
|
|
99
|
-
const clientConfig = nitro.options.graphql?.codegen?.client || {};
|
|
100
|
-
const types = await generateClientTypesCore({
|
|
101
|
-
schemaString,
|
|
102
|
-
documents: docs,
|
|
103
|
-
config: {
|
|
104
|
-
...clientConfig,
|
|
105
|
-
scalars: clientConfig.scalars ?? serverScalars
|
|
106
|
-
},
|
|
107
|
-
sdkConfig: nitro.options.graphql?.codegen?.clientSDK,
|
|
108
|
-
options
|
|
109
|
-
});
|
|
110
|
-
if (types === false) return;
|
|
111
|
-
const placeholders = getDefaultPaths(nitro);
|
|
112
|
-
const typesConfig = getTypesConfig(nitro);
|
|
113
|
-
const sdkConfig = getSdkConfig(nitro);
|
|
114
|
-
const subscriptionsEnabled = nitro.options.graphql?.subscriptions?.enabled ?? false;
|
|
115
|
-
const clientPath = resolveFilePath(typesConfig.client, typesConfig.enabled, true, "{typesDir}/nitro-graphql-client.d.ts", placeholders);
|
|
116
|
-
if (clientPath) {
|
|
117
|
-
writeFile(clientPath, types.types);
|
|
118
|
-
if (!options.silent) logger.success(`Client types: ${clientPath}`);
|
|
119
|
-
}
|
|
120
|
-
const subscriptionCode = generateSubscriptionBuilder(docs, subscriptionsEnabled);
|
|
121
|
-
const sdkPath = resolveFilePath(sdkConfig.main, sdkConfig.enabled, true, "{clientDir}/default/sdk.ts", placeholders);
|
|
122
|
-
if (sdkPath) {
|
|
123
|
-
writeFile(sdkPath, subscriptionCode ? types.sdk + subscriptionCode : types.sdk);
|
|
124
|
-
if (!options.silent) logger.success(`SDK: ${sdkPath}`);
|
|
125
|
-
}
|
|
126
|
-
if (subscriptionsEnabled) {
|
|
127
|
-
const subscribePath = resolveFilePath(true, true, true, "{clientDir}/default/subscribe.ts", placeholders);
|
|
128
|
-
if (subscribePath && !existsSync(subscribePath)) {
|
|
129
|
-
writeFile(subscribePath, subscribeClientTemplate);
|
|
130
|
-
if (!options.silent) logger.success(`Subscribe config: ${subscribePath}`);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
async function generateExternalTypes(nitro, options = {}) {
|
|
135
|
-
for (const service of nitro.options.graphql?.externalServices || []) try {
|
|
136
|
-
if (!options.silent) consola.info(`[${service.name}] Processing external service`);
|
|
137
|
-
await downloadAndSaveSchema(service, nitro.options.buildDir);
|
|
138
|
-
const schema = await loadExternalSchema(service, nitro.options.buildDir);
|
|
139
|
-
if (!schema) {
|
|
140
|
-
consola.warn(`[${service.name}] Failed to load schema`);
|
|
141
|
-
continue;
|
|
142
|
-
}
|
|
143
|
-
const docs = service.documents?.length ? await loadGraphQLDocuments(service.documents).catch(() => []) : [];
|
|
144
|
-
if (service.documents?.length && !docs.length) {
|
|
145
|
-
consola.warn(`[${service.name}] No documents found`);
|
|
146
|
-
continue;
|
|
147
|
-
}
|
|
148
|
-
const types = await generateExternalClientTypesCore(service, schema, docs);
|
|
149
|
-
if (types === false) continue;
|
|
150
|
-
const placeholders = {
|
|
151
|
-
...getDefaultPaths(nitro),
|
|
152
|
-
serviceName: service.name
|
|
153
|
-
};
|
|
154
|
-
const typesConfig = getTypesConfig(nitro);
|
|
155
|
-
const sdkConfig = getSdkConfig(nitro);
|
|
156
|
-
const typesPath = resolveFilePath(service.paths?.types ?? typesConfig.external, typesConfig.enabled, true, "{typesDir}/nitro-graphql-client-{serviceName}.d.ts", placeholders);
|
|
157
|
-
if (typesPath) {
|
|
158
|
-
writeFile(typesPath, types.types);
|
|
159
|
-
if (!options.silent) consola.success(`[${service.name}] Types: ${typesPath}`);
|
|
160
|
-
}
|
|
161
|
-
const sdkPath = resolveFilePath(service.paths?.sdk ?? sdkConfig.external, sdkConfig.enabled, true, "{clientDir}/{serviceName}/sdk.ts", placeholders);
|
|
162
|
-
if (sdkPath) {
|
|
163
|
-
writeFile(sdkPath, types.sdk);
|
|
164
|
-
if (!options.silent) consola.success(`[${service.name}] SDK: ${sdkPath}`);
|
|
165
|
-
}
|
|
166
|
-
} catch (error) {
|
|
167
|
-
consola.error(`[${service.name}] External service failed:`, error);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
//#endregion
|
|
171
|
-
export { generateClientTypes, generateServerTypes };
|
package/dist/nitro/config.d.mts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { NitroGraphQLOptions } from "./types.mjs";
|
|
2
|
-
|
|
3
|
-
//#region src/nitro/config.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* Default type generation configuration
|
|
6
|
-
*/
|
|
7
|
-
declare const DEFAULT_TYPES_CONFIG: {
|
|
8
|
-
readonly server: ".graphql/nitro-graphql-server.d.ts";
|
|
9
|
-
readonly client: ".graphql/nitro-graphql-client.d.ts";
|
|
10
|
-
readonly enabled: true;
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* Default runtime GraphQL configuration
|
|
14
|
-
*/
|
|
15
|
-
declare const DEFAULT_RUNTIME_CONFIG: NitroGraphQLOptions;
|
|
16
|
-
/**
|
|
17
|
-
* Default ignore patterns for file watching
|
|
18
|
-
*/
|
|
19
|
-
declare const DEFAULT_IGNORE_PATTERNS: string[];
|
|
20
|
-
/**
|
|
21
|
-
* Default SDK configuration
|
|
22
|
-
*/
|
|
23
|
-
declare const DEFAULT_SDK_CONFIG: {
|
|
24
|
-
readonly enabled: true;
|
|
25
|
-
readonly main: true;
|
|
26
|
-
readonly external: true;
|
|
27
|
-
};
|
|
28
|
-
/**
|
|
29
|
-
* Default paths configuration
|
|
30
|
-
* These are used as placeholders and resolved based on framework
|
|
31
|
-
*/
|
|
32
|
-
declare const DEFAULT_PATHS_CONFIG: {
|
|
33
|
-
readonly serverDir: "server/graphql";
|
|
34
|
-
readonly clientDir: null;
|
|
35
|
-
readonly typesDir: null;
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* Default TypeScript strict mode setting
|
|
39
|
-
*/
|
|
40
|
-
declare const DEFAULT_TYPESCRIPT_STRICT: true;
|
|
41
|
-
/**
|
|
42
|
-
* Default watcher persistence setting
|
|
43
|
-
*/
|
|
44
|
-
declare const DEFAULT_WATCHER_PERSISTENT: true;
|
|
45
|
-
/**
|
|
46
|
-
* Default watcher ignore initial setting
|
|
47
|
-
*/
|
|
48
|
-
declare const DEFAULT_WATCHER_IGNORE_INITIAL: true;
|
|
49
|
-
//#endregion
|
|
50
|
-
export { DEFAULT_IGNORE_PATTERNS, DEFAULT_PATHS_CONFIG, DEFAULT_RUNTIME_CONFIG, DEFAULT_SDK_CONFIG, DEFAULT_TYPESCRIPT_STRICT, DEFAULT_TYPES_CONFIG, DEFAULT_WATCHER_IGNORE_INITIAL, DEFAULT_WATCHER_PERSISTENT };
|
package/dist/nitro/config.mjs
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { DEFAULT_CLIENT_TYPES_PATH, DEFAULT_SERVER_TYPES_PATH, ENDPOINT_GRAPHQL, ENDPOINT_HEALTH } from "../core/constants.mjs";
|
|
2
|
-
//#region src/nitro/config.ts
|
|
3
|
-
/**
|
|
4
|
-
* Default type generation configuration
|
|
5
|
-
*/
|
|
6
|
-
const DEFAULT_TYPES_CONFIG = {
|
|
7
|
-
server: DEFAULT_SERVER_TYPES_PATH,
|
|
8
|
-
client: DEFAULT_CLIENT_TYPES_PATH,
|
|
9
|
-
enabled: true
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* Default runtime GraphQL configuration
|
|
13
|
-
*/
|
|
14
|
-
const DEFAULT_RUNTIME_CONFIG = {
|
|
15
|
-
endpoint: {
|
|
16
|
-
graphql: ENDPOINT_GRAPHQL,
|
|
17
|
-
healthCheck: ENDPOINT_HEALTH
|
|
18
|
-
},
|
|
19
|
-
playground: true
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* Default ignore patterns for file watching
|
|
23
|
-
*/
|
|
24
|
-
const DEFAULT_IGNORE_PATTERNS = [];
|
|
25
|
-
/**
|
|
26
|
-
* Default SDK configuration
|
|
27
|
-
*/
|
|
28
|
-
const DEFAULT_SDK_CONFIG = {
|
|
29
|
-
enabled: true,
|
|
30
|
-
main: true,
|
|
31
|
-
external: true
|
|
32
|
-
};
|
|
33
|
-
/**
|
|
34
|
-
* Default paths configuration
|
|
35
|
-
* These are used as placeholders and resolved based on framework
|
|
36
|
-
*/
|
|
37
|
-
const DEFAULT_PATHS_CONFIG = {
|
|
38
|
-
serverDir: "server/graphql",
|
|
39
|
-
clientDir: null,
|
|
40
|
-
typesDir: null
|
|
41
|
-
};
|
|
42
|
-
/**
|
|
43
|
-
* Default TypeScript strict mode setting
|
|
44
|
-
*/
|
|
45
|
-
const DEFAULT_TYPESCRIPT_STRICT = true;
|
|
46
|
-
/**
|
|
47
|
-
* Default watcher persistence setting
|
|
48
|
-
*/
|
|
49
|
-
const DEFAULT_WATCHER_PERSISTENT = true;
|
|
50
|
-
/**
|
|
51
|
-
* Default watcher ignore initial setting
|
|
52
|
-
*/
|
|
53
|
-
const DEFAULT_WATCHER_IGNORE_INITIAL = true;
|
|
54
|
-
//#endregion
|
|
55
|
-
export { DEFAULT_IGNORE_PATTERNS, DEFAULT_PATHS_CONFIG, DEFAULT_RUNTIME_CONFIG, DEFAULT_SDK_CONFIG, DEFAULT_TYPESCRIPT_STRICT, DEFAULT_TYPES_CONFIG, DEFAULT_WATCHER_IGNORE_INITIAL, DEFAULT_WATCHER_PERSISTENT };
|