@supacloud/compiler 0.12.0 → 0.13.0

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 CHANGED
@@ -9,6 +9,87 @@ SupaCloud 应用静态编译器:读取 `@supacloud/app` 装饰器元数据的
9
9
 
10
10
  本包不依赖 `@supacloud/app`:AST 只按装饰器名匹配(`Module`/`Injectable`/`Inject`/`Command`/`Query`/`Controller`/`Get`/`Post`/`Put`/`Patch`/`Delete`/`defineModule`/`InjectionToken`),不校验 import 来源。
11
11
 
12
+ ## Recommended GraphQL Query Contracts
13
+
14
+ **Database First is the only server-schema model.** Drizzle and SQL declarations
15
+ are migrated to PostgreSQL; `pg_graphql` reflects the actual database, and
16
+ `graphql-schema` exports the intended role's snapshot. Author queries/fragments,
17
+ not GraphQL resolver classes or a separate server SDL. `graphql.schema` accepts
18
+ only local `.graphql`, `.gql` or `.json` snapshots; executable sources, URLs and
19
+ schema-authoring options such as `autoSchemaFile`, `typePaths`, `resolvers` or
20
+ `mode` are rejected. Snapshot formats and TypedDocumentNode output are not
21
+ alternative authoring modes.
22
+
23
+ Do not edit exported snapshots. Change database declarations, apply migrations,
24
+ export again and compile. Offline compilation cannot attest a snapshot's origin;
25
+ `graphql-schema --check` against the intended database detects local/remote drift.
26
+ The starter's synthetic SDL is solely an offline test fixture, not a deployed
27
+ schema. Replace it with a database export before integration.
28
+
29
+ New `supacloud app init` projects preconfigure GraphQL query contracts and include
30
+ an offline example. Existing REST, Command-only and background-task projects
31
+ remain unchanged: general App/CLI configuration and `compileProject(options)`
32
+ only enable this pipeline when `graphql` is explicitly configured. Enabled
33
+ contracts always reject invalid queries and missing schemas, even with
34
+ `strict: false` or `--no-strict`. Choosing `graphql: false` (or `--no-graphql` for
35
+ one compiler run) disables adoption, not just validation of individual queries.
36
+ The platform extension is still opt-in; compilation changes no database grants,
37
+ extensions or production introspection settings.
38
+
39
+ ```ts
40
+ export default defineSupacloudConfig({
41
+ root: "src",
42
+ graphql: { schema: "graphql/schema.graphql" },
43
+ });
44
+ ```
45
+
46
+ The schema path is configuration-relative, query globs are source-root-relative.
47
+ Normal `compile`, `check`, `dev` and `context` handle the local snapshot and
48
+ queries offline. Invalid fields/variables, unnamed operations, mutations and
49
+ subscriptions produce structured diagnostics; failures preserve working output.
50
+ GraphQL.js and GraphQL Code Generator own parsing, validation and operation types.
51
+ Unknown custom scalars stay `unknown` unless explicitly mapped via `graphql.scalars`.
52
+
53
+ ```sh
54
+ supacloud-compiler graphql-schema --url https://your-project.example \
55
+ --key-env SUPACLOUD_PUBLISHABLE_KEY --token-env APP_USER_ACCESS_TOKEN
56
+ supacloud-compiler compile
57
+ supacloud-compiler check --json
58
+ ```
59
+
60
+ Export is explicit and requires introspection already enabled in the selected
61
+ development project. Flags name environment variables, not secrets. Use the
62
+ intended caller role, never a privileged service-role schema for browser queries.
63
+ After migrations, use the same export command with `--check --json` to detect
64
+ remote schema drift without overwriting the local snapshot (exit 1 on drift).
65
+ Refresh intentionally, then run compile/check and the application's typecheck
66
+ and role/RLS tests. This remote gate requires development introspection; offline
67
+ compilation does not require production introspection.
68
+
69
+ Set `graphql.typedDocuments: true` to additionally generate
70
+ `graphql.documents.ts` using the standard TypedDocumentNode Codegen plugin.
71
+ Consumers of that optional file must install `@graphql-typed-document-node/core`;
72
+ it provides `ResultOf` and `VariablesOf` for operation-level inference. The default
73
+ fetch client still needs no GraphQL runtime dependency.
74
+
75
+ ```ts
76
+ import { createGraphqlClient } from "./generated/graphql";
77
+ const queries = createGraphqlClient({
78
+ url: projectUrl,
79
+ publishableKey,
80
+ getAccessToken: readCurrentUserToken,
81
+ });
82
+ const result = await queries.ReviewList({ first: 20 });
83
+ ```
84
+
85
+ Method names and types come from named operations. The generated client is
86
+ dependency-free and refreshes identity per request; `getSdk(requester)` integrates
87
+ an existing transport. It rejects HTTP errors, GraphQL errors and malformed
88
+ response envelopes, but does not runtime-decode selected field values.
89
+ `graphql.manifest.json` records query locations and the schema hash; context packs
90
+ include colocated queries. RLS/grants, real database acceptance and query resource
91
+ limits remain deployment responsibilities. Business writes stay in Commands.
92
+
12
93
  ## 安装
13
94
 
14
95
  ```bash
@@ -217,7 +298,7 @@ supacloud-compiler check --root ./app --out ./app/generated --strict
217
298
  supacloud-compiler dev --root . --out ./generated
218
299
  ```
219
300
 
220
- 开发模式默认对源码变化做 100ms 防抖,并只监听 TypeScript 文件。编译器会复用进程内的源码快照:相同输入直接命中缓存;只改动普通实现文件时复用既有依赖图和生成物;只有 SupaCloud 元数据、模块声明或依赖相关文件变化时才重建图。编译失败时不会覆盖最后一次成功的 `application.ts` 和 `app.manifest.json`;修复错误后会自动生成新产物。`--debounce <ms>` 可调整防抖时间。
301
+ 开发模式默认对源码变化做 100ms 防抖,监听 TypeScript 文件;启用 GraphQL 后,还监听查询文件和配置的 Schema 快照。编译器会复用进程内的源码快照:相同输入直接命中缓存;只改动普通实现文件时复用既有依赖图和生成物;只有 SupaCloud 元数据、模块声明或依赖相关文件变化时才重建图。编译失败时不会覆盖最后一次成功的 `application.ts` 和 `app.manifest.json`;修复错误后会自动生成新产物。`--debounce <ms>` 可调整防抖时间。
221
302
 
222
303
  ## 图谱与诊断
223
304