@openreachtech/hora-skills-ort-renchan 0.0.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/LICENSE +201 -0
- package/README.ja.md +135 -0
- package/README.md +135 -0
- package/dist/skills/hor-agent-loop/SKILL.md +123 -0
- package/dist/skills/hor-agent-loop/references/core.md +485 -0
- package/dist/skills/hor-agent-loop/references/graphql-integration.md +178 -0
- package/dist/skills/hor-agent-loop/references/renchan-job-integration.md +368 -0
- package/dist/skills/hor-agent-loop/references/testing.md +492 -0
- package/dist/skills/hor-ai-agent-structure/SKILL.md +403 -0
- package/dist/skills/hor-ai-agent-structure/references/loop-and-actions.md +100 -0
- package/dist/skills/hor-ai-prompt-document-store/SKILL.md +220 -0
- package/dist/skills/hor-ai-prompt-document-store/references/models-and-composition.md +156 -0
- package/dist/skills/hor-backend-testing/SKILL.md +118 -0
- package/dist/skills/hor-backend-testing/references/placement-and-ordering.md +89 -0
- package/dist/skills/hor-backend-testing/references/purity-and-mocks.md +82 -0
- package/dist/skills/hor-backend-testing/references/running-tests.md +186 -0
- package/dist/skills/hor-bank-id/SKILL.md +91 -0
- package/dist/skills/hor-build-e2e-test-environment/SKILL.md +609 -0
- package/dist/skills/hor-build-e2e-test-environment/references/compose-definition.md +368 -0
- package/dist/skills/hor-build-e2e-test-environment/references/edge-and-proxy.md +287 -0
- package/dist/skills/hor-build-e2e-test-environment/references/environment-and-ports.md +201 -0
- package/dist/skills/hor-build-e2e-test-environment/references/runner-and-lifecycle.md +330 -0
- package/dist/skills/hor-build-e2e-test-environment/references/seed-data.md +145 -0
- package/dist/skills/hor-build-e2e-test-environment/references/windows-runner.md +146 -0
- package/dist/skills/hor-constant-definition/SKILL.md +139 -0
- package/dist/skills/hor-cookie-authentication/SKILL.md +33 -0
- package/dist/skills/hor-cookie-authentication/references/auth-filter.md +55 -0
- package/dist/skills/hor-cookie-authentication/references/cookie-context.md +53 -0
- package/dist/skills/hor-cookie-authentication/references/dev-login-seeder.md +22 -0
- package/dist/skills/hor-cookie-authentication/references/environment.md +64 -0
- package/dist/skills/hor-cookie-authentication/references/error-codes.md +24 -0
- package/dist/skills/hor-cookie-authentication/references/migrations.md +18 -0
- package/dist/skills/hor-cookie-authentication/references/resolvers.md +97 -0
- package/dist/skills/hor-cookie-authentication/references/session-clerk.md +41 -0
- package/dist/skills/hor-cookie-authentication/references/token-models.md +125 -0
- package/dist/skills/hor-database-design/SKILL.md +54 -0
- package/dist/skills/hor-database-design/references/column-types.md +92 -0
- package/dist/skills/hor-database-design/references/datetimes.md +88 -0
- package/dist/skills/hor-database-design/references/master-tables.md +117 -0
- package/dist/skills/hor-database-design/references/normalization.md +40 -0
- package/dist/skills/hor-database-design/references/update-history.md +35 -0
- package/dist/skills/hor-execution-placement-pattern/SKILL.md +216 -0
- package/dist/skills/hor-external-api-client/SKILL.md +99 -0
- package/dist/skills/hor-external-api-client/references/architecture.md +127 -0
- package/dist/skills/hor-external-api-client/references/authorization.md +105 -0
- package/dist/skills/hor-external-api-client/references/capsule.md +130 -0
- package/dist/skills/hor-external-api-client/references/conventions.md +68 -0
- package/dist/skills/hor-external-api-client/references/launcher.md +138 -0
- package/dist/skills/hor-external-api-client/references/payload.md +176 -0
- package/dist/skills/hor-external-api-client/references/sdk-wrapper.md +291 -0
- package/dist/skills/hor-external-api-client/references/testing.md +130 -0
- package/dist/skills/hor-external-api-client/references/usage.md +152 -0
- package/dist/skills/hor-graphql-schema/SKILL.md +360 -0
- package/dist/skills/hor-graphql-server-engine/SKILL.md +356 -0
- package/dist/skills/hor-light-rag/SKILL.md +242 -0
- package/dist/skills/hor-light-rag/references/retrieval-internals.md +143 -0
- package/dist/skills/hor-multi-llm-provider/SKILL.md +288 -0
- package/dist/skills/hor-multi-llm-provider/references/provider-internals.md +153 -0
- package/dist/skills/hor-mutation-resolver/SKILL.md +360 -0
- package/dist/skills/hor-mutation-resolver/references/dependency-injection.md +148 -0
- package/dist/skills/hor-mutation-resolver/references/errors.md +120 -0
- package/dist/skills/hor-mutation-resolver/references/resolve-flow.md +275 -0
- package/dist/skills/hor-mutation-resolver/references/testing.md +125 -0
- package/dist/skills/hor-mutation-resolver/references/transaction.md +197 -0
- package/dist/skills/hor-post-worker/SKILL.md +320 -0
- package/dist/skills/hor-query-resolver/SKILL.md +246 -0
- package/dist/skills/hor-query-resolver/references/anatomy.md +384 -0
- package/dist/skills/hor-query-resolver/references/data-access.md +248 -0
- package/dist/skills/hor-query-resolver/references/errors-and-context.md +172 -0
- package/dist/skills/hor-query-resolver/references/testing.md +241 -0
- package/dist/skills/hor-renchan-job-bullmq/SKILL.md +178 -0
- package/dist/skills/hor-renchan-job-bullmq/references/daemon-and-scheduler.md +182 -0
- package/dist/skills/hor-renchan-job-bullmq/references/engine-and-infra.md +106 -0
- package/dist/skills/hor-renchan-job-bullmq/references/job-triple.md +189 -0
- package/dist/skills/hor-renchan-job-bullmq/references/queues.md +74 -0
- package/dist/skills/hor-renchan-job-bullmq/references/subscriptions.md +113 -0
- package/dist/skills/hor-resolver-share/SKILL.md +262 -0
- package/dist/skills/hor-resolver-validator/SKILL.md +194 -0
- package/dist/skills/hor-resolver-validator/references/inspector-api.md +115 -0
- package/dist/skills/hor-resolver-validator/references/validator-pattern.md +281 -0
- package/dist/skills/hor-restfulapi-architecture/SKILL.md +275 -0
- package/dist/skills/hor-restfulapi-architecture/references/engine-and-context.md +192 -0
- package/dist/skills/hor-restfulapi-architecture/references/renderers.md +204 -0
- package/dist/skills/hor-restfulapi-architecture/references/response-and-flusher.md +118 -0
- package/dist/skills/hor-restfulapi-architecture/references/validation.md +229 -0
- package/dist/skills/hor-security-audit/SKILL.md +110 -0
- package/dist/skills/hor-security-audit/references/application-surface.md +90 -0
- package/dist/skills/hor-security-audit/references/auth-and-transport.md +147 -0
- package/dist/skills/hor-security-audit/references/code-safety.md +74 -0
- package/dist/skills/hor-security-audit/references/dependencies.md +72 -0
- package/dist/skills/hor-security-audit/references/network-and-logging.md +56 -0
- package/dist/skills/hor-security-audit/references/secrets.md +95 -0
- package/dist/skills/hor-sequelize-migration/SKILL.md +336 -0
- package/dist/skills/hor-sequelize-migration/references/alter-table.md +147 -0
- package/dist/skills/hor-sequelize-migration/references/foreign-keys.md +107 -0
- package/dist/skills/hor-sequelize-migration/references/indexes.md +149 -0
- package/dist/skills/hor-sequelize-migration/references/notation.md +215 -0
- package/dist/skills/hor-sequelize-model/SKILL.md +69 -0
- package/dist/skills/hor-sequelize-model/references/associations.md +218 -0
- package/dist/skills/hor-sequelize-model/references/default-methods.md +244 -0
- package/dist/skills/hor-sequelize-model/references/mixins.md +247 -0
- package/dist/skills/hor-sequelize-model/references/notation.md +225 -0
- package/dist/skills/hor-sequelize-model/references/timestamps.md +74 -0
- package/dist/skills/hor-sequelize-seeder/SKILL.md +275 -0
- package/dist/skills/hor-sequelize-seeder/references/development-coverage.md +74 -0
- package/dist/skills/hor-sequelize-seeder/references/directory-structure.md +113 -0
- package/dist/skills/hor-sequelize-seeder/references/id-numbering.md +133 -0
- package/dist/skills/hor-sequelize-seeder/references/naming.md +59 -0
- package/dist/skills/hor-sequelize-seeder/references/notation.md +170 -0
- package/dist/skills/hor-sequelize-subquery/SKILL.md +369 -0
- package/dist/skills/hor-strategy-pattern/SKILL.md +371 -0
- package/dist/skills/hor-stub-api/SKILL.md +330 -0
- package/dist/skills/hor-subscription-resolver/SKILL.md +105 -0
- package/dist/skills/hor-subscription-resolver/references/authentication.md +99 -0
- package/dist/skills/hor-subscription-resolver/references/basic-notation.md +116 -0
- package/dist/skills/hor-subscription-resolver/references/design-philosophy.md +68 -0
- package/dist/skills/hor-type-interface/SKILL.md +200 -0
- package/docs/skills.ja.md +40 -0
- package/docs/skills.md +40 -0
- package/lib/equip/CommandLineArguments.js +178 -0
- package/lib/equip/HoraSkillsCli.js +590 -0
- package/lib/equip/SkillsInstaller.js +443 -0
- package/lib/equip/SkillsManifestFile.js +260 -0
- package/lib/equip/constants/CLI_COMMAND.js +8 -0
- package/lib/equip/hora-skills-ort-renchan.js +8 -0
- package/package.json +51 -0
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: hor-graphql-schema
|
|
3
|
+
description: >
|
|
4
|
+
Author and edit GraphQL SDL (.graphql) files for a renchan server: per-audience schemas loaded
|
|
5
|
+
via each engine's schemaPath, numbered per-domain files, custom scalars, and the conventions for
|
|
6
|
+
type and field naming, nullability, enums and pagination. Use this skill whenever the user asks
|
|
7
|
+
to add or change a GraphQL schema — a new operation, a new type, a new domain file, a scalar, an
|
|
8
|
+
enum, pagination or sort types — or asks where an SDL definition belongs or what to name a field.
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# GraphQL Schema (SDL conventions)
|
|
12
|
+
|
|
13
|
+
A skill for writing the `.graphql` SDL files that define each audience's GraphQL contract.
|
|
14
|
+
The SDL declares the shape; the behavior behind each field is implemented by
|
|
15
|
+
`hor-query-resolver` / `hor-mutation-resolver`, and input values are checked by
|
|
16
|
+
`hor-resolver-validator`. This skill covers where an SDL definition goes, how it is named, and
|
|
17
|
+
how its fields are typed.
|
|
18
|
+
|
|
19
|
+
## Grand principle: the SDL is a derived contract — names, nullability, and placement follow mechanical rules, not taste
|
|
20
|
+
|
|
21
|
+
Every schema decision in this convention can be derived: the operation name drives the
|
|
22
|
+
type names one-to-one (`<Operation>Input` / `<Operation>Result`), non-null `!` is the
|
|
23
|
+
default unless a value is genuinely optional, each business domain gets its own numbered
|
|
24
|
+
file, and each audience keeps its own schema. **Do not invent ad-hoc names,
|
|
25
|
+
nullable-by-default fields, or a shared "misc" file** — a reader who knows the operation
|
|
26
|
+
name must be able to predict the file, the type names, and the nullability without opening
|
|
27
|
+
anything.
|
|
28
|
+
|
|
29
|
+
- **Why mechanical naming**: resolvers are matched to operations by name
|
|
30
|
+
(`static get schema()` in `hor-query-resolver` / `hor-mutation-resolver` returns the SDL field
|
|
31
|
+
name), and JSDoc types reference `<Operation>Input` / `<Operation>Result` directly. One
|
|
32
|
+
mismatched name breaks the chain from SDL to resolver to type-check.
|
|
33
|
+
- **Why non-null by default**: a nullable field forces every consumer to write a null
|
|
34
|
+
branch. Reserving nullability for genuinely optional values makes each remaining `?`
|
|
35
|
+
meaningful — nullability becomes documentation, not noise.
|
|
36
|
+
- **Why per-audience, per-domain files**: audiences (e.g. customer / admin) have different
|
|
37
|
+
contracts and lifecycles. Merging them, or piling domains into one file, makes it
|
|
38
|
+
impossible to see which audience a change affects.
|
|
39
|
+
|
|
40
|
+
```graphql
|
|
41
|
+
# Good: names derived from the operation, non-null by default, deliberate nullability
|
|
42
|
+
type Query {
|
|
43
|
+
orders(input: OrdersInput!): OrdersResult!
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
input OrdersInput {
|
|
47
|
+
pagination: PaginationInput!
|
|
48
|
+
filters: OrderFiltersInput # nullable: filters are genuinely optional
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
type OrdersResult {
|
|
52
|
+
orders: [OrderSummary!]!
|
|
53
|
+
pagination: Pagination!
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
```graphql
|
|
58
|
+
# Avoid: invented payload name, nullable-by-default fields
|
|
59
|
+
# → the resolver/type chain can no longer be predicted from the operation name,
|
|
60
|
+
# and every consumer must null-check fields that are never actually null.
|
|
61
|
+
type Query {
|
|
62
|
+
orders(input: OrdersArgs): OrdersPayload
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
type OrdersPayload {
|
|
66
|
+
orders: [OrderSummary]
|
|
67
|
+
pagination: Pagination
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## 1. Where a schema lives and how it loads (check the engine first)
|
|
72
|
+
|
|
73
|
+
Each audience is loaded by its own `*GraphqlServerEngine.js`, and **how the schema is
|
|
74
|
+
loaded can differ by audience**. Before adding or editing a file, check that audience's
|
|
75
|
+
engine `schemaPath`:
|
|
76
|
+
|
|
77
|
+
- **Folder path** (e.g. `server/graphql/schemas/customer/`) → the folder's numbered files
|
|
78
|
+
are merged into one schema at load time. Follow the numbered-file conventions below.
|
|
79
|
+
- **Single file path** (e.g. `server/graphql/schemas/admin.graphql`) → edit that one file.
|
|
80
|
+
A sibling folder of the same audience name may exist but be **unwired** — adding files
|
|
81
|
+
there changes nothing until the engine's `schemaPath` points at it.
|
|
82
|
+
|
|
83
|
+
```js
|
|
84
|
+
// server/graphql/CustomerGraphqlServerEngine.js — the source of truth for what loads
|
|
85
|
+
static get config () {
|
|
86
|
+
return {
|
|
87
|
+
// ...existing config...
|
|
88
|
+
schemaPath: rootPath.to('server/graphql/schemas/customer/'),
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
- **Never put a type for one audience in another audience's folder.** Even identical-looking
|
|
94
|
+
types (e.g. `Pagination`) are declared per audience, because the audiences' contracts
|
|
95
|
+
evolve independently.
|
|
96
|
+
|
|
97
|
+
## 2. File organization — numbered, per-domain
|
|
98
|
+
|
|
99
|
+
A merged-folder audience is split into numbered per-domain files. The first file
|
|
100
|
+
(`001-common.graphql`) holds shared plumbing (scalars, `Pagination`, `Sort`, shared enums);
|
|
101
|
+
every later file is one business domain.
|
|
102
|
+
|
|
103
|
+
```
|
|
104
|
+
server/graphql/schemas/customer/
|
|
105
|
+
001-common.graphql # scalars, Pagination, Sort, shared enums
|
|
106
|
+
002-auth.graphql
|
|
107
|
+
003-order.graphql
|
|
108
|
+
004-billing.graphql
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
- Filename is `NNN-<domain>.graphql`. Domain casing (kebab-case vs camelCase) can vary
|
|
112
|
+
between existing files — **match the casing of the sibling files** in the folder you are
|
|
113
|
+
editing.
|
|
114
|
+
- **One domain per file.** Add a new numbered file for a new domain rather than growing an
|
|
115
|
+
existing one.
|
|
116
|
+
- All files in the folder are merged at load time, so `type Query` / `type Mutation` may be
|
|
117
|
+
declared in several files ([4](#4-query--mutation-blocks--colocated-per-domain-file)).
|
|
118
|
+
|
|
119
|
+
## 3. Custom scalars — declared once, at the top of the common file
|
|
120
|
+
|
|
121
|
+
Custom scalars are declared **only** in that audience's `001-common.graphql`, at the very
|
|
122
|
+
top, one per line, no `!`:
|
|
123
|
+
|
|
124
|
+
```graphql
|
|
125
|
+
scalar BigNumber
|
|
126
|
+
scalar DateTime
|
|
127
|
+
scalar Upload
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
- Do not re-declare a scalar in any other file. Just reference it (`createdAt: DateTime!`).
|
|
131
|
+
- Scalars can differ across audiences — declare only the scalars the audience uses,
|
|
132
|
+
matching the sibling audiences' style rather than copying their scalar list.
|
|
133
|
+
|
|
134
|
+
## 4. Query / Mutation blocks — colocated per domain file
|
|
135
|
+
|
|
136
|
+
Do **not** keep one giant root `Query` / `Mutation`. Each domain file opens its own
|
|
137
|
+
`type Query` and `type Mutation` block listing only that domain's fields; the loader merges
|
|
138
|
+
them.
|
|
139
|
+
|
|
140
|
+
```graphql
|
|
141
|
+
# 003-order.graphql
|
|
142
|
+
type Query {
|
|
143
|
+
orders(input: OrdersInput!): OrdersResult!
|
|
144
|
+
orderDetail(input: OrderDetailInput!): OrderDetailResult!
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
type Mutation {
|
|
148
|
+
cancelOrder(input: CancelOrderInput!): CancelOrderResult!
|
|
149
|
+
archiveDeliveredOrders: ArchiveDeliveredOrdersResult!
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
- A field with no input takes no argument (`archiveDeliveredOrders: ArchiveDeliveredOrdersResult!`).
|
|
154
|
+
- Every operation returns a non-null payload type (`...Result!`).
|
|
155
|
+
|
|
156
|
+
## 5. Type naming — `<Operation>Input` and `<Operation>Result`
|
|
157
|
+
|
|
158
|
+
The operation name drives the type names, one-to-one:
|
|
159
|
+
|
|
160
|
+
| Kind | Name | Example |
|
|
161
|
+
| --- | --- | --- |
|
|
162
|
+
| Input | `<Operation>Input` | `cancelOrder` → `CancelOrderInput` |
|
|
163
|
+
| Payload | `<Operation>Result` | `orders` → `OrdersResult` |
|
|
164
|
+
|
|
165
|
+
- Nested / domain object types are plain nouns (`OrderItem`, `ProductImage`, `Status`).
|
|
166
|
+
- Sub-summary types carry a `Summary` suffix (`OrderSummary`).
|
|
167
|
+
- One operation, one input type, one result type — do not share an input or result type
|
|
168
|
+
between operations even when the shapes currently coincide; shared types couple
|
|
169
|
+
operations that will diverge.
|
|
170
|
+
|
|
171
|
+
## 5.1 Field naming — the SDL borrows the database's vocabulary
|
|
172
|
+
|
|
173
|
+
The SDL does not invent a second vocabulary. A field carries the same name as the column it
|
|
174
|
+
exposes, so renaming a concept is one change across the migration, the model, and the schema.
|
|
175
|
+
|
|
176
|
+
- Datetime fields end with `At`; date-only fields end with `On`. A range keeps the suffix and
|
|
177
|
+
adds `From` / `To` (`modifiedAtFrom` / `modifiedAtTo`).
|
|
178
|
+
- **Never expose `updatedAt` / `createdAt`.** They read as the ORM's audit columns, whose timing
|
|
179
|
+
is a framework detail the application does not own — a migration backfill moves them without any
|
|
180
|
+
business event. A business time is its own named field: `modifiedAt`, `generatedAt`,
|
|
181
|
+
`registeredAt`. This is the SDL side of the business-time-vs-audit-time split the database
|
|
182
|
+
design convention enforces on the column side.
|
|
183
|
+
- A classification field is `xxxCategory`, not `xxxType` — `type` collides with the JSDoc type
|
|
184
|
+
annotation, so a reader cannot tell whether it means a JavaScript type or a business
|
|
185
|
+
classification. The shared naming convention lists the one exception: a word borrowed verbatim
|
|
186
|
+
from an external standard (`mimeType`).
|
|
187
|
+
- A `sort.targetColumn` allow-list uses these same field names, so renaming a field renames the
|
|
188
|
+
sort key in the same change.
|
|
189
|
+
- **A single-character key is prohibited** — in a field, an argument, or an input type. `q`, `s`,
|
|
190
|
+
`n`, `p` state nothing about what the value is; name the key for what it holds (`searchQuery`,
|
|
191
|
+
`sortKey`, `pageNumber`). The SDL is the contract every client reads *before* it reads any code,
|
|
192
|
+
so a one-letter key costs every consumer a trip into the resolver to learn what to pass, and the
|
|
193
|
+
generated TypeScript type inherits the same opaque name. Abbreviations are limited to the shared
|
|
194
|
+
naming convention's whitelist, and no single letter is on it.
|
|
195
|
+
|
|
196
|
+
```graphql
|
|
197
|
+
# Good: the key states what the value is
|
|
198
|
+
input SearchArticlesInput {
|
|
199
|
+
searchQuery: String!
|
|
200
|
+
sortKey: String!
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
# Avoid: single-character keys — the contract no longer explains itself
|
|
204
|
+
input SearchArticlesInput {
|
|
205
|
+
q: String!
|
|
206
|
+
s: String!
|
|
207
|
+
}
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
## 6. Non-null `!` — the default
|
|
211
|
+
|
|
212
|
+
`!` is applied to nearly every field and argument. A field is non-null unless the value is
|
|
213
|
+
**genuinely optional**; nullability is deliberate, not the fallback.
|
|
214
|
+
|
|
215
|
+
```graphql
|
|
216
|
+
type Order {
|
|
217
|
+
id: Int!
|
|
218
|
+
customerId: Int # nullable: guest orders have no customer
|
|
219
|
+
items: [OrderItem!]! # non-null list of non-null elements
|
|
220
|
+
modifiedAt: DateTime!
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
- Lists are `[T!]!` when the list is required; use `[T!]` only when the whole list is
|
|
225
|
+
genuinely optional.
|
|
226
|
+
- Optional inputs drop the `!` and carry a short comment stating why the null is allowed
|
|
227
|
+
(`avatarUrl: String # allow null`).
|
|
228
|
+
- SDL `!` only guards *presence*. Value-level checks (ranges, formats, enum membership)
|
|
229
|
+
belong to the `hor-resolver-validator` skill — do not weaken the SDL to "validate later",
|
|
230
|
+
and do not assume `!` makes a validator unnecessary.
|
|
231
|
+
|
|
232
|
+
## 7. Money / decimal fields — `String!`, decimal-as-string
|
|
233
|
+
|
|
234
|
+
Money and decimal amounts are typed **`String!`** — not `Float` (loses precision) and not
|
|
235
|
+
`BigNumber` (reserved for non-money large integers such as byte sizes). Resolvers emit them
|
|
236
|
+
via `BigNumber#toFixed(2)`.
|
|
237
|
+
|
|
238
|
+
```graphql
|
|
239
|
+
type OrderItem {
|
|
240
|
+
quantity: Int!
|
|
241
|
+
unitPrice: String! # Decimal as string for precision
|
|
242
|
+
totalPrice: String!
|
|
243
|
+
}
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
```js
|
|
247
|
+
// Resolver side: emit decimals as fixed strings
|
|
248
|
+
return {
|
|
249
|
+
unitPrice: orderItem.unitPrice.toFixed(2),
|
|
250
|
+
totalPrice: orderItem.totalPrice.toFixed(2),
|
|
251
|
+
}
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
```graphql
|
|
255
|
+
# Avoid: Float for money → binary floating point corrupts amounts like 0.1 + 0.2
|
|
256
|
+
type OrderItem {
|
|
257
|
+
totalPrice: Float!
|
|
258
|
+
}
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
## 8. Pagination type shape
|
|
262
|
+
|
|
263
|
+
A list query returns its rows plus a `Pagination` object; the input carries a
|
|
264
|
+
`PaginationInput`. Both live in `001-common.graphql`.
|
|
265
|
+
|
|
266
|
+
```graphql
|
|
267
|
+
type Pagination {
|
|
268
|
+
limit: Int!
|
|
269
|
+
offset: Int!
|
|
270
|
+
sort: Sort
|
|
271
|
+
totalRecords: Int!
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
input PaginationInput {
|
|
275
|
+
limit: Int!
|
|
276
|
+
offset: Int!
|
|
277
|
+
sort: SortInput
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
type OrdersResult {
|
|
281
|
+
orders: [OrderSummary!]!
|
|
282
|
+
pagination: Pagination!
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
input OrdersInput {
|
|
286
|
+
pagination: PaginationInput!
|
|
287
|
+
filters: OrderFiltersInput # optional filters
|
|
288
|
+
}
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
- `sort` / `SortInput` are **nullable** on the pagination pair; `limit` / `offset` /
|
|
292
|
+
`totalRecords` are non-null.
|
|
293
|
+
- The `Sort` shape can differ across audiences — match the pagination/sort types already
|
|
294
|
+
used in the audience folder you are editing; never copy one audience's shape into
|
|
295
|
+
another.
|
|
296
|
+
- Enums for filters/sort live in the domain file that uses them, or in `001-common` when
|
|
297
|
+
shared.
|
|
298
|
+
- Validation of `limit` / `offset` / `sort` values on the resolver side is covered by the
|
|
299
|
+
shared pagination validator in `hor-resolver-validator`.
|
|
300
|
+
- Enums are written **one member per line**, never inline — an inline enum has nowhere to put
|
|
301
|
+
the per-member comment that explains what the value means, and every added member re-diffs
|
|
302
|
+
the whole line.
|
|
303
|
+
|
|
304
|
+
```graphql
|
|
305
|
+
# Good
|
|
306
|
+
enum SortDirection {
|
|
307
|
+
ASC
|
|
308
|
+
DESC
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
# Avoid
|
|
312
|
+
enum SortDirection { ASC DESC }
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
## 9. Mirror every SDL type into `types/<Audience>GraphQL.d.ts`
|
|
316
|
+
|
|
317
|
+
Defining a type in the SDL is **only half the job** — declare the matching TypeScript
|
|
318
|
+
interface in the audience's `types/<Audience>GraphQL.d.ts` in the same change. Resolvers
|
|
319
|
+
reference these via JSDoc
|
|
320
|
+
(`@param {{ input: server.graphql.customer.CancelOrderInput }}`,
|
|
321
|
+
`@returns {Promise<server.graphql.customer.OrdersResult>}`), so a type present in
|
|
322
|
+
the SDL but missing from the `.d.ts` fails type-check.
|
|
323
|
+
|
|
324
|
+
```typescript
|
|
325
|
+
declare global {
|
|
326
|
+
namespace server.graphql.customer {
|
|
327
|
+
interface CancelOrderInput {
|
|
328
|
+
orderId: number
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
interface CancelOrderResult {
|
|
332
|
+
canceledOrderId: number
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
- Name the interfaces exactly `<Operation>Input` / `<Operation>Result`.
|
|
339
|
+
- Keep fields in sync field-for-field: GraphQL `!` → required property, nullable → `?`.
|
|
340
|
+
|
|
341
|
+
## 10. Match the surrounding file's style
|
|
342
|
+
|
|
343
|
+
Section banners and member ordering are per-audience habits, not one global rule — some
|
|
344
|
+
folders use light banners (`# ===== Order Mutation Input Types =====`), others use full
|
|
345
|
+
`#### QUERY` / `#### MUTATION` / `#### TYPE` / `#### INPUT` blocks with dictionary-order
|
|
346
|
+
rules stated in a header comment. **Follow whichever style the surrounding file already
|
|
347
|
+
uses**, including any stated ordering rule.
|
|
348
|
+
|
|
349
|
+
## Finishing checklist
|
|
350
|
+
|
|
351
|
+
- [ ] Did you check the audience engine's `schemaPath` before adding a file (merged folder vs single file, and is the folder actually wired)?
|
|
352
|
+
- [ ] Is the definition in the right audience and the right numbered domain file (new domain → new `NNN-<domain>.graphql`, casing matched to siblings)?
|
|
353
|
+
- [ ] Are custom scalars declared only once, at the top of that audience's `001-common.graphql`?
|
|
354
|
+
- [ ] Are the domain's `type Query` / `type Mutation` blocks colocated in the domain file (no giant root block)?
|
|
355
|
+
- [ ] Are the type names exactly `<Operation>Input` / `<Operation>Result`, with plain-noun object types and `Summary` sub-types?
|
|
356
|
+
- [ ] Is `!` the default, with every nullable field genuinely optional (and commented why)? Lists `[T!]!` unless the whole list is optional?
|
|
357
|
+
- [ ] Are money/decimal fields `String!` (emitted via `toFixed(2)`), with `BigNumber` reserved for non-money large integers?
|
|
358
|
+
- [ ] Do list operations use the audience's `Pagination` / `PaginationInput` shape (nullable `sort`, non-null `limit`/`offset`/`totalRecords`)?
|
|
359
|
+
- [ ] Did you mirror every added/changed SDL type into `types/<Audience>GraphQL.d.ts`, field-for-field, in the same change?
|
|
360
|
+
- [ ] Did you match the surrounding file's banner style and any stated ordering rule?
|