@ptdgrp/typedgql 1.0.0-beta.15 → 1.0.0-beta.16
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 +9 -2
- package/README.zh-CN.md +7 -0
- package/dist/node.cjs +1 -1
- package/dist/node.mjs +1 -1
- package/dist/{schema-loader-DolAa42F.cjs → schema-loader-BIP51DZO.cjs} +1 -1
- package/dist/{schema-loader-vNpUWFmU.mjs → schema-loader-CsabdnfI.mjs} +2 -2
- package/dist/{schema-loader-vNpUWFmU.mjs.map → schema-loader-CsabdnfI.mjs.map} +1 -1
- package/dist/vite.cjs +26 -36
- package/dist/vite.d.cts +0 -16
- package/dist/vite.d.cts.map +1 -1
- package/dist/vite.d.mts +0 -16
- package/dist/vite.d.mts.map +1 -1
- package/dist/vite.mjs +26 -36
- package/dist/vite.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -30,8 +30,15 @@ pnpm add -D graphql typescript
|
|
|
30
30
|
|
|
31
31
|
For advanced usage (Subscription, directives, GraphQL mapping), see:
|
|
32
32
|
|
|
33
|
-
- [Advanced Usage
|
|
34
|
-
- [Runtime Integration Guide
|
|
33
|
+
- [Advanced Usage](./docs/advanced-usage.md)
|
|
34
|
+
- [Runtime Integration Guide](./docs/runtime-integration.md)
|
|
35
|
+
- [Quickstart](./docs/quickstart.md)
|
|
36
|
+
- [API Map](./docs/api-map.md)
|
|
37
|
+
- [Variables Semantics](./docs/variables.md)
|
|
38
|
+
- [Fragments Guide](./docs/fragments.md)
|
|
39
|
+
- [Runtime Integration Guide](./docs/runtime-integration.md)
|
|
40
|
+
- [Troubleshooting](./docs/troubleshooting.md)
|
|
41
|
+
- [Generated Files Guide](./docs/generated-files.md)
|
|
35
42
|
|
|
36
43
|
### 1. Vite Plugin (Recommended)
|
|
37
44
|
|
package/README.zh-CN.md
CHANGED
|
@@ -24,6 +24,13 @@ pnpm add -D graphql typescript
|
|
|
24
24
|
|
|
25
25
|
- [typedgql 进阶用法(中文)](./docs/advanced-usage.zh-CN.md)
|
|
26
26
|
- [typedgql 运行时接入指南(中文)](./docs/runtime-integration.zh-CN.md)
|
|
27
|
+
- [typedgql Quickstart(英文)](./docs/quickstart.md)
|
|
28
|
+
- [typedgql API 地图(英文)](./docs/api-map.md)
|
|
29
|
+
- [typedgql 参数语义(英文)](./docs/variables.md)
|
|
30
|
+
- [typedgql Fragment 指南(英文)](./docs/fragments.md)
|
|
31
|
+
- [typedgql 运行时接入(英文)](./docs/runtime-integration.md)
|
|
32
|
+
- [typedgql 常见问题(英文)](./docs/troubleshooting.md)
|
|
33
|
+
- [typedgql 生成文件说明(英文)](./docs/generated-files.md)
|
|
27
34
|
|
|
28
35
|
### 1. Vite 插件方式(推荐)
|
|
29
36
|
|
package/dist/node.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_schema_loader = require('./schema-loader-
|
|
2
|
+
const require_schema_loader = require('./schema-loader-BIP51DZO.cjs');
|
|
3
3
|
|
|
4
4
|
exports.Generator = require_schema_loader.Generator;
|
|
5
5
|
exports.loadLocalSchema = require_schema_loader.loadLocalSchema;
|
package/dist/node.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { n as loadRemoteSchema, r as Generator, t as loadLocalSchema } from "./schema-loader-
|
|
1
|
+
import { n as loadRemoteSchema, r as Generator, t as loadLocalSchema } from "./schema-loader-CsabdnfI.mjs";
|
|
2
2
|
|
|
3
3
|
export { Generator, loadLocalSchema, loadRemoteSchema };
|
|
@@ -1607,7 +1607,7 @@ var EnumInputMetadataWriter = class EnumInputMetadataWriter extends Writer {
|
|
|
1607
1607
|
|
|
1608
1608
|
//#endregion
|
|
1609
1609
|
//#region \0raw:/home/runner/work/typedgql/typedgql/src/codegen/templates/async-runtime.template
|
|
1610
|
-
var async_runtime_default = "import type { Selection } from \"../dist/index.mjs\";\nimport { TextBuilder, runtimeOf } from \"../dist/index.mjs\";\n\nexport type GraphQLExecutor = (\n request: string,\n variables: Record<string, unknown>,\n) => Promise<unknown>;\n\nexport type GraphQLSubscriber = (\n request: string,\n variables: Record<string, unknown>,\n) => AsyncIterable<unknown> | Promise<AsyncIterable<unknown>>;\n\n// Set global fallback executor used by `execute(...)`.\nexport function setGraphQLExecutor(executor: GraphQLExecutor) {\n graphQLExecutor = executor;\n}\n\n// Set global fallback subscriber used by `subscribe(...)`.\nexport function setGraphQLSubscriber(subscriber: GraphQLSubscriber) {\n graphQLSubscriber = subscriber;\n}\nexport type Simplify<T> = SimplifyDepth<T>;\ntype Primitive = string | number | boolean | bigint | symbol | null | undefined;\ntype Dec = [0,0,1,2,3,4,5,6,7,8,9];\ntype GraphQLRawResponse = {\n readonly data?: unknown;\n readonly errors?: unknown;\n};\nexport type SimplifyDepth
|
|
1610
|
+
var async_runtime_default = "import type { Selection } from \"../dist/index.mjs\";\nimport { TextBuilder, runtimeOf } from \"../dist/index.mjs\";\n\nexport type GraphQLExecutor = (\n request: string,\n variables: Record<string, unknown>,\n) => Promise<unknown>;\n\nexport type GraphQLSubscriber = (\n request: string,\n variables: Record<string, unknown>,\n) => AsyncIterable<unknown> | Promise<AsyncIterable<unknown>>;\n\n// Set global fallback executor used by `execute(...)`.\nexport function setGraphQLExecutor(executor: GraphQLExecutor) {\n graphQLExecutor = executor;\n}\n\n// Set global fallback subscriber used by `subscribe(...)`.\nexport function setGraphQLSubscriber(subscriber: GraphQLSubscriber) {\n graphQLSubscriber = subscriber;\n}\nexport type Simplify<T> = SimplifyDepth<T>;\ntype Primitive = string | number | boolean | bigint | symbol | null | undefined;\ntype Dec = [0,0,1,2,3,4,5,6,7,8,9];\ntype IsEqual<A, B> =\n (<T>() => T extends A ? 1 : 2) extends\n (<T>() => T extends B ? 1 : 2)\n ? (<T>() => T extends B ? 1 : 2) extends\n (<T>() => T extends A ? 1 : 2)\n ? true\n : false\n : false;\ntype Includes<TItems extends readonly unknown[], TItem> =\n TItems extends readonly [infer Head, ...infer Tail]\n ? IsEqual<Head, TItem> extends true\n ? true\n : Includes<Tail, TItem>\n : false;\ntype GraphQLRawResponse = {\n readonly data?: unknown;\n readonly errors?: unknown;\n};\nexport type SimplifyDepth<\n T,\n D extends number = 5,\n Seen extends readonly unknown[] = [],\n> =\n D extends 0 ? T :\n T extends Primitive | Function ? T :\n Includes<Seen, T> extends true ? T :\n T extends readonly (infer U)[] ? readonly SimplifyDepth<U, Dec[D], [...Seen, T]>[] :\n T extends object ? { [K in keyof T]: SimplifyDepth<T[K], Dec[D], [...Seen, T]> } & {} :\n T;\n\nexport async function execute<\n TData extends object,\n TVariables extends Record<string, unknown>,\n>(\n selection: Selection<\"Query\" | \"Mutation\", TData, TVariables>,\n options?: {\n readonly operationName?: string;\n readonly variables?: TVariables;\n readonly executor?: GraphQLExecutor;\n },\n): Promise<Simplify<TData>> {\n // Per-call override has priority over the globally registered executor.\n const executor = options?.executor ?? graphQLExecutor;\n if (executor === undefined) {\n throw new Error(\n \"Executor not set. Call 'setGraphQLExecutor' first or pass executor in options.\",\n );\n }\n\n const request = buildRequest(selection, options?.operationName);\n const rawResponse = exceptNullValues(\n await executor(request, options?.variables ?? {}),\n ) as GraphQLRawResponse;\n // GraphQL transport errors are surfaced as exceptions.\n if (rawResponse.errors) {\n throw new GraphQLError(rawResponse.errors);\n }\n return rawResponse.data as unknown as Simplify<TData>;\n}\n\nexport async function* subscribe<\n TData extends object,\n TVariables extends Record<string, unknown>,\n>(\n selection: Selection<\"Subscription\", TData, TVariables>,\n options?: {\n readonly operationName?: string;\n readonly variables?: TVariables;\n readonly subscriber?: GraphQLSubscriber;\n },\n): AsyncIterable<Simplify<TData>> {\n // Per-call override has priority over the globally registered subscriber.\n const subscriber = options?.subscriber ?? graphQLSubscriber;\n if (subscriber === undefined) {\n throw new Error(\n \"Subscriber not set. Call 'setGraphQLSubscriber' first or pass subscriber in options.\",\n );\n }\n\n const request = buildRequest(selection, options?.operationName);\n const stream = await subscriber(request, options?.variables ?? {});\n // Stream payloads follow standard GraphQL response shape.\n for await (const payload of stream) {\n const rawResponse = exceptNullValues(payload) as GraphQLRawResponse;\n if (rawResponse.errors) {\n throw new GraphQLError(rawResponse.errors);\n }\n yield rawResponse.data as unknown as Simplify<TData>;\n }\n}\n\nexport interface Response<TData> {\n readonly data?: TData;\n readonly error?: Error;\n}\n\nexport class GraphQLError extends Error {\n readonly errors: readonly GraphQLSubError[];\n\n constructor(errors: unknown) {\n super();\n this.errors = normalizeGraphQLErrors(errors);\n }\n}\n\nexport interface GraphQLSubError {\n readonly message: string;\n readonly path: string[];\n}\n\nlet graphQLExecutor: GraphQLExecutor | undefined = undefined;\nlet graphQLSubscriber: GraphQLSubscriber | undefined = undefined;\n\nfunction normalizeGraphQLErrors(errors: unknown): readonly GraphQLSubError[] {\n if (!Array.isArray(errors)) {\n return [{ message: \"Unknown GraphQL error\", path: [] }];\n }\n return errors.map((item) => {\n if (!item || typeof item !== \"object\") {\n return { message: String(item), path: [] };\n }\n const rec = item as Record<string, unknown>;\n return {\n message: typeof rec.message === \"string\" ? rec.message : \"Unknown GraphQL error\",\n path: Array.isArray(rec.path)\n ? rec.path.filter((p): p is string => typeof p === \"string\")\n : [],\n };\n });\n}\n\n// Build GraphQL document from selection tree and inferred variable declarations.\nfunction buildRequest<\n TData extends object,\n TVariables extends Record<string, unknown>,\n>(\n selection: Selection<\"Query\" | \"Mutation\" | \"Subscription\", TData, TVariables>,\n operationName?: string,\n): string {\n const runtime = runtimeOf(selection);\n const writer = new TextBuilder();\n writer.text(`${runtime.schemaType.name.toLowerCase()} ${operationName ?? runtime.operationName ?? \"\"}`);\n if (runtime.variableTypeMap.size !== 0) {\n writer.scope(\n {\n type: \"arguments\",\n multiLines: runtime.variableTypeMap.size > 2,\n suffix: \" \",\n },\n () => {\n for (const [name, registration] of runtime.variableTypeMap) {\n writer.separator();\n writer.text(`$${name}: ${registration.typeName}`);\n }\n },\n );\n }\n writer.text(selection.toString());\n writer.text(selection.toFragmentString());\n return writer.toString();\n}\n\n// Convert all nullable fields to `undefined` for easier TS optional-field ergonomics.\nfunction exceptNullValues<T>(value: T): T {\n if (value == null) return undefined as any;\n if (typeof value !== \"object\") return value;\n if (Array.isArray(value)) {\n return value.map((el) => el == null ? undefined : exceptNullValues(el)) as any;\n }\n const out: any = {};\n for (const k in value) {\n const v = value[k];\n out[k] = v != null ? exceptNullValues(v) : undefined;\n }\n return out;\n}\n";
|
|
1611
1611
|
|
|
1612
1612
|
//#endregion
|
|
1613
1613
|
//#region src/codegen/scalar-type-declarations.ts
|
|
@@ -1579,7 +1579,7 @@ var EnumInputMetadataWriter = class EnumInputMetadataWriter extends Writer {
|
|
|
1579
1579
|
|
|
1580
1580
|
//#endregion
|
|
1581
1581
|
//#region \0raw:/home/runner/work/typedgql/typedgql/src/codegen/templates/async-runtime.template
|
|
1582
|
-
var async_runtime_default = "import type { Selection } from \"../dist/index.mjs\";\nimport { TextBuilder, runtimeOf } from \"../dist/index.mjs\";\n\nexport type GraphQLExecutor = (\n request: string,\n variables: Record<string, unknown>,\n) => Promise<unknown>;\n\nexport type GraphQLSubscriber = (\n request: string,\n variables: Record<string, unknown>,\n) => AsyncIterable<unknown> | Promise<AsyncIterable<unknown>>;\n\n// Set global fallback executor used by `execute(...)`.\nexport function setGraphQLExecutor(executor: GraphQLExecutor) {\n graphQLExecutor = executor;\n}\n\n// Set global fallback subscriber used by `subscribe(...)`.\nexport function setGraphQLSubscriber(subscriber: GraphQLSubscriber) {\n graphQLSubscriber = subscriber;\n}\nexport type Simplify<T> = SimplifyDepth<T>;\ntype Primitive = string | number | boolean | bigint | symbol | null | undefined;\ntype Dec = [0,0,1,2,3,4,5,6,7,8,9];\ntype GraphQLRawResponse = {\n readonly data?: unknown;\n readonly errors?: unknown;\n};\nexport type SimplifyDepth
|
|
1582
|
+
var async_runtime_default = "import type { Selection } from \"../dist/index.mjs\";\nimport { TextBuilder, runtimeOf } from \"../dist/index.mjs\";\n\nexport type GraphQLExecutor = (\n request: string,\n variables: Record<string, unknown>,\n) => Promise<unknown>;\n\nexport type GraphQLSubscriber = (\n request: string,\n variables: Record<string, unknown>,\n) => AsyncIterable<unknown> | Promise<AsyncIterable<unknown>>;\n\n// Set global fallback executor used by `execute(...)`.\nexport function setGraphQLExecutor(executor: GraphQLExecutor) {\n graphQLExecutor = executor;\n}\n\n// Set global fallback subscriber used by `subscribe(...)`.\nexport function setGraphQLSubscriber(subscriber: GraphQLSubscriber) {\n graphQLSubscriber = subscriber;\n}\nexport type Simplify<T> = SimplifyDepth<T>;\ntype Primitive = string | number | boolean | bigint | symbol | null | undefined;\ntype Dec = [0,0,1,2,3,4,5,6,7,8,9];\ntype IsEqual<A, B> =\n (<T>() => T extends A ? 1 : 2) extends\n (<T>() => T extends B ? 1 : 2)\n ? (<T>() => T extends B ? 1 : 2) extends\n (<T>() => T extends A ? 1 : 2)\n ? true\n : false\n : false;\ntype Includes<TItems extends readonly unknown[], TItem> =\n TItems extends readonly [infer Head, ...infer Tail]\n ? IsEqual<Head, TItem> extends true\n ? true\n : Includes<Tail, TItem>\n : false;\ntype GraphQLRawResponse = {\n readonly data?: unknown;\n readonly errors?: unknown;\n};\nexport type SimplifyDepth<\n T,\n D extends number = 5,\n Seen extends readonly unknown[] = [],\n> =\n D extends 0 ? T :\n T extends Primitive | Function ? T :\n Includes<Seen, T> extends true ? T :\n T extends readonly (infer U)[] ? readonly SimplifyDepth<U, Dec[D], [...Seen, T]>[] :\n T extends object ? { [K in keyof T]: SimplifyDepth<T[K], Dec[D], [...Seen, T]> } & {} :\n T;\n\nexport async function execute<\n TData extends object,\n TVariables extends Record<string, unknown>,\n>(\n selection: Selection<\"Query\" | \"Mutation\", TData, TVariables>,\n options?: {\n readonly operationName?: string;\n readonly variables?: TVariables;\n readonly executor?: GraphQLExecutor;\n },\n): Promise<Simplify<TData>> {\n // Per-call override has priority over the globally registered executor.\n const executor = options?.executor ?? graphQLExecutor;\n if (executor === undefined) {\n throw new Error(\n \"Executor not set. Call 'setGraphQLExecutor' first or pass executor in options.\",\n );\n }\n\n const request = buildRequest(selection, options?.operationName);\n const rawResponse = exceptNullValues(\n await executor(request, options?.variables ?? {}),\n ) as GraphQLRawResponse;\n // GraphQL transport errors are surfaced as exceptions.\n if (rawResponse.errors) {\n throw new GraphQLError(rawResponse.errors);\n }\n return rawResponse.data as unknown as Simplify<TData>;\n}\n\nexport async function* subscribe<\n TData extends object,\n TVariables extends Record<string, unknown>,\n>(\n selection: Selection<\"Subscription\", TData, TVariables>,\n options?: {\n readonly operationName?: string;\n readonly variables?: TVariables;\n readonly subscriber?: GraphQLSubscriber;\n },\n): AsyncIterable<Simplify<TData>> {\n // Per-call override has priority over the globally registered subscriber.\n const subscriber = options?.subscriber ?? graphQLSubscriber;\n if (subscriber === undefined) {\n throw new Error(\n \"Subscriber not set. Call 'setGraphQLSubscriber' first or pass subscriber in options.\",\n );\n }\n\n const request = buildRequest(selection, options?.operationName);\n const stream = await subscriber(request, options?.variables ?? {});\n // Stream payloads follow standard GraphQL response shape.\n for await (const payload of stream) {\n const rawResponse = exceptNullValues(payload) as GraphQLRawResponse;\n if (rawResponse.errors) {\n throw new GraphQLError(rawResponse.errors);\n }\n yield rawResponse.data as unknown as Simplify<TData>;\n }\n}\n\nexport interface Response<TData> {\n readonly data?: TData;\n readonly error?: Error;\n}\n\nexport class GraphQLError extends Error {\n readonly errors: readonly GraphQLSubError[];\n\n constructor(errors: unknown) {\n super();\n this.errors = normalizeGraphQLErrors(errors);\n }\n}\n\nexport interface GraphQLSubError {\n readonly message: string;\n readonly path: string[];\n}\n\nlet graphQLExecutor: GraphQLExecutor | undefined = undefined;\nlet graphQLSubscriber: GraphQLSubscriber | undefined = undefined;\n\nfunction normalizeGraphQLErrors(errors: unknown): readonly GraphQLSubError[] {\n if (!Array.isArray(errors)) {\n return [{ message: \"Unknown GraphQL error\", path: [] }];\n }\n return errors.map((item) => {\n if (!item || typeof item !== \"object\") {\n return { message: String(item), path: [] };\n }\n const rec = item as Record<string, unknown>;\n return {\n message: typeof rec.message === \"string\" ? rec.message : \"Unknown GraphQL error\",\n path: Array.isArray(rec.path)\n ? rec.path.filter((p): p is string => typeof p === \"string\")\n : [],\n };\n });\n}\n\n// Build GraphQL document from selection tree and inferred variable declarations.\nfunction buildRequest<\n TData extends object,\n TVariables extends Record<string, unknown>,\n>(\n selection: Selection<\"Query\" | \"Mutation\" | \"Subscription\", TData, TVariables>,\n operationName?: string,\n): string {\n const runtime = runtimeOf(selection);\n const writer = new TextBuilder();\n writer.text(`${runtime.schemaType.name.toLowerCase()} ${operationName ?? runtime.operationName ?? \"\"}`);\n if (runtime.variableTypeMap.size !== 0) {\n writer.scope(\n {\n type: \"arguments\",\n multiLines: runtime.variableTypeMap.size > 2,\n suffix: \" \",\n },\n () => {\n for (const [name, registration] of runtime.variableTypeMap) {\n writer.separator();\n writer.text(`$${name}: ${registration.typeName}`);\n }\n },\n );\n }\n writer.text(selection.toString());\n writer.text(selection.toFragmentString());\n return writer.toString();\n}\n\n// Convert all nullable fields to `undefined` for easier TS optional-field ergonomics.\nfunction exceptNullValues<T>(value: T): T {\n if (value == null) return undefined as any;\n if (typeof value !== \"object\") return value;\n if (Array.isArray(value)) {\n return value.map((el) => el == null ? undefined : exceptNullValues(el)) as any;\n }\n const out: any = {};\n for (const k in value) {\n const v = value[k];\n out[k] = v != null ? exceptNullValues(v) : undefined;\n }\n return out;\n}\n";
|
|
1583
1583
|
|
|
1584
1584
|
//#endregion
|
|
1585
1585
|
//#region src/codegen/scalar-type-declarations.ts
|
|
@@ -2027,4 +2027,4 @@ async function loadLocalSchema(location) {
|
|
|
2027
2027
|
|
|
2028
2028
|
//#endregion
|
|
2029
2029
|
export { loadRemoteSchema as n, Generator as r, loadLocalSchema as t };
|
|
2030
|
-
//# sourceMappingURL=schema-loader-
|
|
2030
|
+
//# sourceMappingURL=schema-loader-CsabdnfI.mjs.map
|