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.
2
5
3
6
4
7
7
10
8
11
To use the package, simply add the following to your ` pubspec.yaml ` :
9
12
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
+
10
24
` ` ` yaml
11
25
dependencies:
12
26
artemis_custom_gen:
@@ -41,9 +55,62 @@ class MyCustomType {
41
55
}
42
56
` ` `
43
57
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) :
47
114
48
115
` ` ` yaml
49
116
targets:
@@ -53,11 +120,16 @@ targets:
53
120
options:
54
121
scalar_mapping:
55
122
- 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"
57
124
dart_type:
58
125
name: MyCustomType
59
126
imports:
60
127
- "package:your_package/path_to_your_model/my_custom_type.dart"
61
128
` ` `
62
129
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`.
0 commit comments