Skip to content

Commit 1e89778

Browse files
committed
Update CHANGELOG to reflect latest changes
1 parent d3c9301 commit 1e89778

File tree

4 files changed

+80
-13
lines changed

4 files changed

+80
-13
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
## 1.0.0
1+
## 0.1.0
22

33
- Initial version.

README.md

+78-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
`artemis_custom_gen` is a `build_runner` custom types generator for `artemis` GraphQL package.
1+
`artemis_custom_gen`
2+
====================
3+
4+
`artemis_custom_gen` is a custom types generator for `artemis` GraphQL package.
25

36

47

@@ -7,6 +10,17 @@
710

811
To use the package, simply add the following to your `pubspec.yaml`:
912

13+
14+
```yaml
15+
dependencies:
16+
artemis_custom_gen:
17+
18+
dev_dependencies:
19+
build_runner:
20+
```
21+
22+
Or to depend on the latest `main`:
23+
1024
```yaml
1125
dependencies:
1226
artemis_custom_gen:
@@ -41,9 +55,62 @@ class MyCustomType {
4155
}
4256
```
4357

44-
2. Add the `part '....g.dart';` directive after the imports in your Dart file.
45-
3. Run the `build_runner`: `dart run build_runner build`.
46-
4. Add the generated type to the `build.yaml` of your package (see `artemis` documentation to learn more):
58+
__Note__, that for parsing from `String` your custom type __must__ have a single `String` argument constructor. E.g.:
59+
60+
```dart
61+
@ArtemisCustomType(graphQlType: 'MyGraphQlScalar')
62+
class MyCustomType {
63+
const MyCustomType(this.value); // `this.value` is a `String`.
64+
final String value;
65+
}
66+
```
67+
68+
```dart
69+
class Parent {
70+
const Parent(this.value);
71+
final String value;
72+
}
73+
74+
@ArtemisCustomType(graphQlType: 'MyGraphQlScalar')
75+
class MyCustomType extends Parent {
76+
const MyCustomType(super.value); // `super.value` is a `String`.
77+
}
78+
```
79+
80+
```dart
81+
@ArtemisCustomType(graphQlType: 'MyGraphQlScalar')
82+
class MyCustomType {
83+
const MyCustomType(this.value);
84+
85+
// Naming doesn't matter.
86+
const MyCustomType.parse(String string) : value = double.parse(string);
87+
88+
final double value;
89+
}
90+
```
91+
92+
And for parsing to `String` currently `artemis_custom_gen` uses `toString()` on your custom type.
93+
94+
2. (Optionally) Configure the output path (default is `lib/api/parsers.g.dart`).
95+
96+
In your `build.yaml`:
97+
98+
```yaml
99+
targets:
100+
$default:
101+
builders:
102+
artemis_custom_gen:
103+
options:
104+
output: api/backend/parsers.dart # Without `lib/`.
105+
```
106+
107+
3. Run the `build_runner`:
108+
109+
```bash
110+
dart run build_runner build
111+
```
112+
113+
4. Add the generated type to the `artemis` options in `build.yaml` (see `artemis` documentation to learn more):
47114

48115
```yaml
49116
targets:
@@ -53,11 +120,16 @@ targets:
53120
options:
54121
scalar_mapping:
55122
- graphql_type: MyGraphQlScalar
56-
custom_parser_import: "package:your_package/path_to_your_model/my_custom_type.dart"
123+
custom_parser_import: "package:your_package/path_to_parsed_file.dart"
57124
dart_type:
58125
name: MyCustomType
59126
imports:
60127
- "package:your_package/path_to_your_model/my_custom_type.dart"
61128
```
62129

63-
Note, that `custom_parser_import` and `imports` are the same. That's because of that `part` directive you put.
130+
131+
132+
133+
## Roadmap
134+
135+
- [ ] Configurable to `String` and from `String` parsers on `ArtemisCustomType`.

lib/src/builder.dart

-5
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ class ArtemisCustomTypeBuilder implements Builder {
4646
}
4747
}
4848

49-
print('IMPORTS: ${imports.join('\n')}');
50-
5149
if (items.isEmpty) {
5250
// Nothing to generate.
5351
return;
@@ -62,8 +60,6 @@ class ArtemisCustomTypeBuilder implements Builder {
6260
buffer.writeln();
6361

6462
for (var e in items) {
65-
print('Generating for ${e.element.name}');
66-
6763
final List<ConstructorElement> ctors =
6864
(e.element as ClassElement).constructors;
6965
final String name = e.element.name!;
@@ -115,6 +111,5 @@ class ArtemisCustomTypeBuilder implements Builder {
115111

116112
final outputId = AssetId(buildStep.inputId.package, 'lib/$output');
117113
await buildStep.writeAsString(outputId, buffer.toString());
118-
print('written to $outputId');
119114
}
120115
}

pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: artemis_custom_gen
22
description: Custom types generator for artemis.
3-
version: 1.0.0
3+
version: 0.1.0
44
repository: https://github.com/lapuske/artemis_custom_gen
55

66
environment:

0 commit comments

Comments
 (0)