Skip to content
This repository was archived by the owner on Oct 2, 2024. It is now read-only.

Commit 6f834a0

Browse files
committed
remove nullable feature
1 parent e709b2d commit 6f834a0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1350
-371
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# Files and directories created by pub
88
.dart_tool/
99
.packages
10+
.fvm
1011
build/
1112
# If you're building an application, you may want to check-in your pubspec.lock
1213
/pubspec.lock

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## 7.1.1-beta.0
4+
5+
- exclude nullable items from input
6+
37
## 7.1.0-beta.0
48

59
**BREAKING CHANGE**

README.md

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,30 @@ json), the `custom_parser_import` path must be set and the file must implement b
144144
and `fromDart___toGraphQL___` constant functions.
145145
`___ToDart___` and `___toGraphQL___` should be named including nullability, here is an example
146146

147-
`file: Upload` => `fromGraphQLUploadNullableToDartMultipartFileNullable`
148-
and `fromDartMultipartFileNullableToGraphQLUploadNullable`
149-
`file: Upload!` => `fromGraphQLUploadToDartMultipartFile` and `fromDartMultipartFileToGraphQLUpload`
150-
`file: [Upload]` => `fromGraphQLListNullableUploadNullableToDartListNullableMultipartFileNullable`
151-
and `fromDartListNullableMultipartFileNullableToGraphQLListNullableUploadNullable`
152-
`file: [Upload]!` => `fromGraphQLListUploadNullableToDartListMultipartFileNullable`
153-
and `fromDartListMultipartFileNullableToGraphQLListUploadNullable`
154-
`file: [Upload!]!` => `fromGraphQLListUploadToDartListMultipartFile` and `fromDartListMultipartFileToGraphQLListUpload`
147+
`file: Upload`
148+
149+
- `fromGraphQLUploadNullableToDartMultipartFileNullable`
150+
- `fromDartMultipartFileNullableToGraphQLUploadNullable`
151+
152+
`file: Upload!`
153+
154+
- `fromGraphQLUploadToDartMultipartFile`
155+
- `fromDartMultipartFileToGraphQLUpload`
156+
157+
`file: [Upload]`
158+
159+
- `fromGraphQLListNullableUploadNullableToDartListNullableMultipartFileNullable`
160+
- `fromDartListNullableMultipartFileNullableToGraphQLListNullableUploadNullable`
161+
162+
`file: [Upload]!`
163+
164+
- `fromGraphQLListUploadNullableToDartListMultipartFileNullable`
165+
- `fromDartListMultipartFileNullableToGraphQLListUploadNullable`
166+
167+
`file: [Upload!]!`
168+
169+
- `fromGraphQLListUploadToDartListMultipartFile`
170+
- `fromDartListMultipartFileToGraphQLListUpload`
155171

156172
```yaml
157173
targets:

lib/builder.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ class GraphQLQueryBuilder implements Builder {
184184

185185
writeLibraryDefinitionToBuffer(
186186
buffer,
187-
options.ignoreForFile,
187+
options,
188+
schemaMap,
188189
libDefinition,
189190
);
190191

lib/generator.dart

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:artemis/generator/data/annotation.dart';
12
import 'package:artemis/generator/data/data.dart';
23
import 'package:artemis/generator/data/enum_value_definition.dart';
34
import 'package:artemis/generator/data/nullable.dart';
@@ -8,6 +9,7 @@ import 'package:artemis/visitor/schema_definition_visitor.dart';
89
import 'package:artemis/visitor/type_definition_node_visitor.dart';
910
import 'package:collection/collection.dart' show IterableExtension;
1011
import 'package:gql/ast.dart';
12+
import 'package:json_annotation/json_annotation.dart';
1113
import 'package:path/path.dart' as p;
1214

1315
import './generator/ephemeral_data.dart';
@@ -265,7 +267,11 @@ ClassProperty createClassProperty({
265267
return ClassProperty(
266268
type: TypeName(name: 'String'),
267269
name: fieldName,
268-
annotations: ['JsonKey(name: \'${context.schemaMap.typeNameField}\')'],
270+
annotations: [
271+
JsonKeyAnnotation(
272+
jsonKey: JsonKeyItem(name: context.schemaMap.typeNameField),
273+
)
274+
],
269275
isResolveType: true,
270276
);
271277
}
@@ -341,7 +347,7 @@ Make sure your query is correct and your schema is updated.''');
341347
// On custom scalars
342348
final jsonKeyAnnotation = <String, String>{};
343349
if (name.namePrintable != name.name) {
344-
jsonKeyAnnotation['name'] = '\'${name.name}\'';
350+
jsonKeyAnnotation['name'] = name.name;
345351
}
346352

347353
if (nextType is ScalarTypeDefinitionNode) {
@@ -380,13 +386,10 @@ Make sure your query is correct and your schema is updated.''');
380386
final fieldDirectives =
381387
regularField?.directives ?? regularInputField?.directives;
382388

383-
var annotations = <String>[];
389+
var annotations = <Annotation>[];
384390

385391
if (jsonKeyAnnotation.isNotEmpty) {
386-
final jsonKey = jsonKeyAnnotation.entries
387-
.map<String>((e) => '${e.key}: ${e.value}')
388-
.join(', ');
389-
annotations.add('JsonKey($jsonKey)');
392+
annotations.add(JsonKeyAnnotation.fromMap(jsonKeyAnnotation));
390393
}
391394
annotations.addAll(proceedDeprecated(fieldDirectives));
392395

lib/generator/data/annotation.dart

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
import 'package:artemis/generator/data_printer.dart';
2+
import 'package:artemis/generator/data/definition.dart';
3+
import 'package:equatable/equatable.dart';
4+
import 'package:json_annotation/json_annotation.dart';
5+
6+
abstract class Annotation extends Equatable with DataPrinter {
7+
String toAnnotation();
8+
}
9+
10+
class JsonKeyItem extends Equatable with DataPrinter {
11+
final String? defaultValue;
12+
13+
final String? disallowNullValue;
14+
15+
final String? fromJson;
16+
17+
final String? ignore;
18+
19+
final String? includeIfNull;
20+
21+
final String? name;
22+
23+
final String? required;
24+
25+
final String? toJson;
26+
27+
final String? unknownEnumValue;
28+
29+
const JsonKeyItem({
30+
this.defaultValue,
31+
this.disallowNullValue,
32+
this.fromJson,
33+
this.ignore,
34+
this.includeIfNull,
35+
this.name,
36+
this.required,
37+
this.toJson,
38+
this.unknownEnumValue,
39+
});
40+
41+
@override
42+
Map<String, Object?> get namedProps {
43+
return {
44+
'defaultValue': defaultValue,
45+
'disallowNullValue': disallowNullValue,
46+
'fromJson': fromJson,
47+
'ignore': ignore,
48+
'includeIfNull': includeIfNull,
49+
'name': name,
50+
'required': required,
51+
'toJson': toJson,
52+
'unknownEnumValue': unknownEnumValue,
53+
};
54+
}
55+
56+
JsonKeyItem copyWith({
57+
String? defaultValue,
58+
String? disallowNullValue,
59+
String? fromJson,
60+
String? ignore,
61+
String? includeIfNull,
62+
String? name,
63+
String? required,
64+
String? toJson,
65+
String? unknownEnumValue,
66+
}) {
67+
return JsonKeyItem(
68+
defaultValue: defaultValue ?? this.defaultValue,
69+
disallowNullValue: disallowNullValue ?? this.disallowNullValue,
70+
fromJson: fromJson ?? this.fromJson,
71+
ignore: ignore ?? this.ignore,
72+
includeIfNull: includeIfNull ?? this.includeIfNull,
73+
name: name ?? this.name,
74+
required: required ?? this.required,
75+
toJson: toJson ?? this.toJson,
76+
unknownEnumValue: unknownEnumValue ?? this.unknownEnumValue,
77+
);
78+
}
79+
}
80+
81+
class StringAnnotation extends Annotation {
82+
final String name;
83+
84+
StringAnnotation({required this.name});
85+
86+
@override
87+
String toAnnotation() => name;
88+
89+
@override
90+
Map<String, Object?> get namedProps => {
91+
'name': name,
92+
};
93+
}
94+
95+
class OverrideAnnotation extends StringAnnotation {
96+
OverrideAnnotation() : super(name: 'override');
97+
}
98+
99+
class JsonKeyAnnotation extends Annotation {
100+
final JsonKeyItem jsonKey;
101+
102+
JsonKeyAnnotation({required this.jsonKey});
103+
104+
factory JsonKeyAnnotation.fromMap(Map<String, dynamic> jsonKeyAnnotation) {
105+
return JsonKeyAnnotation(
106+
jsonKey: JsonKeyItem(
107+
defaultValue: jsonKeyAnnotation['defaultValue'] as String?,
108+
disallowNullValue: jsonKeyAnnotation['disallowNullValue'] as String?,
109+
fromJson: jsonKeyAnnotation['fromJson'] as String?,
110+
ignore: jsonKeyAnnotation['ignore'] as String?,
111+
includeIfNull: jsonKeyAnnotation['includeIfNull'] as String?,
112+
name: jsonKeyAnnotation['name'] as String?,
113+
required: jsonKeyAnnotation['required'] as String?,
114+
toJson: jsonKeyAnnotation['toJson'] as String?,
115+
unknownEnumValue: jsonKeyAnnotation['unknownEnumValue'] as String?,
116+
),
117+
);
118+
}
119+
120+
@override
121+
String toAnnotation() {
122+
final jsonKeyAnnotation = <String, dynamic>{
123+
'disallowNullValue': jsonKey.disallowNullValue,
124+
'fromJson': jsonKey.fromJson,
125+
'ignore': jsonKey.ignore,
126+
'includeIfNull': jsonKey.includeIfNull,
127+
'name': jsonKey.name,
128+
'required': jsonKey.required,
129+
'toJson': jsonKey.toJson,
130+
'unknownEnumValue': jsonKey.unknownEnumValue
131+
};
132+
133+
final key = jsonKeyAnnotation.entries
134+
.map<String?>((e) {
135+
if (e.value != null) {
136+
switch (e.key) {
137+
case 'name':
138+
return '${e.key}: \'${e.value}\'';
139+
default:
140+
return '${e.key}: ${e.value}';
141+
}
142+
}
143+
144+
return null;
145+
})
146+
.whereType<String>()
147+
.join(', ');
148+
149+
return 'JsonKey($key)';
150+
}
151+
152+
@override
153+
Map<String, Object?> get namedProps {
154+
return {
155+
'jsonKey': jsonKey,
156+
};
157+
}
158+
}

lib/generator/data/class_property.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:artemis/generator/data/annotation.dart';
12
import 'package:artemis/generator/data/definition.dart';
23
import 'package:artemis/generator/data_printer.dart';
34
import 'package:artemis/generator/helpers.dart';
@@ -12,7 +13,7 @@ class ClassProperty extends Definition with DataPrinter {
1213
final TypeName type;
1314

1415
/// Some other custom annotation.
15-
final List<String> annotations;
16+
final List<Annotation> annotations;
1617

1718
/// Whether this parameter corresponds to the __resolveType (or equivalent)
1819
final bool isResolveType;
@@ -33,7 +34,7 @@ class ClassProperty extends Definition with DataPrinter {
3334
ClassProperty copyWith({
3435
TypeName? type,
3536
ClassPropertyName? name,
36-
List<String>? annotations,
37+
List<Annotation>? annotations,
3738
bool? isResolveType,
3839
}) =>
3940
ClassProperty(

lib/generator/data/enum_value_definition.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:artemis/generator/data/annotation.dart';
12
import 'package:artemis/generator/data/definition.dart';
23
import 'package:artemis/generator/data_printer.dart';
34
import 'package:recase/recase.dart';
@@ -8,7 +9,7 @@ class EnumValueDefinition extends Definition with DataPrinter {
89
final EnumValueName name;
910

1011
/// Some other custom annotation.
11-
final List<String> annotations;
12+
final List<Annotation> annotations;
1213

1314
/// Instantiate an enum value
1415
EnumValueDefinition({

lib/generator/data/query_input.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:artemis/generator/data/annotation.dart';
12
import 'package:artemis/generator/data/class_property.dart';
23
import 'package:artemis/generator/data/definition.dart';
34
import 'package:artemis/generator/data_printer.dart';
@@ -12,14 +13,14 @@ class QueryInput extends Definition with DataPrinter {
1213
final TypeName type;
1314

1415
/// Some other custom annotation.
15-
final List<String> annotations;
16+
final List<Annotation> annotations;
1617

1718
/// Instantiate an input parameter.
1819
QueryInput({
1920
required this.type,
2021
this.annotations = const [],
2122
required this.name,
22-
}) : assert(hasValue(type) && hasValue(name)),
23+
}) : assert(hasValue(type) && hasValue(name)),
2324
super(name: name);
2425

2526
@override

lib/generator/helpers.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:artemis/generator/data/annotation.dart';
12
import 'package:artemis/generator/ephemeral_data.dart';
23
import 'package:build/build.dart';
34
import 'package:collection/collection.dart' show IterableExtension;
@@ -136,10 +137,10 @@ bool hasValue(Object? obj) {
136137
}
137138

138139
/// Proceeds deprecated annotation
139-
List<String> proceedDeprecated(
140+
List<Annotation> proceedDeprecated(
140141
List<DirectiveNode>? directives,
141142
) {
142-
final annotations = <String>[];
143+
final annotations = <Annotation>[];
143144

144145
final deprecatedDirective = directives?.firstWhereOrNull(
145146
(directive) => directive.name.value == 'deprecated',
@@ -154,7 +155,7 @@ List<String> proceedDeprecated(
154155
? reasonValueNode.value
155156
: 'No longer supported';
156157

157-
annotations.add("Deprecated('$reason')");
158+
annotations.add(StringAnnotation(name: "Deprecated('$reason')"));
158159
}
159160

160161
return annotations;

0 commit comments

Comments
 (0)