@ptdgrp/typedgql 1.0.0-beta.16 → 1.0.0-beta.20
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 +55 -2
- package/README.zh-CN.md +57 -4
- package/dist/cli.cjs +47 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +49 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/{schema-loader-BIP51DZO.cjs → config-loader-Bxj44SGD.cjs} +348 -41
- package/dist/{schema-loader-CsabdnfI.mjs → config-loader-DZ7d_CWR.mjs} +342 -47
- package/dist/config-loader-DZ7d_CWR.mjs.map +1 -0
- package/dist/cyrb53-B2tdX6NT.mjs +921 -0
- package/dist/cyrb53-B2tdX6NT.mjs.map +1 -0
- package/dist/cyrb53-BTzxwvXR.cjs +1010 -0
- package/dist/cyrb53-DWYFRdWZ.d.mts +333 -0
- package/dist/cyrb53-DWYFRdWZ.d.mts.map +1 -0
- package/dist/cyrb53-FbY3n_2r.d.cts +333 -0
- package/dist/cyrb53-FbY3n_2r.d.cts.map +1 -0
- package/dist/index.cjs +18 -935
- package/dist/index.d.cts +2 -333
- package/dist/index.d.mts +2 -333
- package/dist/index.mjs +3 -920
- package/dist/node.cjs +6 -4
- package/dist/node.d.cts +63 -2
- package/dist/node.d.cts.map +1 -1
- package/dist/node.d.mts +63 -2
- package/dist/node.d.mts.map +1 -1
- package/dist/node.mjs +2 -2
- package/dist/{options-CgrZ2der.d.cts → options-B6mcYDIz.d.cts} +10 -1
- package/dist/options-B6mcYDIz.d.cts.map +1 -0
- package/dist/{options-BWcHrC-1.d.mts → options-T07dJfbz.d.mts} +10 -1
- package/dist/options-T07dJfbz.d.mts.map +1 -0
- package/dist/runtime.cjs +18 -0
- package/dist/runtime.d.cts +2 -0
- package/dist/runtime.d.mts +2 -0
- package/dist/runtime.mjs +3 -0
- package/dist/vite.cjs +48 -29
- package/dist/vite.d.cts +13 -3
- package/dist/vite.d.cts.map +1 -1
- package/dist/vite.d.mts +13 -3
- package/dist/vite.d.mts.map +1 -1
- package/dist/vite.mjs +46 -27
- package/dist/vite.mjs.map +1 -1
- package/package.json +23 -4
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/options-BWcHrC-1.d.mts.map +0 -1
- package/dist/options-CgrZ2der.d.cts.map +0 -1
- package/dist/schema-loader-CsabdnfI.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -30,6 +30,7 @@ pnpm add -D graphql typescript
|
|
|
30
30
|
|
|
31
31
|
For advanced usage (Subscription, directives, GraphQL mapping), see:
|
|
32
32
|
|
|
33
|
+
- [Configuration Guide](./docs/configuration.md) - **NEW: Configuration file support**
|
|
33
34
|
- [Advanced Usage](./docs/advanced-usage.md)
|
|
34
35
|
- [Runtime Integration Guide](./docs/runtime-integration.md)
|
|
35
36
|
- [Quickstart](./docs/quickstart.md)
|
|
@@ -40,6 +41,28 @@ For advanced usage (Subscription, directives, GraphQL mapping), see:
|
|
|
40
41
|
- [Troubleshooting](./docs/troubleshooting.md)
|
|
41
42
|
- [Generated Files Guide](./docs/generated-files.md)
|
|
42
43
|
|
|
44
|
+
### 0. Configuration File (Optional)
|
|
45
|
+
|
|
46
|
+
Create a `.typedgqlrc.toml` file in your project root:
|
|
47
|
+
|
|
48
|
+
```toml
|
|
49
|
+
# GraphQL schema source
|
|
50
|
+
schema = "./schema.graphql"
|
|
51
|
+
|
|
52
|
+
# Output directory for generated files
|
|
53
|
+
outputDir = "./src/__generated"
|
|
54
|
+
|
|
55
|
+
# Indentation (optional)
|
|
56
|
+
indent = " "
|
|
57
|
+
|
|
58
|
+
# Scalar type mapping (optional)
|
|
59
|
+
[scalarTypeMap]
|
|
60
|
+
DateTime = "string"
|
|
61
|
+
JSON = "JsonObject"
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
See [Configuration Guide](./docs/configuration.md) for all available options.
|
|
65
|
+
|
|
43
66
|
### 1. Vite Plugin (Recommended)
|
|
44
67
|
|
|
45
68
|
Configure `vite.config.ts`:
|
|
@@ -50,9 +73,12 @@ import { typedgql } from "@ptdgrp/typedgql/vite";
|
|
|
50
73
|
|
|
51
74
|
export default defineConfig({
|
|
52
75
|
plugins: [
|
|
76
|
+
// With inline options
|
|
53
77
|
typedgql({ schema: "./schema.graphql" }),
|
|
54
78
|
// or remote schema:
|
|
55
79
|
// typedgql({ schema: "http://localhost:4000/graphql" }),
|
|
80
|
+
// or use .typedgqlrc.toml config file:
|
|
81
|
+
// typedgql(),
|
|
56
82
|
],
|
|
57
83
|
});
|
|
58
84
|
```
|
|
@@ -62,16 +88,43 @@ Codegen runs automatically when Vite starts, and re-runs when the schema changes
|
|
|
62
88
|
### 2. Manual Generation in Node
|
|
63
89
|
|
|
64
90
|
```ts
|
|
65
|
-
import { Generator, loadLocalSchema } from "@ptdgrp/typedgql/node";
|
|
91
|
+
import { Generator, loadLocalSchema, loadConfig } from "@ptdgrp/typedgql/node";
|
|
66
92
|
|
|
93
|
+
// Option 1: Use configuration file
|
|
94
|
+
const config = await loadConfig();
|
|
95
|
+
const generator = new Generator({
|
|
96
|
+
...config,
|
|
97
|
+
schemaLoader: () => loadLocalSchema(config.schema),
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
// Option 2: Programmatic configuration
|
|
67
101
|
const generator = new Generator({
|
|
68
102
|
schemaLoader: () => loadLocalSchema("./schema.graphql"),
|
|
103
|
+
targetDir: "./src/__generated",
|
|
69
104
|
});
|
|
70
105
|
|
|
71
106
|
await generator.generate();
|
|
72
107
|
```
|
|
73
108
|
|
|
74
|
-
### 3.
|
|
109
|
+
### 3. CLI Tool
|
|
110
|
+
|
|
111
|
+
If you have a `.typedgqlrc.toml` configuration file, you can use the CLI:
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
# Run code generation
|
|
115
|
+
npx typedgql
|
|
116
|
+
|
|
117
|
+
# Or add to package.json scripts
|
|
118
|
+
{
|
|
119
|
+
"scripts": {
|
|
120
|
+
"codegen": "typedgql"
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
The CLI will automatically read your `.typedgqlrc.toml` configuration and generate types accordingly.
|
|
126
|
+
|
|
127
|
+
### 4. Runtime Execution (Basic Example)
|
|
75
128
|
|
|
76
129
|
```ts
|
|
77
130
|
import { G, execute, setGraphQLExecutor } from "@ptdgrp/typedgql";
|
package/README.zh-CN.md
CHANGED
|
@@ -22,6 +22,7 @@ pnpm add -D graphql typescript
|
|
|
22
22
|
|
|
23
23
|
进阶内容(Subscription、指令、GraphQL 对照)见:
|
|
24
24
|
|
|
25
|
+
- [配置指南(英文)](./docs/configuration.md) - **新增:配置文件支持**
|
|
25
26
|
- [typedgql 进阶用法(中文)](./docs/advanced-usage.zh-CN.md)
|
|
26
27
|
- [typedgql 运行时接入指南(中文)](./docs/runtime-integration.zh-CN.md)
|
|
27
28
|
- [typedgql Quickstart(英文)](./docs/quickstart.md)
|
|
@@ -32,6 +33,28 @@ pnpm add -D graphql typescript
|
|
|
32
33
|
- [typedgql 常见问题(英文)](./docs/troubleshooting.md)
|
|
33
34
|
- [typedgql 生成文件说明(英文)](./docs/generated-files.md)
|
|
34
35
|
|
|
36
|
+
### 0. 配置文件(可选)
|
|
37
|
+
|
|
38
|
+
在项目根目录创建 `.typedgqlrc.toml` 文件:
|
|
39
|
+
|
|
40
|
+
```toml
|
|
41
|
+
# GraphQL schema 源
|
|
42
|
+
schema = "./schema.graphql"
|
|
43
|
+
|
|
44
|
+
# 生成文件的输出目录(可选)
|
|
45
|
+
outputDir = "./src/__generated"
|
|
46
|
+
|
|
47
|
+
# 缩进(可选)
|
|
48
|
+
indent = " "
|
|
49
|
+
|
|
50
|
+
# 标量类型映射(可选)
|
|
51
|
+
[scalarTypeMap]
|
|
52
|
+
DateTime = "string"
|
|
53
|
+
JSON = "JsonObject"
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
查看[配置指南](./docs/configuration.md)了解所有可用选项。
|
|
57
|
+
|
|
35
58
|
### 1. Vite 插件方式(推荐)
|
|
36
59
|
|
|
37
60
|
在 `vite.config.ts` 中配置:
|
|
@@ -42,9 +65,12 @@ import { typedgql } from "@ptdgrp/typedgql/vite";
|
|
|
42
65
|
|
|
43
66
|
export default defineConfig({
|
|
44
67
|
plugins: [
|
|
68
|
+
// 使用内联选项
|
|
45
69
|
typedgql({ schema: "./schema.graphql" }),
|
|
46
70
|
// 或远程 schema:
|
|
47
71
|
// typedgql({ schema: "http://localhost:4000/graphql" }),
|
|
72
|
+
// 或使用 .typedgqlrc.toml 配置文件:
|
|
73
|
+
// typedgql(),
|
|
48
74
|
],
|
|
49
75
|
});
|
|
50
76
|
```
|
|
@@ -54,16 +80,43 @@ export default defineConfig({
|
|
|
54
80
|
### 2. Node 手动生成
|
|
55
81
|
|
|
56
82
|
```ts
|
|
57
|
-
import { Generator, loadLocalSchema } from "@ptdgrp/typedgql/node";
|
|
83
|
+
import { Generator, loadLocalSchema, loadConfig } from "@ptdgrp/typedgql/node";
|
|
58
84
|
|
|
85
|
+
// 方式 1: 使用配置文件
|
|
86
|
+
const config = await loadConfig();
|
|
87
|
+
const generator = new Generator({
|
|
88
|
+
...config,
|
|
89
|
+
schemaLoader: () => loadLocalSchema(config.schema),
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// 方式 2: 编程式配置
|
|
59
93
|
const generator = new Generator({
|
|
60
94
|
schemaLoader: () => loadLocalSchema("./schema.graphql"),
|
|
95
|
+
targetDir: "./src/__generated",
|
|
61
96
|
});
|
|
62
97
|
|
|
63
98
|
await generator.generate();
|
|
64
99
|
```
|
|
65
100
|
|
|
66
|
-
### 3.
|
|
101
|
+
### 3. CLI 命令行工具
|
|
102
|
+
|
|
103
|
+
如果你有 `.typedgqlrc.toml` 配置文件,可以使用 CLI:
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
# 运行代码生成
|
|
107
|
+
npx typedgql
|
|
108
|
+
|
|
109
|
+
# 或添加到 package.json scripts
|
|
110
|
+
{
|
|
111
|
+
"scripts": {
|
|
112
|
+
"codegen": "typedgql"
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
CLI 会自动读取 `.typedgqlrc.toml` 配置并生成类型。
|
|
118
|
+
|
|
119
|
+
### 4. 运行时执行(基础示例)
|
|
67
120
|
|
|
68
121
|
```ts
|
|
69
122
|
import { G, execute, setGraphQLExecutor } from "@ptdgrp/typedgql";
|
|
@@ -84,7 +137,7 @@ const selection = G.query((q) =>
|
|
|
84
137
|
const data = await execute(selection);
|
|
85
138
|
```
|
|
86
139
|
|
|
87
|
-
###
|
|
140
|
+
### 5. 带变量查询(推荐写法)
|
|
88
141
|
|
|
89
142
|
`selection` 与变量传值解耦:selection 可复用,变量在执行时传入。
|
|
90
143
|
|
|
@@ -98,7 +151,7 @@ const data = await execute(selection, {
|
|
|
98
151
|
});
|
|
99
152
|
```
|
|
100
153
|
|
|
101
|
-
###
|
|
154
|
+
### 6. 显式变量占位(可选)
|
|
102
155
|
|
|
103
156
|
```ts
|
|
104
157
|
import { G, execute, ParameterRef } from "@ptdgrp/typedgql";
|
package/dist/cli.cjs
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const require_config_loader = require('./config-loader-Bxj44SGD.cjs');
|
|
3
|
+
|
|
4
|
+
//#region src/cli.ts
|
|
5
|
+
/**
|
|
6
|
+
* TypedGQL CLI
|
|
7
|
+
*
|
|
8
|
+
* Simple command-line tool to generate TypeScript types from GraphQL schema
|
|
9
|
+
* using configuration from .typedgqlrc.toml
|
|
10
|
+
*/
|
|
11
|
+
const isRemote = (schema) => {
|
|
12
|
+
return /^https?:\/\//.test(schema);
|
|
13
|
+
};
|
|
14
|
+
async function main() {
|
|
15
|
+
try {
|
|
16
|
+
console.log("[typedgql] Loading configuration from .typedgqlrc.toml...");
|
|
17
|
+
const config = await require_config_loader.loadConfig();
|
|
18
|
+
if (!config) {
|
|
19
|
+
console.error("[typedgql] Error: No .typedgqlrc.toml configuration file found.\nPlease create a .typedgqlrc.toml file in your project root.\nSee: https://github.com/tonitrnel/typedgql#configuration");
|
|
20
|
+
process.exit(1);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (!config.schema) {
|
|
24
|
+
console.error("[typedgql] Error: 'schema' option is required in .typedgqlrc.toml\nPlease specify a schema source:\n schema = \"./schema.graphql\" # Local file\n schema = \"http://localhost:4000/graphql\" # Remote endpoint");
|
|
25
|
+
process.exit(1);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
console.log(`[typedgql] Schema source: ${config.schema}`);
|
|
29
|
+
if (config.targetDir || config.outputDir) console.log(`[typedgql] Output directory: ${config.targetDir || config.outputDir}`);
|
|
30
|
+
const schemaLoader = isRemote(config.schema) ? () => require_config_loader.loadRemoteSchema(config.schema, config.schemaHeaders) : () => require_config_loader.loadLocalSchema(config.schema);
|
|
31
|
+
const generator = new require_config_loader.Generator({
|
|
32
|
+
...config,
|
|
33
|
+
schemaLoader
|
|
34
|
+
});
|
|
35
|
+
console.log("[typedgql] Generating TypeScript types...");
|
|
36
|
+
await generator.generate();
|
|
37
|
+
console.log("[typedgql] ✓ Generation complete!");
|
|
38
|
+
process.exit(0);
|
|
39
|
+
} catch (error) {
|
|
40
|
+
console.error("[typedgql] Error:", error.message);
|
|
41
|
+
if (process.env.DEBUG) console.error(error.stack);
|
|
42
|
+
process.exit(1);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
main();
|
|
46
|
+
|
|
47
|
+
//#endregion
|
package/dist/cli.d.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/cli.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/cli.mjs
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { a as Generator, i as loadRemoteSchema, r as loadLocalSchema, t as loadConfig } from "./config-loader-DZ7d_CWR.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/cli.ts
|
|
5
|
+
/**
|
|
6
|
+
* TypedGQL CLI
|
|
7
|
+
*
|
|
8
|
+
* Simple command-line tool to generate TypeScript types from GraphQL schema
|
|
9
|
+
* using configuration from .typedgqlrc.toml
|
|
10
|
+
*/
|
|
11
|
+
const isRemote = (schema) => {
|
|
12
|
+
return /^https?:\/\//.test(schema);
|
|
13
|
+
};
|
|
14
|
+
async function main() {
|
|
15
|
+
try {
|
|
16
|
+
console.log("[typedgql] Loading configuration from .typedgqlrc.toml...");
|
|
17
|
+
const config = await loadConfig();
|
|
18
|
+
if (!config) {
|
|
19
|
+
console.error("[typedgql] Error: No .typedgqlrc.toml configuration file found.\nPlease create a .typedgqlrc.toml file in your project root.\nSee: https://github.com/tonitrnel/typedgql#configuration");
|
|
20
|
+
process.exit(1);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (!config.schema) {
|
|
24
|
+
console.error("[typedgql] Error: 'schema' option is required in .typedgqlrc.toml\nPlease specify a schema source:\n schema = \"./schema.graphql\" # Local file\n schema = \"http://localhost:4000/graphql\" # Remote endpoint");
|
|
25
|
+
process.exit(1);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
console.log(`[typedgql] Schema source: ${config.schema}`);
|
|
29
|
+
if (config.targetDir || config.outputDir) console.log(`[typedgql] Output directory: ${config.targetDir || config.outputDir}`);
|
|
30
|
+
const schemaLoader = isRemote(config.schema) ? () => loadRemoteSchema(config.schema, config.schemaHeaders) : () => loadLocalSchema(config.schema);
|
|
31
|
+
const generator = new Generator({
|
|
32
|
+
...config,
|
|
33
|
+
schemaLoader
|
|
34
|
+
});
|
|
35
|
+
console.log("[typedgql] Generating TypeScript types...");
|
|
36
|
+
await generator.generate();
|
|
37
|
+
console.log("[typedgql] ✓ Generation complete!");
|
|
38
|
+
process.exit(0);
|
|
39
|
+
} catch (error) {
|
|
40
|
+
console.error("[typedgql] Error:", error.message);
|
|
41
|
+
if (process.env.DEBUG) console.error(error.stack);
|
|
42
|
+
process.exit(1);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
main();
|
|
46
|
+
|
|
47
|
+
//#endregion
|
|
48
|
+
export { };
|
|
49
|
+
//# sourceMappingURL=cli.mjs.map
|
package/dist/cli.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.mjs","names":[],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n\n/**\n * TypedGQL CLI\n * \n * Simple command-line tool to generate TypeScript types from GraphQL schema\n * using configuration from .typedgqlrc.toml\n */\n\nimport { Generator } from \"./codegen/generator\";\nimport { loadConfig } from \"./codegen/config-loader\";\nimport { loadLocalSchema, loadRemoteSchema } from \"./codegen/schema-loader\";\n\nconst isRemote = (schema: string): boolean => {\n return /^https?:\\/\\//.test(schema);\n};\n\nasync function main() {\n try {\n console.log(\"[typedgql] Loading configuration from .typedgqlrc.toml...\");\n \n // Load configuration file\n const config = await loadConfig();\n \n if (!config) {\n console.error(\n \"[typedgql] Error: No .typedgqlrc.toml configuration file found.\\n\" +\n \"Please create a .typedgqlrc.toml file in your project root.\\n\" +\n \"See: https://github.com/tonitrnel/typedgql#configuration\"\n );\n process.exit(1);\n return;\n }\n\n if (!config.schema) {\n console.error(\n \"[typedgql] Error: 'schema' option is required in .typedgqlrc.toml\\n\" +\n \"Please specify a schema source:\\n\" +\n ' schema = \"./schema.graphql\" # Local file\\n' +\n ' schema = \"http://localhost:4000/graphql\" # Remote endpoint'\n );\n process.exit(1);\n return;\n }\n\n console.log(`[typedgql] Schema source: ${config.schema}`);\n \n if (config.targetDir || config.outputDir) {\n console.log(`[typedgql] Output directory: ${config.targetDir || config.outputDir}`);\n }\n\n // Create schema loader\n const schemaLoader = isRemote(config.schema)\n ? () => loadRemoteSchema(config.schema!, config.schemaHeaders)\n : () => loadLocalSchema(config.schema!);\n\n // Create generator\n const generator = new Generator({\n ...config,\n schemaLoader,\n });\n\n console.log(\"[typedgql] Generating TypeScript types...\");\n \n // Run generation\n await generator.generate();\n\n console.log(\"[typedgql] ✓ Generation complete!\");\n process.exit(0);\n } catch (error) {\n console.error(\"[typedgql] Error:\", (error as Error).message);\n if (process.env.DEBUG) {\n console.error((error as Error).stack);\n }\n process.exit(1);\n }\n}\n\n// Run CLI\nmain();\n"],"mappings":";;;;;;;;;;AAaA,MAAM,YAAY,WAA4B;AAC5C,QAAO,eAAe,KAAK,OAAO;;AAGpC,eAAe,OAAO;AACpB,KAAI;AACF,UAAQ,IAAI,4DAA4D;EAGxE,MAAM,SAAS,MAAM,YAAY;AAEjC,MAAI,CAAC,QAAQ;AACX,WAAQ,MACN,yLAGD;AACD,WAAQ,KAAK,EAAE;AACf;;AAGF,MAAI,CAAC,OAAO,QAAQ;AAClB,WAAQ,MACN,qNAID;AACD,WAAQ,KAAK,EAAE;AACf;;AAGF,UAAQ,IAAI,6BAA6B,OAAO,SAAS;AAEzD,MAAI,OAAO,aAAa,OAAO,UAC7B,SAAQ,IAAI,gCAAgC,OAAO,aAAa,OAAO,YAAY;EAIrF,MAAM,eAAe,SAAS,OAAO,OAAO,SAClC,iBAAiB,OAAO,QAAS,OAAO,cAAc,SACtD,gBAAgB,OAAO,OAAQ;EAGzC,MAAM,YAAY,IAAI,UAAU;GAC9B,GAAG;GACH;GACD,CAAC;AAEF,UAAQ,IAAI,4CAA4C;AAGxD,QAAM,UAAU,UAAU;AAE1B,UAAQ,IAAI,oCAAoC;AAChD,UAAQ,KAAK,EAAE;UACR,OAAO;AACd,UAAQ,MAAM,qBAAsB,MAAgB,QAAQ;AAC5D,MAAI,QAAQ,IAAI,MACd,SAAQ,MAAO,MAAgB,MAAM;AAEvC,UAAQ,KAAK,EAAE;;;AAKnB,MAAM"}
|