nitro-graphql 2.0.0-beta.36 → 2.0.0-beta.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/commands/generate.d.mts +26 -0
- package/dist/cli/commands/generate.mjs +196 -0
- package/dist/cli/commands/index.d.mts +4 -0
- package/dist/cli/commands/index.mjs +5 -0
- package/dist/cli/commands/init.d.mts +12 -0
- package/dist/cli/commands/init.mjs +100 -0
- package/dist/cli/commands/validate.d.mts +10 -0
- package/dist/cli/commands/validate.mjs +69 -0
- package/dist/cli/config.d.mts +75 -0
- package/dist/cli/config.mjs +20 -0
- package/dist/cli/index.d.mts +24 -0
- package/dist/cli/index.mjs +219 -0
- package/dist/core/codegen/client.d.mts +23 -0
- package/dist/core/codegen/client.mjs +150 -0
- package/dist/core/codegen/document-loader.d.mts +10 -0
- package/dist/core/codegen/document-loader.mjs +18 -0
- package/dist/core/codegen/index.d.mts +8 -0
- package/dist/core/codegen/index.mjs +9 -0
- package/dist/{utils/codegen-plugin.d.mts → core/codegen/plugin.d.mts} +2 -2
- package/dist/{utils/codegen-plugin.mjs → core/codegen/plugin.mjs} +1 -1
- package/dist/core/codegen/runtime.d.mts +20 -0
- package/dist/core/codegen/runtime.mjs +60 -0
- package/dist/core/codegen/schema-loader.d.mts +28 -0
- package/dist/core/codegen/schema-loader.mjs +128 -0
- package/dist/core/codegen/server.d.mts +28 -0
- package/dist/core/codegen/server.mjs +143 -0
- package/dist/{codegen → core/codegen}/validation.d.mts +1 -1
- package/dist/{codegen → core/codegen}/validation.mjs +1 -1
- package/dist/core/config.d.mts +50 -0
- package/dist/core/config.mjs +82 -0
- package/dist/core/constants.d.mts +188 -0
- package/dist/core/constants.mjs +210 -0
- package/dist/core/index.d.mts +32 -0
- package/dist/core/index.mjs +26 -0
- package/dist/core/scanning/ast-scanner.d.mts +23 -0
- package/dist/core/scanning/ast-scanner.mjs +103 -0
- package/dist/core/scanning/common.d.mts +37 -0
- package/dist/core/scanning/common.mjs +60 -0
- package/dist/core/scanning/directives.d.mts +10 -0
- package/dist/core/scanning/directives.mjs +29 -0
- package/dist/core/scanning/documents.d.mts +21 -0
- package/dist/core/scanning/documents.mjs +43 -0
- package/dist/core/scanning/index.d.mts +7 -0
- package/dist/core/scanning/index.mjs +8 -0
- package/dist/core/scanning/resolvers.d.mts +10 -0
- package/dist/core/scanning/resolvers.mjs +58 -0
- package/dist/core/scanning/schemas.d.mts +14 -0
- package/dist/core/scanning/schemas.mjs +64 -0
- package/dist/{utils/schema-builder.d.mts → core/schema/builder.d.mts} +7 -2
- package/dist/{utils/schema-builder.mjs → core/schema/builder.mjs} +22 -3
- package/dist/{utils → core/schema}/federation.d.mts +10 -5
- package/dist/{utils → core/schema}/federation.mjs +1 -1
- package/dist/core/schema/index.d.mts +3 -0
- package/dist/core/schema/index.mjs +4 -0
- package/dist/core/types/adapter.d.mts +58 -0
- package/dist/core/types/codegen.d.mts +133 -0
- package/dist/core/types/config.d.mts +212 -0
- package/dist/{types → core/types}/define.d.mts +3 -7
- package/dist/core/types/index.d.mts +5 -0
- package/dist/core/types/scanning.d.mts +69 -0
- package/dist/core/types/scanning.mjs +1 -0
- package/dist/{utils → core/utils}/directive-parser.d.mts +21 -5
- package/dist/{utils → core/utils}/directive-parser.mjs +25 -36
- package/dist/{utils → core/utils}/errors.d.mts +8 -4
- package/dist/{utils → core/utils}/errors.mjs +8 -4
- package/dist/core/utils/file-io.d.mts +24 -0
- package/dist/core/utils/file-io.mjs +47 -0
- package/dist/{utils → core/utils}/imports.d.mts +1 -1
- package/dist/{utils → core/utils}/imports.mjs +1 -1
- package/dist/core/utils/index.d.mts +7 -0
- package/dist/core/utils/index.mjs +8 -0
- package/dist/core/utils/logger.d.mts +19 -0
- package/dist/core/utils/logger.mjs +38 -0
- package/dist/{utils → core/utils}/ofetch-templates.d.mts +1 -1
- package/dist/{utils → core/utils}/ofetch-templates.mjs +1 -1
- package/dist/core/validation/external-services.d.mts +11 -0
- package/dist/{utils/validation.mjs → core/validation/external-services.mjs} +3 -3
- package/dist/core/validation/index.d.mts +2 -0
- package/dist/core/validation/index.mjs +3 -0
- package/dist/define.d.mts +1 -3
- package/dist/index.d.mts +6 -43
- package/dist/index.mjs +5 -62
- package/dist/nitro/adapter.d.mts +30 -0
- package/dist/nitro/adapter.mjs +97 -0
- package/dist/{utils → nitro}/apollo.d.mts +1 -1
- package/dist/{utils → nitro}/apollo.mjs +1 -1
- package/dist/nitro/codegen.d.mts +19 -0
- package/dist/nitro/codegen.mjs +141 -0
- package/dist/nitro/config.d.mts +52 -0
- package/dist/nitro/config.mjs +58 -0
- package/dist/nitro/index.d.mts +46 -0
- package/dist/nitro/index.mjs +65 -0
- package/dist/{utils/path-resolver.d.mts → nitro/paths.d.mts} +3 -19
- package/dist/{utils/path-resolver.mjs → nitro/paths.mjs} +2 -36
- package/dist/{rollup.d.mts → nitro/rollup.d.mts} +1 -1
- package/dist/{rollup.mjs → nitro/rollup.mjs} +11 -23
- package/dist/{routes → nitro/routes}/apollo-server.d.mts +1 -1
- package/dist/nitro/routes/apollo-server.mjs +71 -0
- package/dist/{routes → nitro/routes}/debug-template.d.mts +1 -1
- package/dist/{routes → nitro/routes}/debug-template.mjs +1 -1
- package/dist/{routes → nitro/routes}/debug.d.mts +10 -16
- package/dist/{routes → nitro/routes}/debug.mjs +2 -2
- package/dist/nitro/routes/graphql-yoga.d.mts +6 -0
- package/dist/{routes → nitro/routes}/graphql-yoga.mjs +21 -10
- package/dist/nitro/routes/health.d.mts +10 -0
- package/dist/{routes → nitro/routes}/health.mjs +1 -1
- package/dist/nitro/setup/file-watcher.d.mts +16 -0
- package/dist/{setup → nitro/setup}/file-watcher.mjs +14 -18
- package/dist/nitro/setup/logging.d.mts +17 -0
- package/dist/nitro/setup/logging.mjs +66 -0
- package/dist/nitro/setup/rollup-integration.d.mts +16 -0
- package/dist/{setup → nitro/setup}/rollup-integration.mjs +2 -2
- package/dist/nitro/setup/routes.d.mts +10 -0
- package/dist/nitro/setup/routes.mjs +35 -0
- package/dist/nitro/setup/ts-config.d.mts +11 -0
- package/dist/{setup → nitro/setup}/ts-config.mjs +3 -3
- package/dist/{setup.d.mts → nitro/setup.d.mts} +3 -2
- package/dist/{setup.mjs → nitro/setup.mjs} +73 -62
- package/dist/nitro/types.d.mts +378 -0
- package/dist/nitro/types.mjs +1 -0
- package/dist/nitro/virtual/generators.d.mts +31 -0
- package/dist/nitro/virtual/generators.mjs +193 -0
- package/dist/nitro/virtual/stubs.d.mts +20 -0
- package/dist/nitro/virtual/stubs.mjs +31 -0
- package/dist/{ecosystem/nuxt.d.mts → nuxt.d.mts} +1 -1
- package/dist/{ecosystem/nuxt.mjs → nuxt.mjs} +2 -2
- package/dist/{graphql/server.d.mts → stubs/index.d.mts} +5 -1
- package/dist/stubs/index.mjs +1 -0
- package/package.json +45 -43
- package/dist/codegen/client-types.d.mts +0 -13
- package/dist/codegen/client-types.mjs +0 -131
- package/dist/codegen/external-types.d.mts +0 -12
- package/dist/codegen/external-types.mjs +0 -88
- package/dist/codegen/index.d.mts +0 -18
- package/dist/codegen/index.mjs +0 -24
- package/dist/codegen/server-types.d.mts +0 -13
- package/dist/codegen/server-types.mjs +0 -64
- package/dist/config/defaults.mjs +0 -36
- package/dist/constants/scalars.mjs +0 -27
- package/dist/constants.mjs +0 -106
- package/dist/graphql/index.d.mts +0 -5
- package/dist/routes/apollo-server.mjs +0 -45
- package/dist/routes/graphql-yoga.d.mts +0 -6
- package/dist/routes/health.d.mts +0 -10
- package/dist/setup/graphql-scanner.mjs +0 -25
- package/dist/setup/scaffold-generator.mjs +0 -109
- package/dist/types/index.d.mts +0 -246
- package/dist/types/standard-schema.d.mts +0 -59
- package/dist/utils/client-codegen.d.mts +0 -41
- package/dist/utils/client-codegen.mjs +0 -267
- package/dist/utils/file-generator.d.mts +0 -37
- package/dist/utils/file-generator.mjs +0 -72
- package/dist/utils/file-writer.d.mts +0 -35
- package/dist/utils/file-writer.mjs +0 -32
- package/dist/utils/index.d.mts +0 -13
- package/dist/utils/index.mjs +0 -13
- package/dist/utils/layers.d.mts +0 -22
- package/dist/utils/layers.mjs +0 -28
- package/dist/utils/scanning/common.d.mts +0 -23
- package/dist/utils/scanning/common.mjs +0 -39
- package/dist/utils/scanning/directives.d.mts +0 -11
- package/dist/utils/scanning/directives.mjs +0 -43
- package/dist/utils/scanning/documents.d.mts +0 -15
- package/dist/utils/scanning/documents.mjs +0 -46
- package/dist/utils/scanning/index.d.mts +0 -6
- package/dist/utils/scanning/index.mjs +0 -7
- package/dist/utils/scanning/resolvers.d.mts +0 -11
- package/dist/utils/scanning/resolvers.mjs +0 -100
- package/dist/utils/scanning/schemas.d.mts +0 -15
- package/dist/utils/scanning/schemas.mjs +0 -29
- package/dist/utils/server-codegen.d.mts +0 -7
- package/dist/utils/server-codegen.mjs +0 -113
- package/dist/utils/type-generation.d.mts +0 -6
- package/dist/utils/type-generation.mjs +0 -7
- package/dist/utils/validation.d.mts +0 -11
- package/dist/virtual/debug-info.d.mts +0 -9
- package/dist/virtual/debug-info.mjs +0 -26
- package/dist/virtual/generators/config.d.mts +0 -22
- package/dist/virtual/generators/config.mjs +0 -36
- package/dist/virtual/generators/debug.d.mts +0 -14
- package/dist/virtual/generators/debug.mjs +0 -53
- package/dist/virtual/generators/directives.d.mts +0 -14
- package/dist/virtual/generators/directives.mjs +0 -52
- package/dist/virtual/generators/index.d.mts +0 -6
- package/dist/virtual/generators/index.mjs +0 -7
- package/dist/virtual/generators/resolvers.d.mts +0 -14
- package/dist/virtual/generators/resolvers.mjs +0 -55
- package/dist/virtual/generators/schemas.d.mts +0 -14
- package/dist/virtual/generators/schemas.mjs +0 -43
- package/dist/virtual/graphql-config.d.mts +0 -9
- package/dist/virtual/graphql-config.mjs +0 -10
- package/dist/virtual/module-config.d.mts +0 -9
- package/dist/virtual/module-config.mjs +0 -10
- package/dist/virtual/server-directives.d.mts +0 -11
- package/dist/virtual/server-directives.mjs +0 -10
- package/dist/virtual/server-resolvers.d.mts +0 -11
- package/dist/virtual/server-resolvers.mjs +0 -10
- package/dist/virtual/server-schemas.d.mts +0 -11
- package/dist/virtual/server-schemas.mjs +0 -10
- /package/dist/{graphql/index.mjs → core/types/adapter.mjs} +0 -0
- /package/dist/{graphql/server.mjs → core/types/codegen.mjs} +0 -0
- /package/dist/{types/define.mjs → core/types/config.mjs} +0 -0
- /package/dist/{types/index.mjs → core/types/define.mjs} +0 -0
- /package/dist/{types/standard-schema.mjs → core/types/index.mjs} +0 -0
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { LOG_TAG } from "../core/constants.mjs";
|
|
3
|
+
import { DEFAULT_CLI_CONFIG, defineConfig } from "./config.mjs";
|
|
4
|
+
import consola from "consola";
|
|
5
|
+
import { resolve } from "pathe";
|
|
6
|
+
import { existsSync } from "node:fs";
|
|
7
|
+
import { defineCommand, runMain } from "citty";
|
|
8
|
+
|
|
9
|
+
//#region src/cli/index.ts
|
|
10
|
+
const logger = consola.withTag(LOG_TAG);
|
|
11
|
+
/**
|
|
12
|
+
* Load CLI configuration from file or defaults
|
|
13
|
+
*/
|
|
14
|
+
async function loadConfig(cwd = process.cwd()) {
|
|
15
|
+
for (const file of [
|
|
16
|
+
"nitro-graphql.config.ts",
|
|
17
|
+
"nitro-graphql.config.js",
|
|
18
|
+
"nitro-graphql.config.mjs",
|
|
19
|
+
"graphql.config.ts"
|
|
20
|
+
]) {
|
|
21
|
+
const configPath = resolve(cwd, file);
|
|
22
|
+
if (existsSync(configPath)) try {
|
|
23
|
+
const module = await import(configPath);
|
|
24
|
+
const config = module.default || module;
|
|
25
|
+
logger.info(`Loaded config from ${file}`);
|
|
26
|
+
return {
|
|
27
|
+
...DEFAULT_CLI_CONFIG,
|
|
28
|
+
...config
|
|
29
|
+
};
|
|
30
|
+
} catch (error) {
|
|
31
|
+
logger.warn(`Failed to load config from ${file}:`, error);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
logger.debug("Using default configuration");
|
|
35
|
+
return { ...DEFAULT_CLI_CONFIG };
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Create CLI context from configuration
|
|
39
|
+
*/
|
|
40
|
+
async function createCLIContext(options = {}) {
|
|
41
|
+
const cwd = options.cwd || process.cwd();
|
|
42
|
+
const config = await loadConfig(cwd);
|
|
43
|
+
const rootDir = config.rootDir ? resolve(cwd, config.rootDir) : cwd;
|
|
44
|
+
const buildDir = config.buildDir ? resolve(rootDir, config.buildDir) : resolve(rootDir, ".nitro-graphql");
|
|
45
|
+
const serverDir = config.serverDir ? resolve(rootDir, config.serverDir) : resolve(rootDir, "server/graphql");
|
|
46
|
+
const clientDir = config.clientDir ? resolve(rootDir, config.clientDir) : resolve(rootDir, "graphql");
|
|
47
|
+
const typesDir = config.typesDir ? resolve(rootDir, config.typesDir) : resolve(buildDir, "types");
|
|
48
|
+
return {
|
|
49
|
+
cwd,
|
|
50
|
+
config: {
|
|
51
|
+
...config,
|
|
52
|
+
rootDir,
|
|
53
|
+
buildDir,
|
|
54
|
+
serverDir,
|
|
55
|
+
clientDir,
|
|
56
|
+
typesDir,
|
|
57
|
+
framework: config.framework || "graphql-yoga",
|
|
58
|
+
ignore: config.ignore || ["**/node_modules/**", "**/dist/**"]
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
const generateCommand = defineCommand({
|
|
63
|
+
meta: {
|
|
64
|
+
name: "generate",
|
|
65
|
+
description: "Generate all GraphQL types"
|
|
66
|
+
},
|
|
67
|
+
args: {
|
|
68
|
+
cwd: {
|
|
69
|
+
type: "string",
|
|
70
|
+
description: "Set working directory"
|
|
71
|
+
},
|
|
72
|
+
silent: {
|
|
73
|
+
type: "boolean",
|
|
74
|
+
alias: "s",
|
|
75
|
+
description: "Suppress output"
|
|
76
|
+
},
|
|
77
|
+
watch: {
|
|
78
|
+
type: "boolean",
|
|
79
|
+
alias: "w",
|
|
80
|
+
description: "Watch mode"
|
|
81
|
+
},
|
|
82
|
+
runtime: {
|
|
83
|
+
type: "boolean",
|
|
84
|
+
alias: "r",
|
|
85
|
+
description: "Generate runtime files (resolvers.ts, schema.ts)"
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
async run({ args }) {
|
|
89
|
+
const ctx = await createCLIContext({ cwd: args.cwd });
|
|
90
|
+
const silent = Boolean(args.silent);
|
|
91
|
+
const watch = Boolean(args.watch);
|
|
92
|
+
const runtime = Boolean(args.runtime) || Boolean(ctx.config.runtime);
|
|
93
|
+
if (!silent) logger.info("Generating GraphQL types...");
|
|
94
|
+
const { generateAll } = await import("./commands/generate.mjs");
|
|
95
|
+
await generateAll(ctx, {
|
|
96
|
+
silent,
|
|
97
|
+
watch,
|
|
98
|
+
runtime
|
|
99
|
+
});
|
|
100
|
+
if (!silent) logger.success("Type generation complete!");
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
const generateServerCommand = defineCommand({
|
|
104
|
+
meta: {
|
|
105
|
+
name: "generate:server",
|
|
106
|
+
description: "Generate server types only"
|
|
107
|
+
},
|
|
108
|
+
args: {
|
|
109
|
+
cwd: {
|
|
110
|
+
type: "string",
|
|
111
|
+
description: "Set working directory"
|
|
112
|
+
},
|
|
113
|
+
silent: {
|
|
114
|
+
type: "boolean",
|
|
115
|
+
alias: "s",
|
|
116
|
+
description: "Suppress output"
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
async run({ args }) {
|
|
120
|
+
const ctx = await createCLIContext({ cwd: args.cwd });
|
|
121
|
+
const silent = Boolean(args.silent);
|
|
122
|
+
if (!silent) logger.info("Generating server types...");
|
|
123
|
+
const { generateServer } = await import("./commands/generate.mjs");
|
|
124
|
+
await generateServer(ctx, { silent });
|
|
125
|
+
if (!silent) logger.success("Server type generation complete!");
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
const generateClientCommand = defineCommand({
|
|
129
|
+
meta: {
|
|
130
|
+
name: "generate:client",
|
|
131
|
+
description: "Generate client types only"
|
|
132
|
+
},
|
|
133
|
+
args: {
|
|
134
|
+
cwd: {
|
|
135
|
+
type: "string",
|
|
136
|
+
description: "Set working directory"
|
|
137
|
+
},
|
|
138
|
+
silent: {
|
|
139
|
+
type: "boolean",
|
|
140
|
+
alias: "s",
|
|
141
|
+
description: "Suppress output"
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
async run({ args }) {
|
|
145
|
+
const ctx = await createCLIContext({ cwd: args.cwd });
|
|
146
|
+
const silent = Boolean(args.silent);
|
|
147
|
+
if (!silent) logger.info("Generating client types...");
|
|
148
|
+
const { generateClient } = await import("./commands/generate.mjs");
|
|
149
|
+
await generateClient(ctx, { silent });
|
|
150
|
+
if (!silent) logger.success("Client type generation complete!");
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
const validateCommand = defineCommand({
|
|
154
|
+
meta: {
|
|
155
|
+
name: "validate",
|
|
156
|
+
description: "Validate GraphQL schemas"
|
|
157
|
+
},
|
|
158
|
+
args: { cwd: {
|
|
159
|
+
type: "string",
|
|
160
|
+
description: "Set working directory"
|
|
161
|
+
} },
|
|
162
|
+
async run({ args }) {
|
|
163
|
+
const ctx = await createCLIContext({ cwd: args.cwd });
|
|
164
|
+
logger.info("Validating GraphQL schemas...");
|
|
165
|
+
const { validate } = await import("./commands/validate.mjs");
|
|
166
|
+
if (await validate(ctx)) logger.success("Schema validation passed!");
|
|
167
|
+
else {
|
|
168
|
+
logger.error("Schema validation failed!");
|
|
169
|
+
process.exit(1);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
const initCommand = defineCommand({
|
|
174
|
+
meta: {
|
|
175
|
+
name: "init",
|
|
176
|
+
description: "Initialize project structure"
|
|
177
|
+
},
|
|
178
|
+
args: {
|
|
179
|
+
cwd: {
|
|
180
|
+
type: "string",
|
|
181
|
+
description: "Set working directory"
|
|
182
|
+
},
|
|
183
|
+
force: {
|
|
184
|
+
type: "boolean",
|
|
185
|
+
alias: "f",
|
|
186
|
+
description: "Force overwrite existing files"
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
async run({ args }) {
|
|
190
|
+
const ctx = await createCLIContext({ cwd: args.cwd });
|
|
191
|
+
logger.info("Initializing nitro-graphql project...");
|
|
192
|
+
const { init } = await import("./commands/init.mjs");
|
|
193
|
+
await init(ctx, { force: Boolean(args.force) });
|
|
194
|
+
logger.success("Project initialized!");
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
const main = defineCommand({
|
|
198
|
+
meta: {
|
|
199
|
+
name: "nitro-graphql",
|
|
200
|
+
version: "2.0.0",
|
|
201
|
+
description: "GraphQL type generation CLI for Nitro"
|
|
202
|
+
},
|
|
203
|
+
subCommands: {
|
|
204
|
+
"generate": generateCommand,
|
|
205
|
+
"gen": generateCommand,
|
|
206
|
+
"g": generateCommand,
|
|
207
|
+
"generate:server": generateServerCommand,
|
|
208
|
+
"gen:server": generateServerCommand,
|
|
209
|
+
"generate:client": generateClientCommand,
|
|
210
|
+
"gen:client": generateClientCommand,
|
|
211
|
+
"validate": validateCommand,
|
|
212
|
+
"v": validateCommand,
|
|
213
|
+
"init": initCommand
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
runMain(main);
|
|
217
|
+
|
|
218
|
+
//#endregion
|
|
219
|
+
export { createCLIContext, defineConfig, loadConfig };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ClientCodegenConfig, ClientCodegenInput, ClientCodegenResult, ExternalServiceCodegenConfig } from "../types/codegen.mjs";
|
|
2
|
+
import { loadGraphQLDocuments } from "./document-loader.mjs";
|
|
3
|
+
import { GraphQLLoadSchemaOptions, GraphQLTypeDefPointer, downloadAndSaveSchema, graphQLLoadSchemaSync, loadExternalSchema } from "./schema-loader.mjs";
|
|
4
|
+
import { Source } from "@graphql-tools/utils";
|
|
5
|
+
import { GraphQLSchema } from "graphql";
|
|
6
|
+
|
|
7
|
+
//#region src/core/codegen/client.d.ts
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Default client codegen configuration
|
|
11
|
+
*/
|
|
12
|
+
declare const DEFAULT_CLIENT_CODEGEN_CONFIG: ClientCodegenConfig;
|
|
13
|
+
/**
|
|
14
|
+
* Generate client-side GraphQL types
|
|
15
|
+
* Pure function that generates TypeScript types from a GraphQL schema and documents
|
|
16
|
+
*/
|
|
17
|
+
declare function generateClientTypesCore(input: ClientCodegenInput): Promise<ClientCodegenResult | false>;
|
|
18
|
+
/**
|
|
19
|
+
* Generate client types for external GraphQL service
|
|
20
|
+
*/
|
|
21
|
+
declare function generateExternalClientTypesCore(service: ExternalServiceCodegenConfig, schema: GraphQLSchema, documents: Source[], virtualTypesPath?: string): Promise<ClientCodegenResult | false>;
|
|
22
|
+
//#endregion
|
|
23
|
+
export { DEFAULT_CLIENT_CODEGEN_CONFIG, type GraphQLLoadSchemaOptions, type GraphQLTypeDefPointer, downloadAndSaveSchema, generateClientTypesCore, generateExternalClientTypesCore, graphQLLoadSchemaSync, loadExternalSchema, loadGraphQLDocuments };
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { DEFAULT_GRAPHQL_SCALARS } from "../constants.mjs";
|
|
2
|
+
import { pluginContent } from "./plugin.mjs";
|
|
3
|
+
import { loadGraphQLDocuments } from "./document-loader.mjs";
|
|
4
|
+
import { downloadAndSaveSchema, graphQLLoadSchemaSync, loadExternalSchema } from "./schema-loader.mjs";
|
|
5
|
+
import { defu as defu$1 } from "defu";
|
|
6
|
+
import { codegen } from "@graphql-codegen/core";
|
|
7
|
+
import { preset } from "@graphql-codegen/import-types-preset";
|
|
8
|
+
import { plugin } from "@graphql-codegen/typed-document-node";
|
|
9
|
+
import { plugin as plugin$1 } from "@graphql-codegen/typescript";
|
|
10
|
+
import { plugin as plugin$2 } from "@graphql-codegen/typescript-generic-sdk";
|
|
11
|
+
import { plugin as plugin$3 } from "@graphql-codegen/typescript-operations";
|
|
12
|
+
import { printSchemaWithDirectives } from "@graphql-tools/utils";
|
|
13
|
+
import { parse } from "graphql";
|
|
14
|
+
|
|
15
|
+
//#region src/core/codegen/client.ts
|
|
16
|
+
/**
|
|
17
|
+
* Default client codegen configuration
|
|
18
|
+
*/
|
|
19
|
+
const DEFAULT_CLIENT_CODEGEN_CONFIG = {
|
|
20
|
+
emitLegacyCommonJSImports: false,
|
|
21
|
+
useTypeImports: true,
|
|
22
|
+
enumsAsTypes: true,
|
|
23
|
+
strictScalars: true,
|
|
24
|
+
maybeValue: "T | null | undefined",
|
|
25
|
+
inputMaybeValue: "T | undefined",
|
|
26
|
+
documentMode: "string",
|
|
27
|
+
pureMagicComment: true,
|
|
28
|
+
dedupeOperationSuffix: true,
|
|
29
|
+
rawRequest: true,
|
|
30
|
+
scalars: DEFAULT_GRAPHQL_SCALARS
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Generate generic SDK content for schema-only generation
|
|
34
|
+
*/
|
|
35
|
+
function generateGenericSdkContent() {
|
|
36
|
+
return `// THIS FILE IS GENERATED, DO NOT EDIT!
|
|
37
|
+
/* eslint-disable eslint-comments/no-unlimited-disable */
|
|
38
|
+
/* tslint:disable */
|
|
39
|
+
/* eslint-disable */
|
|
40
|
+
/* prettier-ignore */
|
|
41
|
+
|
|
42
|
+
import type { GraphQLResolveInfo } from 'graphql'
|
|
43
|
+
export type RequireFields<T, K extends keyof T> = Omit<T, K> & { [P in K]-?: NonNullable<T[P]> }
|
|
44
|
+
|
|
45
|
+
export interface Requester<C = {}, E = unknown> {
|
|
46
|
+
<R, V>(doc: string, vars?: V, options?: C): Promise<R> | AsyncIterable<R>
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export type Sdk = {
|
|
50
|
+
request: <R, V = Record<string, any>>(document: string, variables?: V) => Promise<R>
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function getSdk(requester: Requester): Sdk {
|
|
54
|
+
return {
|
|
55
|
+
request: <R, V = Record<string, any>>(document: string, variables?: V): Promise<R> => {
|
|
56
|
+
return requester<R, V>(document, variables)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
`;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Generate client-side GraphQL types
|
|
64
|
+
* Pure function that generates TypeScript types from a GraphQL schema and documents
|
|
65
|
+
*/
|
|
66
|
+
async function generateClientTypesCore(input) {
|
|
67
|
+
const { schema, documents, config = {}, sdkConfig = {}, outputPath, serviceName, virtualTypesPath } = input;
|
|
68
|
+
if (documents.length === 0 && !serviceName) return false;
|
|
69
|
+
const mergedConfig = defu$1(DEFAULT_CLIENT_CODEGEN_CONFIG, config);
|
|
70
|
+
const mergedSdkConfig = defu$1(mergedConfig, sdkConfig);
|
|
71
|
+
try {
|
|
72
|
+
if (documents.length === 0) return {
|
|
73
|
+
types: await codegen({
|
|
74
|
+
filename: outputPath || "client-types.generated.ts",
|
|
75
|
+
schema: parse(printSchemaWithDirectives(schema)),
|
|
76
|
+
documents: [],
|
|
77
|
+
config: mergedConfig,
|
|
78
|
+
plugins: [{ pluginContent: {} }, { typescript: {} }],
|
|
79
|
+
pluginMap: {
|
|
80
|
+
pluginContent: { plugin: pluginContent },
|
|
81
|
+
typescript: { plugin: plugin$1 }
|
|
82
|
+
}
|
|
83
|
+
}),
|
|
84
|
+
sdk: generateGenericSdkContent()
|
|
85
|
+
};
|
|
86
|
+
const enableTypedDocumentNode = config.typedDocumentNode === true;
|
|
87
|
+
const plugins = [
|
|
88
|
+
{ pluginContent: {} },
|
|
89
|
+
{ typescript: {} },
|
|
90
|
+
{ typescriptOperations: {} }
|
|
91
|
+
];
|
|
92
|
+
const pluginMap = {
|
|
93
|
+
pluginContent: { plugin: pluginContent },
|
|
94
|
+
typescript: { plugin: plugin$1 },
|
|
95
|
+
typescriptOperations: { plugin: plugin$3 }
|
|
96
|
+
};
|
|
97
|
+
if (enableTypedDocumentNode) {
|
|
98
|
+
plugins.push({ typedDocumentNode: {} });
|
|
99
|
+
pluginMap.typedDocumentNode = { plugin };
|
|
100
|
+
}
|
|
101
|
+
const output = await codegen({
|
|
102
|
+
filename: outputPath || "client-types.generated.ts",
|
|
103
|
+
schema: parse(printSchemaWithDirectives(schema)),
|
|
104
|
+
documents: [...documents],
|
|
105
|
+
config: mergedConfig,
|
|
106
|
+
plugins,
|
|
107
|
+
pluginMap
|
|
108
|
+
});
|
|
109
|
+
const typesPath = virtualTypesPath || (serviceName ? `#graphql/client/${serviceName}` : "#graphql/client");
|
|
110
|
+
const sdkOutput = await preset.buildGeneratesSection({
|
|
111
|
+
baseOutputDir: outputPath || "client-types.generated.ts",
|
|
112
|
+
schema: parse(printSchemaWithDirectives(schema)),
|
|
113
|
+
documents: [...documents],
|
|
114
|
+
config: mergedSdkConfig,
|
|
115
|
+
presetConfig: { typesPath },
|
|
116
|
+
plugins: [{ pluginContent: {} }, { typescriptGenericSdk: {} }],
|
|
117
|
+
pluginMap: {
|
|
118
|
+
pluginContent: { plugin: pluginContent },
|
|
119
|
+
typescriptGenericSdk: { plugin: plugin$2 }
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
return {
|
|
123
|
+
types: output,
|
|
124
|
+
sdk: (await Promise.all(sdkOutput.map(async (config$1) => {
|
|
125
|
+
return {
|
|
126
|
+
file: config$1.filename,
|
|
127
|
+
content: await codegen(config$1)
|
|
128
|
+
};
|
|
129
|
+
})))[0]?.content || ""
|
|
130
|
+
};
|
|
131
|
+
} catch {
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Generate client types for external GraphQL service
|
|
137
|
+
*/
|
|
138
|
+
async function generateExternalClientTypesCore(service, schema, documents, virtualTypesPath) {
|
|
139
|
+
return generateClientTypesCore({
|
|
140
|
+
schema,
|
|
141
|
+
documents,
|
|
142
|
+
config: service.codegen?.client || {},
|
|
143
|
+
sdkConfig: service.codegen?.clientSDK || {},
|
|
144
|
+
serviceName: service.name,
|
|
145
|
+
virtualTypesPath
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
//#endregion
|
|
150
|
+
export { DEFAULT_CLIENT_CODEGEN_CONFIG, downloadAndSaveSchema, generateClientTypesCore, generateExternalClientTypesCore, graphQLLoadSchemaSync, loadExternalSchema, loadGraphQLDocuments };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Source } from "@graphql-tools/utils";
|
|
2
|
+
|
|
3
|
+
//#region src/core/codegen/document-loader.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Load GraphQL documents from files
|
|
7
|
+
*/
|
|
8
|
+
declare function loadGraphQLDocuments(patterns: string | string[]): Promise<Source[]>;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { loadGraphQLDocuments };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { GraphQLFileLoader } from "@graphql-tools/graphql-file-loader";
|
|
2
|
+
import { loadDocuments } from "@graphql-tools/load";
|
|
3
|
+
|
|
4
|
+
//#region src/core/codegen/document-loader.ts
|
|
5
|
+
/**
|
|
6
|
+
* Load GraphQL documents from files
|
|
7
|
+
*/
|
|
8
|
+
async function loadGraphQLDocuments(patterns) {
|
|
9
|
+
try {
|
|
10
|
+
return await loadDocuments(patterns, { loaders: [new GraphQLFileLoader()] });
|
|
11
|
+
} catch (e) {
|
|
12
|
+
if ((e.message || "").includes("Unable to find any GraphQL type definitions for the following pointers:")) return [];
|
|
13
|
+
throw e;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { loadGraphQLDocuments };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { loadGraphQLDocuments } from "./document-loader.mjs";
|
|
2
|
+
import { GraphQLLoadSchemaOptions, GraphQLTypeDefPointer, downloadAndSaveSchema, graphQLLoadSchemaSync, loadExternalSchema } from "./schema-loader.mjs";
|
|
3
|
+
import { DEFAULT_CLIENT_CODEGEN_CONFIG, generateClientTypesCore, generateExternalClientTypesCore } from "./client.mjs";
|
|
4
|
+
import { GENERATED_FILE_HEADER, pluginContent } from "./plugin.mjs";
|
|
5
|
+
import { generateResolverModule, generateRuntimeIndex, generateSchemaModule } from "./runtime.mjs";
|
|
6
|
+
import { DEFAULT_SERVER_CODEGEN_CONFIG, generateServerTypesCore, generateTypes } from "./server.mjs";
|
|
7
|
+
import { validateNoDuplicateTypes } from "./validation.mjs";
|
|
8
|
+
export { DEFAULT_CLIENT_CODEGEN_CONFIG, DEFAULT_SERVER_CODEGEN_CONFIG, GENERATED_FILE_HEADER, type GraphQLLoadSchemaOptions, type GraphQLTypeDefPointer, downloadAndSaveSchema, generateClientTypesCore, generateExternalClientTypesCore, generateResolverModule, generateRuntimeIndex, generateSchemaModule, generateServerTypesCore, generateTypes, graphQLLoadSchemaSync, loadExternalSchema, loadGraphQLDocuments, pluginContent, validateNoDuplicateTypes };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { GENERATED_FILE_HEADER, pluginContent } from "./plugin.mjs";
|
|
2
|
+
import { loadGraphQLDocuments } from "./document-loader.mjs";
|
|
3
|
+
import { downloadAndSaveSchema, graphQLLoadSchemaSync, loadExternalSchema } from "./schema-loader.mjs";
|
|
4
|
+
import { DEFAULT_CLIENT_CODEGEN_CONFIG, generateClientTypesCore, generateExternalClientTypesCore } from "./client.mjs";
|
|
5
|
+
import { generateResolverModule, generateRuntimeIndex, generateSchemaModule } from "./runtime.mjs";
|
|
6
|
+
import { DEFAULT_SERVER_CODEGEN_CONFIG, generateServerTypesCore, generateTypes } from "./server.mjs";
|
|
7
|
+
import { validateNoDuplicateTypes } from "./validation.mjs";
|
|
8
|
+
|
|
9
|
+
export { DEFAULT_CLIENT_CODEGEN_CONFIG, DEFAULT_SERVER_CODEGEN_CONFIG, GENERATED_FILE_HEADER, downloadAndSaveSchema, generateClientTypesCore, generateExternalClientTypesCore, generateResolverModule, generateRuntimeIndex, generateSchemaModule, generateServerTypesCore, generateTypes, graphQLLoadSchemaSync, loadExternalSchema, loadGraphQLDocuments, pluginContent, validateNoDuplicateTypes };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { GraphQLSchema } from "graphql";
|
|
2
1
|
import { Source } from "@graphql-tools/utils";
|
|
2
|
+
import { GraphQLSchema } from "graphql";
|
|
3
3
|
|
|
4
|
-
//#region src/
|
|
4
|
+
//#region src/core/codegen/plugin.d.ts
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Plugin to add prepend comments to generated files
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ScannedResolver } from "../types/scanning.mjs";
|
|
2
|
+
import "../types/index.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/core/codegen/runtime.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Generate resolver module code
|
|
8
|
+
* Outputs Nitro-compatible format with { resolver: ... } wrapper
|
|
9
|
+
*/
|
|
10
|
+
declare function generateResolverModule(resolvers: ScannedResolver[], baseDir: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Generate schema module code
|
|
13
|
+
*/
|
|
14
|
+
declare function generateSchemaModule(schemaString: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* Generate runtime index module
|
|
17
|
+
*/
|
|
18
|
+
declare function generateRuntimeIndex(): string;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { generateResolverModule, generateRuntimeIndex, generateSchemaModule };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { relative } from "pathe";
|
|
2
|
+
|
|
3
|
+
//#region src/core/codegen/runtime.ts
|
|
4
|
+
/**
|
|
5
|
+
* Generate resolver module code
|
|
6
|
+
* Outputs Nitro-compatible format with { resolver: ... } wrapper
|
|
7
|
+
*/
|
|
8
|
+
function generateResolverModule(resolvers, baseDir) {
|
|
9
|
+
if (!resolvers.length) return `// Auto-generated by nitro-graphql - no resolvers found
|
|
10
|
+
export const resolvers = []
|
|
11
|
+
`;
|
|
12
|
+
const imports = [];
|
|
13
|
+
const resolverEntries = [];
|
|
14
|
+
const reexports = [];
|
|
15
|
+
for (const resolver of resolvers) {
|
|
16
|
+
const relativePath = relative(baseDir, resolver.specifier).replace(/\.ts$/, "");
|
|
17
|
+
const exportNames = resolver.imports.map((i) => i.name);
|
|
18
|
+
if (exportNames.length > 0) {
|
|
19
|
+
imports.push(`import { ${exportNames.join(", ")} } from '${relativePath}'`);
|
|
20
|
+
for (const name of exportNames) resolverEntries.push(` { resolver: ${name} }`);
|
|
21
|
+
reexports.push(`export { ${exportNames.join(", ")} } from '${relativePath}'`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return `// Auto-generated by nitro-graphql - do not edit
|
|
25
|
+
${imports.join("\n")}
|
|
26
|
+
|
|
27
|
+
export const resolvers = [
|
|
28
|
+
${resolverEntries.join(",\n")},
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
// Re-exports for tree-shaking
|
|
32
|
+
${reexports.join("\n")}
|
|
33
|
+
`;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Generate schema module code
|
|
37
|
+
*/
|
|
38
|
+
function generateSchemaModule(schemaString) {
|
|
39
|
+
return `// Auto-generated by nitro-graphql - do not edit
|
|
40
|
+
export const schemaString = \`
|
|
41
|
+
${schemaString.replace(/`/g, "\\`").replace(/\$/g, "\\$")}
|
|
42
|
+
\`
|
|
43
|
+
|
|
44
|
+
// Pre-parsed for convenience
|
|
45
|
+
import { parse } from 'graphql'
|
|
46
|
+
export const typeDefs = parse(schemaString)
|
|
47
|
+
`;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Generate runtime index module
|
|
51
|
+
*/
|
|
52
|
+
function generateRuntimeIndex() {
|
|
53
|
+
return `// Auto-generated by nitro-graphql - do not edit
|
|
54
|
+
export { resolvers } from './resolvers'
|
|
55
|
+
export { schemaString, typeDefs } from './schema'
|
|
56
|
+
`;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
//#endregion
|
|
60
|
+
export { generateResolverModule, generateRuntimeIndex, generateSchemaModule };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ExternalServiceCodegenConfig } from "../types/codegen.mjs";
|
|
2
|
+
import { GraphQLSchema } from "graphql";
|
|
3
|
+
import { LoadSchemaOptions, UnnormalizedTypeDefPointer } from "@graphql-tools/load";
|
|
4
|
+
|
|
5
|
+
//#region src/core/codegen/schema-loader.d.ts
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Type definition pointer for GraphQL schemas
|
|
9
|
+
*/
|
|
10
|
+
type GraphQLTypeDefPointer = UnnormalizedTypeDefPointer | UnnormalizedTypeDefPointer[];
|
|
11
|
+
/**
|
|
12
|
+
* Options for loading GraphQL schemas
|
|
13
|
+
*/
|
|
14
|
+
type GraphQLLoadSchemaOptions = Partial<LoadSchemaOptions>;
|
|
15
|
+
/**
|
|
16
|
+
* Load GraphQL schema synchronously
|
|
17
|
+
*/
|
|
18
|
+
declare function graphQLLoadSchemaSync(schemaPointers: GraphQLTypeDefPointer, data?: GraphQLLoadSchemaOptions): GraphQLSchema | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Load schema from external GraphQL service
|
|
21
|
+
*/
|
|
22
|
+
declare function loadExternalSchema(service: ExternalServiceCodegenConfig, buildDir?: string): Promise<GraphQLSchema | undefined>;
|
|
23
|
+
/**
|
|
24
|
+
* Download and save schema from external service
|
|
25
|
+
*/
|
|
26
|
+
declare function downloadAndSaveSchema(service: ExternalServiceCodegenConfig, buildDir: string): Promise<string | undefined>;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { GraphQLLoadSchemaOptions, GraphQLTypeDefPointer, downloadAndSaveSchema, graphQLLoadSchemaSync, loadExternalSchema };
|