@ptdgrp/typedgql 1.0.0-beta.15 → 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.
Files changed (49) hide show
  1. package/README.md +64 -4
  2. package/README.zh-CN.md +64 -4
  3. package/dist/cli.cjs +47 -0
  4. package/dist/cli.d.cts +1 -0
  5. package/dist/cli.d.mts +1 -0
  6. package/dist/cli.mjs +49 -0
  7. package/dist/cli.mjs.map +1 -0
  8. package/dist/{schema-loader-DolAa42F.cjs → config-loader-Bxj44SGD.cjs} +349 -42
  9. package/dist/{schema-loader-vNpUWFmU.mjs → config-loader-DZ7d_CWR.mjs} +343 -48
  10. package/dist/config-loader-DZ7d_CWR.mjs.map +1 -0
  11. package/dist/cyrb53-B2tdX6NT.mjs +921 -0
  12. package/dist/cyrb53-B2tdX6NT.mjs.map +1 -0
  13. package/dist/cyrb53-BTzxwvXR.cjs +1010 -0
  14. package/dist/cyrb53-DWYFRdWZ.d.mts +333 -0
  15. package/dist/cyrb53-DWYFRdWZ.d.mts.map +1 -0
  16. package/dist/cyrb53-FbY3n_2r.d.cts +333 -0
  17. package/dist/cyrb53-FbY3n_2r.d.cts.map +1 -0
  18. package/dist/index.cjs +18 -935
  19. package/dist/index.d.cts +2 -333
  20. package/dist/index.d.mts +2 -333
  21. package/dist/index.mjs +3 -920
  22. package/dist/node.cjs +6 -4
  23. package/dist/node.d.cts +63 -2
  24. package/dist/node.d.cts.map +1 -1
  25. package/dist/node.d.mts +63 -2
  26. package/dist/node.d.mts.map +1 -1
  27. package/dist/node.mjs +2 -2
  28. package/dist/{options-CgrZ2der.d.cts → options-B6mcYDIz.d.cts} +10 -1
  29. package/dist/options-B6mcYDIz.d.cts.map +1 -0
  30. package/dist/{options-BWcHrC-1.d.mts → options-T07dJfbz.d.mts} +10 -1
  31. package/dist/options-T07dJfbz.d.mts.map +1 -0
  32. package/dist/runtime.cjs +18 -0
  33. package/dist/runtime.d.cts +2 -0
  34. package/dist/runtime.d.mts +2 -0
  35. package/dist/runtime.mjs +3 -0
  36. package/dist/vite.cjs +68 -59
  37. package/dist/vite.d.cts +11 -17
  38. package/dist/vite.d.cts.map +1 -1
  39. package/dist/vite.d.mts +11 -17
  40. package/dist/vite.d.mts.map +1 -1
  41. package/dist/vite.mjs +66 -57
  42. package/dist/vite.mjs.map +1 -1
  43. package/package.json +23 -4
  44. package/dist/index.d.cts.map +0 -1
  45. package/dist/index.d.mts.map +0 -1
  46. package/dist/index.mjs.map +0 -1
  47. package/dist/options-BWcHrC-1.d.mts.map +0 -1
  48. package/dist/options-CgrZ2der.d.cts.map +0 -1
  49. package/dist/schema-loader-vNpUWFmU.mjs.map +0 -1
package/README.md CHANGED
@@ -30,8 +30,38 @@ pnpm add -D graphql typescript
30
30
 
31
31
  For advanced usage (Subscription, directives, GraphQL mapping), see:
32
32
 
33
- - [Advanced Usage (Chinese)](./docs/advanced-usage.zh-CN.md)
34
- - [Runtime Integration Guide (Chinese)](./docs/runtime-integration.zh-CN.md)
33
+ - [Configuration Guide](./docs/configuration.md) - **NEW: Configuration file support**
34
+ - [Advanced Usage](./docs/advanced-usage.md)
35
+ - [Runtime Integration Guide](./docs/runtime-integration.md)
36
+ - [Quickstart](./docs/quickstart.md)
37
+ - [API Map](./docs/api-map.md)
38
+ - [Variables Semantics](./docs/variables.md)
39
+ - [Fragments Guide](./docs/fragments.md)
40
+ - [Runtime Integration Guide](./docs/runtime-integration.md)
41
+ - [Troubleshooting](./docs/troubleshooting.md)
42
+ - [Generated Files Guide](./docs/generated-files.md)
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.
35
65
 
36
66
  ### 1. Vite Plugin (Recommended)
37
67
 
@@ -43,9 +73,12 @@ import { typedgql } from "@ptdgrp/typedgql/vite";
43
73
 
44
74
  export default defineConfig({
45
75
  plugins: [
76
+ // With inline options
46
77
  typedgql({ schema: "./schema.graphql" }),
47
78
  // or remote schema:
48
79
  // typedgql({ schema: "http://localhost:4000/graphql" }),
80
+ // or use .typedgqlrc.toml config file:
81
+ // typedgql(),
49
82
  ],
50
83
  });
51
84
  ```
@@ -55,16 +88,43 @@ Codegen runs automatically when Vite starts, and re-runs when the schema changes
55
88
  ### 2. Manual Generation in Node
56
89
 
57
90
  ```ts
58
- import { Generator, loadLocalSchema } from "@ptdgrp/typedgql/node";
91
+ import { Generator, loadLocalSchema, loadConfig } from "@ptdgrp/typedgql/node";
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
+ });
59
99
 
100
+ // Option 2: Programmatic configuration
60
101
  const generator = new Generator({
61
102
  schemaLoader: () => loadLocalSchema("./schema.graphql"),
103
+ targetDir: "./src/__generated",
62
104
  });
63
105
 
64
106
  await generator.generate();
65
107
  ```
66
108
 
67
- ### 3. Runtime Execution (Basic Example)
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)
68
128
 
69
129
  ```ts
70
130
  import { G, execute, setGraphQLExecutor } from "@ptdgrp/typedgql";
package/README.zh-CN.md CHANGED
@@ -22,8 +22,38 @@ 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)
28
+ - [typedgql Quickstart(英文)](./docs/quickstart.md)
29
+ - [typedgql API 地图(英文)](./docs/api-map.md)
30
+ - [typedgql 参数语义(英文)](./docs/variables.md)
31
+ - [typedgql Fragment 指南(英文)](./docs/fragments.md)
32
+ - [typedgql 运行时接入(英文)](./docs/runtime-integration.md)
33
+ - [typedgql 常见问题(英文)](./docs/troubleshooting.md)
34
+ - [typedgql 生成文件说明(英文)](./docs/generated-files.md)
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)了解所有可用选项。
27
57
 
28
58
  ### 1. Vite 插件方式(推荐)
29
59
 
@@ -35,9 +65,12 @@ import { typedgql } from "@ptdgrp/typedgql/vite";
35
65
 
36
66
  export default defineConfig({
37
67
  plugins: [
68
+ // 使用内联选项
38
69
  typedgql({ schema: "./schema.graphql" }),
39
70
  // 或远程 schema:
40
71
  // typedgql({ schema: "http://localhost:4000/graphql" }),
72
+ // 或使用 .typedgqlrc.toml 配置文件:
73
+ // typedgql(),
41
74
  ],
42
75
  });
43
76
  ```
@@ -47,16 +80,43 @@ export default defineConfig({
47
80
  ### 2. Node 手动生成
48
81
 
49
82
  ```ts
50
- import { Generator, loadLocalSchema } from "@ptdgrp/typedgql/node";
83
+ import { Generator, loadLocalSchema, loadConfig } from "@ptdgrp/typedgql/node";
51
84
 
85
+ // 方式 1: 使用配置文件
86
+ const config = await loadConfig();
87
+ const generator = new Generator({
88
+ ...config,
89
+ schemaLoader: () => loadLocalSchema(config.schema),
90
+ });
91
+
92
+ // 方式 2: 编程式配置
52
93
  const generator = new Generator({
53
94
  schemaLoader: () => loadLocalSchema("./schema.graphql"),
95
+ targetDir: "./src/__generated",
54
96
  });
55
97
 
56
98
  await generator.generate();
57
99
  ```
58
100
 
59
- ### 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. 运行时执行(基础示例)
60
120
 
61
121
  ```ts
62
122
  import { G, execute, setGraphQLExecutor } from "@ptdgrp/typedgql";
@@ -77,7 +137,7 @@ const selection = G.query((q) =>
77
137
  const data = await execute(selection);
78
138
  ```
79
139
 
80
- ### 4. 带变量查询(推荐写法)
140
+ ### 5. 带变量查询(推荐写法)
81
141
 
82
142
  `selection` 与变量传值解耦:selection 可复用,变量在执行时传入。
83
143
 
@@ -91,7 +151,7 @@ const data = await execute(selection, {
91
151
  });
92
152
  ```
93
153
 
94
- ### 5. 显式变量占位(可选)
154
+ ### 6. 显式变量占位(可选)
95
155
 
96
156
  ```ts
97
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
@@ -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"}