You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> More options can be found in [utils.ts](./src/utils.ts)
77
+
> More options will be introduced below.
93
78
94
79
generated:
95
80
@@ -148,89 +133,112 @@ export class Root {
148
133
}
149
134
```
150
135
151
-
## Simple Documentation
136
+
## Options
152
137
153
138
### Reader
154
139
155
-
Reader handles content obtainment from JSON file / URL request / raw JavaScript object, you must provide at least one of `reader.path` / `reader.url` / `reader.raw` options.
140
+
**Reader** is responsible for reading data from different sources including `JSON File` / `URL Request` / `Raw JavaScript Object`, you must provide one of `reader.path` / `reader.url` / `reader.raw` options.
156
141
157
142
#### Reader.Options
158
143
159
-
-`path`: **Absoulte** JSON file path.
160
-
-`url` & `options`: Using [got](https://www.npmjs.com/package/got) for data fetching like`got(url, options)`.
161
-
-`raw`: Plain JavaScript Object / Array.
144
+
-`path`(`string`): **Absoulte** JSON file path.
145
+
-`url`(`string`) & `options`(`Got Options`): Using [got](https://www.npmjs.com/package/got) for data fetching:`got(url, options)`.
After raw content is readed, it will be passed to `preprocessor`.
148
+
After content acquisition got completed, the content will be passed to next handler called **preprocessor**.
164
149
165
150
### Preprocessor
166
151
167
-
Preprocessor will perform some extra processing on the input content:
152
+
Preprocessor will perform some extra pre-processing works in the incoming content:
168
153
169
-
-Recursively **delete** object pairs which value is kind of **nested array** like `[[]]`, this is not supported yet which may also cause unexpected errors.
170
-
- Ensure array contains **either primitive values or object values**, only obejct values will be preserved when the array
171
-
contains mixed members. You can control this behaviour by `preprocessor.preserveObjectOnlyInArray`.
154
+
-**Recursively delete** object field which value is kind of **nested array** like `[[]]`, this is not supported yet which may cause unexpected behaviours or errors.
155
+
- Ensure array contains either **primitive type values** or **object type values**, by default,**only obejct values will be preserved** when the array
156
+
contains both kinds of members(You can control this behaviour by `preprocessor.preserveObjectOnlyInArray`).
172
157
173
158
#### Preprocessor.Options
174
159
175
-
-`preserveObjectOnlyInArray`: `default: true`
176
-
-`customPreprocessor`: Use your own custom preprocessor, which accepts `raw` from reader.
-`customPreprocessor`(`(raw: object | array) => object | array`): Use your own custom preprocessor, which accepts content from reader, and should return JavaScript Object / Array.
177
162
178
163
### Parser
179
164
180
-
Parser will transform the preprocessed raw content to specific object structure,
165
+
**Parser** will transform the pre-processed content to specific object structure,
181
166
which will be consumed by `generator`.
182
167
183
-
Array entry structure(like `[]`) and object entry structure(like `{}`) will be parsed differently.
168
+
> Array entry structure(like `[]`) and object entry structure(like `{}`) will be parsed differently.
184
169
185
170
#### Parser.Options
186
171
187
-
-`forceNonNullable`: Mark all field as non-nullale. `default: true`
188
-
-`forceNonNullableListItem`: Mark all list item as non-nullale.`default: false`
189
-
-`forceReturnType`: Generate return type for even string / boolean / field like `@Field((type) => String)`. `default: false`
190
-
-`arrayEntryProp`: When parsing array-entry structure, use specified prop name like: `data: Data[]`. `default: 'data'`
172
+
-`forceNonNullable`(`boolean`): Mark all field as non-nullale. `default: true`
173
+
-`forceNonNullableListItem`(`boolean`): Mark all list item as non-nullale. `default: false`
174
+
-`forceReturnType`(`boolean`): Generate return type for even `string` / `boolean` field like `@Field((type) => String)`. `default: false`
175
+
-`arrayEntryProp`(`string`): When parsing array-entry structure, use specified prop name like: `data: Data[]`. `default: 'data'`.
176
+
For example, `[{ foo: 1 }]` will be parsed to:
177
+
178
+
```javascript
179
+
classData {
180
+
foo: number;
181
+
}
191
182
192
-
> Custom parser is not supported now.
183
+
classRoot {
184
+
data: Data[];
185
+
}
186
+
```
193
187
194
188
### Generator
195
189
196
-
Generator will traverse the parsed info record, perform corresponding AST operations to generate TypeGraphQL class-based types.
190
+
**Generator** will traverse the parsed info, perform corresponding AST operations to generate class definitions with TypeGraphQL decorators.
197
191
198
192
#### Generator.Options
199
193
200
-
-`entryClassName`: The top-level generated entry class name. `default: 'Root'`.
201
-
-`prefix`: Prefix for generated class name, you can set `prefix: true` to simply avoid repeated class specifier(by using parent class as child class name prefix, like `RootChildSomeChildProp` is from `Root-Child-SomeType`). `default: false`
202
-
-`suffix`: Suffix for generated class name. `default: false`.
203
-
-`publicProps`: Prop names included by it will be attatched with `public` keyword.
204
-
-`readonlyProps`: Prop names included by it will be attatched with `readonly` keyword.
205
-
-`sort`: Should sort generated class in normal order like `P-C1-C11-C12-C2-C21-C3-C31`. `default: true`.
194
+
-`entryClassName`(`string`): The top-level generated entry class name. `default: 'Root'`.
195
+
-`prefix`(`boolean` | `string`): Prefix for generated class name, you can set `prefix: true` to simply avoid repeated class specifier. `default: false`.
196
+
By using parent class in child class name's prefix, like `RootChildSomeChildProp` is from:
197
+
198
+
```javascript
199
+
classRoot {
200
+
child: RootChild;
201
+
}
202
+
203
+
classRootChild {
204
+
someChildProp: RootChildSomeChildProp;
205
+
}
206
+
207
+
classRootChildSomeChildProp {}
208
+
```
209
+
210
+
-`suffix`(`boolean` | `string`): Suffix for generated class name, e.g. `RootType`, `Type` is the specified suffix.`default: false`.
211
+
-`publicProps`(`string[]`): Prop names included by it will be attatched with `public` keyword.
212
+
-`readonlyProps`(`string[]`): Prop names included by it will be attatched with `readonly` keyword.
213
+
-`sort`(`boolean`): Should sort generated class in normal order like `P-C1-C11-C12-C2-C21-C3-C31`. `default: true`.
206
214
207
215
### Postprocessor
208
216
209
-
Postprocessor is used to apply some post-processing works on generated source (`SourceFile`), you can use [ts-morph](https://ts-morph.com/) for simple and flexiable AST operations, which also powers the generator part.
217
+
**Postprocessor** is used to apply some post-process works on generated source (`TypeScript SourceFile`), you can use [ts-morph](https://ts-morph.com/) for simple and flexiable AST operations, which also powers the generator part indeed.
210
218
211
219
#### Postprocessor.Options
212
220
213
-
-`customPostprocessor`: Custom post-processor accepts the source and perform extra options.
Checker will use generated class to create a tmp reoslver, invoking `TypeGraphQL.buildSchemaSync` method to check does generated file work correctly.
225
+
**Checker** will use generated class definitions to create a tmp reoslver, invoking `TypeGraphQL.buildSchemaSync` method to check if generated file works correctly.
218
226
219
-
Under the hood, we're using `ts-node tmp-file.ts --compiler-options [options]` to perform the check.
227
+
We're using `ts-node tmp-file.ts --compiler-options [options]` to perform the check under the hood.
0 commit comments