From 228f09b75a13f9f1a115872e2fd4e2ebb039d973 Mon Sep 17 00:00:00 2001 From: Vinicius Salvati Melquiades Date: Sun, 7 Jun 2020 01:26:00 -0300 Subject: [PATCH 01/13] Enum values can now be marked as deprecated - Added an `annotations` field to the `EnumDefinition` - Added test for deprecated enum values - Made Artemis generate the `@deprecated` annotations in the code --- lib/generator.dart | 35 +++++- lib/generator/data/enum_definition.dart | 9 +- lib/generator/print_helpers.dart | 10 +- .../deprecated_enum_value_test.dart | 116 ++++++++++++++++++ 4 files changed, 166 insertions(+), 4 deletions(-) create mode 100644 test/query_generator/deprecated/deprecated_enum_value_test.dart diff --git a/lib/generator.dart b/lib/generator.dart index 8fccc500..1a5819ea 100644 --- a/lib/generator.dart +++ b/lib/generator.dart @@ -349,6 +349,28 @@ Make sure your query is correct and your schema is updated.'''); ); } +void _addDeprecatedAnnotationIfNecessary( + List annotations, + List directives, +) { + final deprecatedDirective = directives?.firstWhere( + (directive) => directive.name.value == 'deprecated', + orElse: () => null, + ); + + if (deprecatedDirective != null) { + final reasonValueNode = deprecatedDirective?.arguments + ?.firstWhere((argument) => argument.name.value == 'reason') + ?.value; + + final reason = reasonValueNode is StringValueNode + ? reasonValueNode.value + : 'No longer supported'; + + annotations.add("Deprecated('$reason')"); + } +} + class _GeneratorVisitor extends RecursiveVisitor { _GeneratorVisitor({ @required this.context, @@ -633,11 +655,20 @@ class _CanonicalVisitor extends RecursiveVisitor { enums.add(EnumDefinition( name: enumName, - values: node.values.map((eV) => EnumValue(name: eV.name.value)).toList() - ..add(ARTEMIS_UNKNOWN), + values: node.values.map(_getEnumValue).toList()..add(ARTEMIS_UNKNOWN), )); } + EnumValue _getEnumValue(EnumValueDefinitionNode enumValue) { + final annotations = []; + _addDeprecatedAnnotationIfNecessary(annotations, enumValue.directives); + + return EnumValue( + name: enumValue.name.value, + annotations: annotations, + ); + } + @override void visitInputObjectTypeDefinitionNode(InputObjectTypeDefinitionNode node) { final name = ClassName(name: node.name.value); diff --git a/lib/generator/data/enum_definition.dart b/lib/generator/data/enum_definition.dart index 56254285..e6067fbe 100644 --- a/lib/generator/data/enum_definition.dart +++ b/lib/generator/data/enum_definition.dart @@ -29,11 +29,18 @@ class EnumDefinition extends Definition with DataPrinter { /// Enum value name class EnumValue extends Name with DataPrinter { /// Instantiate a enum value name definition. - EnumValue({@required String name}) : super(name: name); + EnumValue({ + @required String name, + this.annotations = const [], + }) : super(name: name); + + /// Some other custom annotation. + final List annotations; @override Map get namedProps => { 'name': name, + 'annotations': annotations, }; @override diff --git a/lib/generator/print_helpers.dart b/lib/generator/print_helpers.dart index c9e2aa2b..6c672c60 100644 --- a/lib/generator/print_helpers.dart +++ b/lib/generator/print_helpers.dart @@ -8,9 +8,17 @@ import '../generator/helpers.dart'; /// Generates a [Spec] of a single enum definition. Spec enumDefinitionToSpec(EnumDefinition definition) => CodeExpression(Code('''enum ${definition.name.namePrintable} { - ${definition.values.removeDuplicatedBy((i) => i).map((v) => '@JsonValue("${v.name}")${v.namePrintable}, ').join()} + ${definition.values.removeDuplicatedBy((i) => i).map(_enumValueToSpec).join()} }''')); +String _enumValueToSpec(EnumValue value) { + final annotations = value.annotations + .map((annotation) => '@$annotation') + .followedBy(['@JsonValue("${value.name}")']).join(' '); + + return '$annotations${value.namePrintable}, '; +} + String _fromJsonBody(ClassDefinition definition) { final buffer = StringBuffer(); buffer.writeln( diff --git a/test/query_generator/deprecated/deprecated_enum_value_test.dart b/test/query_generator/deprecated/deprecated_enum_value_test.dart new file mode 100644 index 00000000..bf527d6f --- /dev/null +++ b/test/query_generator/deprecated/deprecated_enum_value_test.dart @@ -0,0 +1,116 @@ +import 'package:artemis/generator/data/data.dart'; +import 'package:gql/language.dart'; +import 'package:test/test.dart'; + +import '../../helpers.dart'; + +void main() { + group('On deprecated value', () { + print(libraryDefinition); + test( + 'Enum values can be deprecated', + () async => testGenerator( + query: query, + schema: r''' + schema { + query: QueryResponse + } + + type QueryResponse { + someValue: StarWarsMovies + } + + enum StarWarsMovies { + NEW_HOPE @deprecated(reason: "deprecated movie") + EMPIRE + JEDI + } + ''', + libraryDefinition: libraryDefinition, + generatedFile: generatedFile, + ), + ); + }); +} + +const query = r''' + query some_query { + someValue + } +'''; + +final LibraryDefinition libraryDefinition = + LibraryDefinition(basename: r'query.graphql', queries: [ + QueryDefinition( + document: parseString(query), + name: QueryName(name: r'SomeQuery$_QueryResponse'), + operationName: 'some_query', + classes: [ + EnumDefinition( + name: EnumName(name: r'StarWarsMovies'), + values: [ + EnumValue( + name: 'NEW_HOPE', + annotations: [ + r"Deprecated('deprecated movie')", + ], + ), + EnumValue(name: 'EMPIRE'), + EnumValue(name: 'JEDI'), + EnumValue(name: 'ARTEMIS_UNKNOWN'), + ], + ), + ClassDefinition( + name: ClassName(name: r'SomeQuery$_QueryResponse'), + properties: [ + ClassProperty( + type: TypeName(name: r'StarWarsMovies'), + name: ClassPropertyName(name: r'someValue'), + // isOverride: false, + isNonNull: false, + annotations: [ + r'JsonKey(unknownEnumValue: StarWarsMovies.artemisUnknown)', + ]) + ], + factoryPossibilities: {}, + typeNameField: TypeName(name: r'__typename'), + isInput: false) + ], + generateHelpers: false, + suffix: r'Query') +]); + +const generatedFile = r'''// GENERATED CODE - DO NOT MODIFY BY HAND + +import 'package:json_annotation/json_annotation.dart'; +import 'package:equatable/equatable.dart'; +import 'package:gql/ast.dart'; +part 'query.graphql.g.dart'; + +@JsonSerializable(explicitToJson: true) +class SomeQuery$QueryResponse with EquatableMixin { + SomeQuery$QueryResponse(); + + factory SomeQuery$QueryResponse.fromJson(Map json) => + _$SomeQuery$QueryResponseFromJson(json); + + @JsonKey(unknownEnumValue: StarWarsMovies.artemisUnknown) + StarWarsMovies someValue; + + @override + List get props => [someValue]; + Map toJson() => _$SomeQuery$QueryResponseToJson(this); +} + +enum StarWarsMovies { + @Deprecated('deprecated movie') + @JsonValue("NEW_HOPE") + newHope, + @JsonValue("EMPIRE") + empire, + @JsonValue("JEDI") + jedi, + @JsonValue("ARTEMIS_UNKNOWN") + artemisUnknown, +} +'''; From ba2ea608d44d8d1c2c0caf22eb4c529dd85be091 Mon Sep 17 00:00:00 2001 From: Vinicius Salvati Melquiades Date: Tue, 9 Jun 2020 18:58:32 -0300 Subject: [PATCH 02/13] Added tests for deprecated fields in types So I can implement and test the deprecated fields correctly, I've created tests for some cases. None of them pass yet. - Added tests for fields of types - Added tests for fields of interfaces - Added tests for fields of input types --- .../deprecated/deprecated_field_test.dart | 178 +++++++++++ .../deprecated_input_object_field_test.dart | 234 ++++++++++++++ .../deprecated_interface_field_test.dart | 296 ++++++++++++++++++ 3 files changed, 708 insertions(+) create mode 100644 test/query_generator/deprecated/deprecated_field_test.dart create mode 100644 test/query_generator/deprecated/deprecated_input_object_field_test.dart create mode 100644 test/query_generator/deprecated/deprecated_interface_field_test.dart diff --git a/test/query_generator/deprecated/deprecated_field_test.dart b/test/query_generator/deprecated/deprecated_field_test.dart new file mode 100644 index 00000000..e75acc36 --- /dev/null +++ b/test/query_generator/deprecated/deprecated_field_test.dart @@ -0,0 +1,178 @@ +import 'package:artemis/generator/data/data.dart'; +import 'package:gql/language.dart'; +import 'package:test/test.dart'; + +import '../../helpers.dart'; + +void main() { + group('On deprecated', () { + test( + 'Fields can be deprecated', + () async => testGenerator( + query: query, + schema: r''' + schema { + query: QueryResponse + } + + type QueryResponse { + someObject: SomeObject @deprecated(reason: "message") + someObjects: [SomeObject] + } + + type SomeObject { + someField: String + deprecatedField: String @deprecated(reason: "message 2") + } + ''', + libraryDefinition: libraryDefinition, + generatedFile: generatedFile, + ), + ); + }); +} + +const query = r''' + query some_query { + deprecatedObject: someObject { + someField + deprecatedField + } + someObjects { + someField + deprecatedField + } + } +'''; + +final LibraryDefinition libraryDefinition = + LibraryDefinition(basename: r'query.graphql', queries: [ + QueryDefinition( + document: parseString(query), + operationName: r'some_query', + name: QueryName(name: r'SomeQuery$_QueryResponse'), + classes: [ + ClassDefinition( + name: ClassName(name: r'SomeQuery$_QueryResponse$_deprecatedObject'), + properties: [ + ClassProperty( + type: TypeName(name: r'String'), + name: ClassPropertyName(name: r'someField'), + isNonNull: false, + ), + ClassProperty( + type: TypeName(name: r'String'), + name: ClassPropertyName(name: r'deprecatedField'), + isNonNull: false, + annotations: [r"Deprecated('message 2')"], + ), + ], + factoryPossibilities: {}, + typeNameField: TypeName(name: r'__typename'), + isInput: false, + ), + ClassDefinition( + name: ClassName(name: r'SomeQuery$_QueryResponse$_SomeObject'), + properties: [ + ClassProperty( + type: TypeName(name: r'String'), + name: ClassPropertyName(name: r'someField'), + isNonNull: false, + ), + ClassProperty( + type: TypeName(name: r'String'), + name: ClassPropertyName(name: r'deprecatedField'), + isNonNull: false, + annotations: [r"Deprecated('message 2')"], + ), + ], + factoryPossibilities: {}, + typeNameField: TypeName(name: r'__typename'), + isInput: false, + ), + ClassDefinition( + name: ClassName(name: r'SomeQuery$_QueryResponse'), + properties: [ + ClassProperty( + type: TypeName(name: r'SomeQuery$QueryResponse$DeprecatedObject'), + name: ClassPropertyName(name: r'deprecatedObject'), + isNonNull: false, + annotations: [r"Deprecated('message')"], + ), + ClassProperty( + type: TypeName(name: r'List'), + name: ClassPropertyName(name: r'someObjects'), + isNonNull: false, + ) + ], + factoryPossibilities: {}, + typeNameField: TypeName(name: r'__typename'), + isInput: false, + ) + ], + generateHelpers: false, + suffix: r'Query') +]); + +const generatedFile = r'''// GENERATED CODE - DO NOT MODIFY BY HAND + +import 'package:json_annotation/json_annotation.dart'; +import 'package:equatable/equatable.dart'; +import 'package:gql/ast.dart'; +part 'query.graphql.g.dart'; + +@JsonSerializable(explicitToJson: true) +class SomeQuery$QueryResponse$DeprecatedObject with EquatableMixin { + SomeQuery$QueryResponse$DeprecatedObject(); + + factory SomeQuery$QueryResponse$DeprecatedObject.fromJson( + Map json) => + _$SomeQuery$QueryResponse$DeprecatedObjectFromJson(json); + + String someField; + + @Deprecated('message 2') + String deprecatedField; + + @override + List get props => [someField, deprecatedField]; + Map toJson() => + _$SomeQuery$QueryResponse$DeprecatedObjectToJson(this); +} + +@JsonSerializable(explicitToJson: true) +class SomeQuery$QueryResponse$SomeObject with EquatableMixin { + SomeQuery$QueryResponse$SomeObject(); + + factory SomeQuery$QueryResponse$SomeObject.fromJson( + Map json) => + _$SomeQuery$QueryResponse$SomeObjectFromJson(json); + + String someField; + + @Deprecated('message 2') + String deprecatedField; + + @override + List get props => [someField, deprecatedField]; + Map toJson() => + _$SomeQuery$QueryResponse$SomeObjectToJson(this); +} + +@JsonSerializable(explicitToJson: true) +class SomeQuery$QueryResponse with EquatableMixin { + SomeQuery$QueryResponse(); + + factory SomeQuery$QueryResponse.fromJson(Map json) => + _$SomeQuery$QueryResponseFromJson(json); + + @Deprecated('message') + SomeQuery$QueryResponse$DeprecatedObject deprecatedObject; + + List someObjects; + + @override + List get props => [deprecatedObject, someObjects]; + Map toJson() => _$SomeQuery$QueryResponseToJson(this); +} +'''; diff --git a/test/query_generator/deprecated/deprecated_input_object_field_test.dart b/test/query_generator/deprecated/deprecated_input_object_field_test.dart new file mode 100644 index 00000000..b3297eb4 --- /dev/null +++ b/test/query_generator/deprecated/deprecated_input_object_field_test.dart @@ -0,0 +1,234 @@ +import 'package:artemis/generator/data/data.dart'; +import 'package:test/test.dart'; + +import '../../helpers.dart'; + +void main() { + group('On mutations', () { + test( + 'The mutation class will be suffixed as Mutation', + () async => testGenerator( + query: query, + schema: r''' + schema { + mutation: MutationRoot + } + + type MutationRoot { + mut(input: Input!): MutationResponse + } + + type MutationResponse { + s: String + } + + input Input { + s: String! + d: String @deprecated(reason: "deprecated input field") + } + ''', + libraryDefinition: libraryDefinition, + generatedFile: generatedFile, + generateHelpers: true, + ), + ); + }); +} + +const query = r''' +mutation custom($input: Input!) { + mut(input: $input) { + s + } +} +'''; + +final LibraryDefinition libraryDefinition = LibraryDefinition( + basename: r'query.graphql', + queries: [ + QueryDefinition( + operationName: r'custom', + name: QueryName(name: r'Custom$_MutationRoot'), + classes: [ + ClassDefinition( + name: ClassName(name: r'Custom$_MutationRoot$_MutationResponse'), + properties: [ + ClassProperty( + type: TypeName(name: r'String'), + name: ClassPropertyName(name: r's'), + isNonNull: false, + ), + ], + factoryPossibilities: {}, + typeNameField: TypeName(name: r'__typename'), + isInput: false, + ), + ClassDefinition( + name: ClassName(name: r'Custom$_MutationRoot'), + properties: [ + ClassProperty( + type: TypeName(name: r'Custom$MutationRoot$MutationResponse'), + name: ClassPropertyName(name: r'mut'), + isNonNull: false, + ), + ], + factoryPossibilities: {}, + typeNameField: TypeName(name: r'__typename'), + isInput: false, + ), + ClassDefinition( + name: ClassName(name: r'Input'), + properties: [ + ClassProperty( + type: TypeName(name: r'String'), + name: ClassPropertyName(name: r's'), + isNonNull: true, + ), + ClassProperty( + type: TypeName(name: r'String'), + name: ClassPropertyName(name: r'd'), + isNonNull: false, + annotations: [ + r"Deprecated('deprecated input field')", + ], + ), + ], + factoryPossibilities: {}, + typeNameField: TypeName(name: r'__typename'), + isInput: true, + ), + ], + inputs: [ + QueryInput( + type: TypeName(name: r'Input'), + name: QueryInputName(name: r'input'), + isNonNull: true, + ), + ], + generateHelpers: true, + suffix: r'Mutation', + ), + ], +); + +const generatedFile = r'''// GENERATED CODE - DO NOT MODIFY BY HAND + +import 'package:meta/meta.dart'; +import 'package:artemis/artemis.dart'; +import 'package:json_annotation/json_annotation.dart'; +import 'package:equatable/equatable.dart'; +import 'package:gql/ast.dart'; +part 'query.graphql.g.dart'; + +@JsonSerializable(explicitToJson: true) +class Custom$MutationRoot$MutationResponse with EquatableMixin { + Custom$MutationRoot$MutationResponse(); + + factory Custom$MutationRoot$MutationResponse.fromJson( + Map json) => + _$Custom$MutationRoot$MutationResponseFromJson(json); + + String s; + + @override + List get props => [s]; + Map toJson() => + _$Custom$MutationRoot$MutationResponseToJson(this); +} + +@JsonSerializable(explicitToJson: true) +class Custom$MutationRoot with EquatableMixin { + Custom$MutationRoot(); + + factory Custom$MutationRoot.fromJson(Map json) => + _$Custom$MutationRootFromJson(json); + + Custom$MutationRoot$MutationResponse mut; + + @override + List get props => [mut]; + Map toJson() => _$Custom$MutationRootToJson(this); +} + +@JsonSerializable(explicitToJson: true) +class Input with EquatableMixin { + Input({@required this.s, this.d}); + + factory Input.fromJson(Map json) => _$InputFromJson(json); + + String s; + + @Deprecated('deprecated input field') + String d; + + @override + List get props => [s, d]; + Map toJson() => _$InputToJson(this); +} + +@JsonSerializable(explicitToJson: true) +class CustomArguments extends JsonSerializable with EquatableMixin { + CustomArguments({@required this.input}); + + factory CustomArguments.fromJson(Map json) => + _$CustomArgumentsFromJson(json); + + final Input input; + + @override + List get props => [input]; + Map toJson() => _$CustomArgumentsToJson(this); +} + +class CustomMutation + extends GraphQLQuery { + CustomMutation({this.variables}); + + @override + final DocumentNode document = DocumentNode(definitions: [ + OperationDefinitionNode( + type: OperationType.mutation, + name: NameNode(value: 'custom'), + variableDefinitions: [ + VariableDefinitionNode( + variable: VariableNode(name: NameNode(value: 'input')), + type: NamedTypeNode( + name: NameNode(value: 'Input'), isNonNull: true), + defaultValue: DefaultValueNode(value: null), + directives: []) + ], + directives: [], + selectionSet: SelectionSetNode(selections: [ + FieldNode( + name: NameNode(value: 'mut'), + alias: null, + arguments: [ + ArgumentNode( + name: NameNode(value: 'input'), + value: VariableNode(name: NameNode(value: 'input'))) + ], + directives: [], + selectionSet: SelectionSetNode(selections: [ + FieldNode( + name: NameNode(value: 's'), + alias: null, + arguments: [], + directives: [], + selectionSet: null) + ])) + ])) + ]); + + @override + final String operationName = 'custom'; + + @override + final CustomArguments variables; + + @override + List get props => [document, operationName, variables]; + @override + Custom$MutationRoot parse(Map json) => + Custom$MutationRoot.fromJson(json); +} +'''; diff --git a/test/query_generator/deprecated/deprecated_interface_field_test.dart b/test/query_generator/deprecated/deprecated_interface_field_test.dart new file mode 100644 index 00000000..40a43f1f --- /dev/null +++ b/test/query_generator/deprecated/deprecated_interface_field_test.dart @@ -0,0 +1,296 @@ +import 'package:artemis/generator/data/data.dart'; +import 'package:test/test.dart'; + +import '../../helpers.dart'; + +void main() { + group('On interfaces', () { + test( + 'On interfaces', + () async => testGenerator( + query: query, + schema: graphQLSchema, + libraryDefinition: libraryDefinition, + generatedFile: generatedFile, + ), + ); + }); +} + +const query = r''' + query custom($id: ID!) { + nodeById(id: $id) { + id + deprecatedField + ... on User { + ...UserFrag + } + ... on ChatMessage { + message + user { + ...UserFrag + } + } + } + } + + fragment UserFrag on User { + id + username + } +'''; + +// https://graphql-code-generator.com/#live-demo +final String graphQLSchema = r''' + scalar String + scalar ID + + schema { + query: Query + } + + type Query { + nodeById(id: ID!): Node + } + + interface Node { + id: ID! + deprecatedField: String @deprecated(reason: "deprecated interface field") + } + + type User implements Node { + id: ID! + username: String! + deprecatedField: String + } + + type ChatMessage implements Node { + id: ID! + message: String! + user: User! + } +'''; + +final LibraryDefinition libraryDefinition = LibraryDefinition( + basename: r'query.graphql', + queries: [ + QueryDefinition( + operationName: r'custom', + name: QueryName(name: r'Custom$_Query'), + classes: [ + ClassDefinition( + name: ClassName(name: r'Custom$_Query$_Node$_User'), + extension: ClassName(name: r'Custom$_Query$_Node'), + mixins: [FragmentName(name: r'UserFragMixin')], + factoryPossibilities: {}, + typeNameField: TypeName(name: r'__typename'), + isInput: false, + ), + ClassDefinition( + name: ClassName(name: r'Custom$_Query$_Node$_ChatMessage$_User'), + extension: ClassName(name: r'Custom$_Query$_Node$_ChatMessage'), + mixins: [FragmentName(name: r'UserFragMixin')], + factoryPossibilities: {}, + typeNameField: TypeName(name: r'__typename'), + isInput: false, + ), + ClassDefinition( + name: ClassName(name: r'Custom$_Query$_Node$_ChatMessage'), + properties: [ + ClassProperty( + type: TypeName(name: r'String'), + name: ClassPropertyName(name: r'message'), + isNonNull: true, + isResolveType: false, + ), + ClassProperty( + type: TypeName(name: r'Custom$Query$Node$ChatMessage$User'), + name: ClassPropertyName(name: r'user'), + isNonNull: true, + isResolveType: false, + ) + ], + extension: ClassName(name: r'Custom$_Query$_Node'), + factoryPossibilities: {}, + typeNameField: TypeName(name: r'__typename'), + isInput: false, + ), + ClassDefinition( + name: ClassName(name: r'Custom$_Query$_Node'), + properties: [ + ClassProperty( + type: TypeName(name: r'String'), + name: ClassPropertyName(name: r'id'), + isNonNull: true, + isResolveType: false, + ), + ClassProperty( + type: TypeName(name: r'String'), + name: ClassPropertyName(name: r'deprecatedField'), + isNonNull: false, + isResolveType: false, + annotations: [ + "Deprecated('deprecated interface field')", + ], + ), + ], + factoryPossibilities: { + r'User': ClassName(name: r'Custom$_Query$_Node$_User'), + r'ChatMessage': ClassName(name: r'Custom$_Query$_Node$_ChatMessage') + }, + typeNameField: TypeName(name: r'__typename'), + isInput: false, + ), + ClassDefinition( + name: ClassName(name: r'Custom$_Query'), + properties: [ + ClassProperty( + type: TypeName(name: r'Custom$Query$Node'), + name: ClassPropertyName(name: r'nodeById'), + isNonNull: false, + isResolveType: false, + ), + ], + factoryPossibilities: {}, + typeNameField: TypeName(name: r'__typename'), + isInput: false, + ), + FragmentClassDefinition( + name: FragmentName( + name: r'UserFragMixin', + ), + properties: [ + ClassProperty( + type: TypeName(name: r'String'), + name: ClassPropertyName(name: r'id'), + isNonNull: true, + isResolveType: false, + ), + ClassProperty( + type: TypeName(name: r'String'), + name: ClassPropertyName(name: r'username'), + isNonNull: true, + isResolveType: false, + ), + ], + ) + ], + inputs: [ + QueryInput( + type: TypeName(name: r'String'), + name: QueryInputName(name: r'id'), + isNonNull: true, + ), + ], + generateHelpers: false, + suffix: r'Query', + ) + ], +); + +const generatedFile = r'''// GENERATED CODE - DO NOT MODIFY BY HAND + +import 'package:meta/meta.dart'; +import 'package:json_annotation/json_annotation.dart'; +import 'package:equatable/equatable.dart'; +import 'package:gql/ast.dart'; +part 'query.graphql.g.dart'; + +mixin UserFragMixin { + String id; + String username; +} + +@JsonSerializable(explicitToJson: true) +class Custom$Query$Node$User extends Custom$Query$Node + with EquatableMixin, UserFragMixin { + Custom$Query$Node$User(); + + factory Custom$Query$Node$User.fromJson(Map json) => + _$Custom$Query$Node$UserFromJson(json); + + @override + List get props => [id, username]; + Map toJson() => _$Custom$Query$Node$UserToJson(this); +} + +@JsonSerializable(explicitToJson: true) +class Custom$Query$Node$ChatMessage$User extends Custom$Query$Node$ChatMessage + with EquatableMixin, UserFragMixin { + Custom$Query$Node$ChatMessage$User(); + + factory Custom$Query$Node$ChatMessage$User.fromJson( + Map json) => + _$Custom$Query$Node$ChatMessage$UserFromJson(json); + + @override + List get props => [id, username]; + Map toJson() => + _$Custom$Query$Node$ChatMessage$UserToJson(this); +} + +@JsonSerializable(explicitToJson: true) +class Custom$Query$Node$ChatMessage extends Custom$Query$Node + with EquatableMixin { + Custom$Query$Node$ChatMessage(); + + factory Custom$Query$Node$ChatMessage.fromJson(Map json) => + _$Custom$Query$Node$ChatMessageFromJson(json); + + String message; + + Custom$Query$Node$ChatMessage$User user; + + @override + List get props => [message, user]; + Map toJson() => _$Custom$Query$Node$ChatMessageToJson(this); +} + +@JsonSerializable(explicitToJson: true) +class Custom$Query$Node with EquatableMixin { + Custom$Query$Node(); + + factory Custom$Query$Node.fromJson(Map json) { + switch (json['__typename'].toString()) { + case r'User': + return Custom$Query$Node$User.fromJson(json); + case r'ChatMessage': + return Custom$Query$Node$ChatMessage.fromJson(json); + default: + } + return _$Custom$Query$NodeFromJson(json); + } + + String id; + + @Deprecated('deprecated interface field') + String deprecatedField; + + @override + List get props => [id, deprecatedField]; + Map toJson() { + switch ($$typename) { + case r'User': + return (this as Custom$Query$Node$User).toJson(); + case r'ChatMessage': + return (this as Custom$Query$Node$ChatMessage).toJson(); + default: + } + return _$Custom$Query$NodeToJson(this); + } +} + +@JsonSerializable(explicitToJson: true) +class Custom$Query with EquatableMixin { + Custom$Query(); + + factory Custom$Query.fromJson(Map json) => + _$Custom$QueryFromJson(json); + + Custom$Query$Node nodeById; + + @override + List get props => [nodeById]; + Map toJson() => _$Custom$QueryToJson(this); +} +'''; From 847ed7c380a409a17391a0a589c116a5f903aae5 Mon Sep 17 00:00:00 2001 From: Vinicius Salvati Melquiades Date: Tue, 9 Jun 2020 21:58:02 -0300 Subject: [PATCH 03/13] Nullable fields Now fields in types, interfaces and input types that are marked as deprecated will have dart code generated with the `@Deprecated` annotation. --- lib/generator.dart | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/generator.dart b/lib/generator.dart index 1a5819ea..70ebb0ff 100644 --- a/lib/generator.dart +++ b/lib/generator.dart @@ -341,6 +341,11 @@ Make sure your query is correct and your schema is updated.'''); annotations.add('JsonKey(name: \'${name.name}\')'); } + final fieldDirectives = + regularField?.directives ?? regularInputField?.directives; + + _addDeprecatedAnnotationIfNecessary(annotations, fieldDirectives); + return ClassProperty( type: dartTypeName, name: name, From 461de5b7050d17f89995c27c6c2e7be5feb5f084 Mon Sep 17 00:00:00 2001 From: Vinicius Salvati Melquiades Date: Thu, 2 Jul 2020 10:23:39 -0300 Subject: [PATCH 04/13] Made the code in generator.dart easier to read --- lib/generator.dart | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/lib/generator.dart b/lib/generator.dart index 70ebb0ff..40d13a08 100644 --- a/lib/generator.dart +++ b/lib/generator.dart @@ -344,7 +344,7 @@ Make sure your query is correct and your schema is updated.'''); final fieldDirectives = regularField?.directives ?? regularInputField?.directives; - _addDeprecatedAnnotationIfNecessary(annotations, fieldDirectives); + annotations.addAll(_proceedDeprecated(fieldDirectives)); return ClassProperty( type: dartTypeName, @@ -354,10 +354,11 @@ Make sure your query is correct and your schema is updated.'''); ); } -void _addDeprecatedAnnotationIfNecessary( - List annotations, +List _proceedDeprecated( List directives, ) { + final annotations = []; + final deprecatedDirective = directives?.firstWhere( (directive) => directive.name.value == 'deprecated', orElse: () => null, @@ -374,6 +375,8 @@ void _addDeprecatedAnnotationIfNecessary( annotations.add("Deprecated('$reason')"); } + + return annotations; } class _GeneratorVisitor extends RecursiveVisitor { @@ -660,20 +663,16 @@ class _CanonicalVisitor extends RecursiveVisitor { enums.add(EnumDefinition( name: enumName, - values: node.values.map(_getEnumValue).toList()..add(ARTEMIS_UNKNOWN), + values: node.values + .map((ev) => EnumValue( + name: ev.name.value, + annotations: _proceedDeprecated(ev.directives), + )) + .toList() + ..add(ARTEMIS_UNKNOWN), )); } - EnumValue _getEnumValue(EnumValueDefinitionNode enumValue) { - final annotations = []; - _addDeprecatedAnnotationIfNecessary(annotations, enumValue.directives); - - return EnumValue( - name: enumValue.name.value, - annotations: annotations, - ); - } - @override void visitInputObjectTypeDefinitionNode(InputObjectTypeDefinitionNode node) { final name = ClassName(name: node.name.value); From ff92a159dad6c81c45e1b0850043a26a81abbf69 Mon Sep 17 00:00:00 2001 From: Vinicius Salvati Melquiades Date: Thu, 2 Jul 2020 11:31:20 -0300 Subject: [PATCH 05/13] Separaated the EnumValue into EnumValueDefinition and EnumValueName - The EnumValueDefinition will hold the EnumValueName and a list of annotations - The EnumValueName will be only the name - Updated all the references to the EnumValue --- lib/generator.dart | 13 +++-- lib/generator/data/enum_definition.dart | 27 +---------- lib/generator/data/enum_value_definition.dart | 42 ++++++++++++++++ lib/generator/print_helpers.dart | 7 +-- test/generator/print_helpers_test.dart | 41 +++++++++++----- .../aliases/alias_on_leaves_test.dart | 13 +++-- .../deprecated_enum_value_test.dart | 17 +++++-- .../deprecated/deprecated_field_test.dart | 3 +- .../deprecated_input_object_field_test.dart | 2 +- .../deprecated_interface_field_test.dart | 4 +- .../enums/enum_duplication_test.dart | 27 ++++++++--- .../query_generator/enums/enum_list_test.dart | 14 ++++-- .../enums/filter_enum_test.dart | 48 ++++++++++++++----- .../enums/input_enum_test.dart | 27 ++++++++--- .../enums/query_enum_test.dart | 14 ++++-- .../complex_input_objects_test.dart | 13 +++-- .../naming/casing_conversion_test.dart | 21 ++++++-- 17 files changed, 240 insertions(+), 93 deletions(-) create mode 100644 lib/generator/data/enum_value_definition.dart diff --git a/lib/generator.dart b/lib/generator.dart index 40d13a08..9630f5c6 100644 --- a/lib/generator.dart +++ b/lib/generator.dart @@ -1,4 +1,5 @@ import 'package:artemis/generator/data/data.dart'; +import 'package:artemis/generator/data/enum_value_definition.dart'; import 'package:build/build.dart'; import 'package:meta/meta.dart'; import 'package:gql/ast.dart'; @@ -19,7 +20,9 @@ void _log(Context context, int align, Object logObject) { } /// Enum value for values not mapped in the GraphQL enum -final EnumValue ARTEMIS_UNKNOWN = EnumValue(name: 'ARTEMIS_UNKNOWN'); +final EnumValueDefinition ARTEMIS_UNKNOWN = EnumValueDefinition( + name: EnumValueName(name: 'ARTEMIS_UNKNOWN'), +); /// Generate queries definitions from a GraphQL schema and a list of queries, /// given Artemis options and schema mappings. @@ -331,7 +334,7 @@ Make sure your query is correct and your schema is updated.'''); if (fieldType is! ListTypeNode) { annotations.add( - 'JsonKey(unknownEnumValue: ${dartTypeName.namePrintable}.${ARTEMIS_UNKNOWN.namePrintable})'); + 'JsonKey(unknownEnumValue: ${dartTypeName.namePrintable}.${ARTEMIS_UNKNOWN.name.namePrintable})'); } } @@ -527,7 +530,7 @@ class _GeneratorVisitor extends RecursiveVisitor { context.usedEnums.add(EnumName(name: leafType.name.value)); if (leafType is! ListTypeNode) { annotations.add( - 'JsonKey(unknownEnumValue: ${EnumName(name: dartTypeName.name).namePrintable}.${ARTEMIS_UNKNOWN.namePrintable})'); + 'JsonKey(unknownEnumValue: ${EnumName(name: dartTypeName.name).namePrintable}.${ARTEMIS_UNKNOWN.name.namePrintable})'); } } else if (leafType is InputObjectTypeDefinitionNode) { addUsedInputObjectsAndEnums(leafType); @@ -664,8 +667,8 @@ class _CanonicalVisitor extends RecursiveVisitor { enums.add(EnumDefinition( name: enumName, values: node.values - .map((ev) => EnumValue( - name: ev.name.value, + .map((ev) => EnumValueDefinition( + name: EnumValueName(name: ev.name.value), annotations: _proceedDeprecated(ev.directives), )) .toList() diff --git a/lib/generator/data/enum_definition.dart b/lib/generator/data/enum_definition.dart index e6067fbe..65e2cd4c 100644 --- a/lib/generator/data/enum_definition.dart +++ b/lib/generator/data/enum_definition.dart @@ -1,8 +1,8 @@ import 'package:artemis/generator/data/definition.dart'; +import 'package:artemis/generator/data/enum_value_definition.dart'; import 'package:artemis/generator/data_printer.dart'; import 'package:artemis/generator/helpers.dart'; import 'package:meta/meta.dart'; -import 'package:recase/recase.dart'; /// Define a Dart enum parsed from GraphQL schema. class EnumDefinition extends Definition with DataPrinter { @@ -10,7 +10,7 @@ class EnumDefinition extends Definition with DataPrinter { final EnumName name; /// The possible values of this enum. - final Iterable values; + final Iterable values; /// Instantiate an enum definition. EnumDefinition({ @@ -26,29 +26,6 @@ class EnumDefinition extends Definition with DataPrinter { }; } -/// Enum value name -class EnumValue extends Name with DataPrinter { - /// Instantiate a enum value name definition. - EnumValue({ - @required String name, - this.annotations = const [], - }) : super(name: name); - - /// Some other custom annotation. - final List annotations; - - @override - Map get namedProps => { - 'name': name, - 'annotations': annotations, - }; - - @override - String normalize(String name) { - return ReCase(super.normalize(name)).camelCase; - } -} - /// Enum name class EnumName extends Name with DataPrinter { /// Instantiate a enum name definition. diff --git a/lib/generator/data/enum_value_definition.dart b/lib/generator/data/enum_value_definition.dart new file mode 100644 index 00000000..df87bb23 --- /dev/null +++ b/lib/generator/data/enum_value_definition.dart @@ -0,0 +1,42 @@ +import 'package:artemis/generator/data/definition.dart'; +import 'package:artemis/generator/data_printer.dart'; +import 'package:artemis/generator/helpers.dart'; +import 'package:meta/meta.dart'; +import 'package:recase/recase.dart'; + +/// Enum value +class EnumValueDefinition extends Definition with DataPrinter { + @override + final EnumValueName name; + + /// Some other custom annotation. + final List annotations; + + /// Instantiate an enum value + EnumValueDefinition({ + @required this.name, + this.annotations = const [], + }); + + @override + Map get namedProps => { + 'name': name, + 'annotations': annotations, + }; +} + +/// Enum value name +class EnumValueName extends Name with DataPrinter { + /// Instantiate a enum value name definition. + EnumValueName({@required String name}) : super(name: name); + + @override + Map get namedProps => { + 'name': name, + }; + + @override + String normalize(String name) { + return ReCase(super.normalize(name)).camelCase; + } +} diff --git a/lib/generator/print_helpers.dart b/lib/generator/print_helpers.dart index 6c672c60..57c2a1d2 100644 --- a/lib/generator/print_helpers.dart +++ b/lib/generator/print_helpers.dart @@ -1,4 +1,5 @@ import 'package:artemis/generator/data/data.dart'; +import 'package:artemis/generator/data/enum_value_definition.dart'; import 'package:code_builder/code_builder.dart'; import 'package:dart_style/dart_style.dart'; import 'package:gql_code_gen/gql_code_gen.dart' as dart; @@ -11,12 +12,12 @@ Spec enumDefinitionToSpec(EnumDefinition definition) => ${definition.values.removeDuplicatedBy((i) => i).map(_enumValueToSpec).join()} }''')); -String _enumValueToSpec(EnumValue value) { +String _enumValueToSpec(EnumValueDefinition value) { final annotations = value.annotations .map((annotation) => '@$annotation') - .followedBy(['@JsonValue("${value.name}")']).join(' '); + .followedBy(['@JsonValue("${value.name.name}")']).join(' '); - return '$annotations${value.namePrintable}, '; + return '$annotations${value.name.namePrintable}, '; } String _fromJsonBody(ClassDefinition definition) { diff --git a/test/generator/print_helpers_test.dart b/test/generator/print_helpers_test.dart index f3136e92..e5352f4d 100644 --- a/test/generator/print_helpers_test.dart +++ b/test/generator/print_helpers_test.dart @@ -1,4 +1,5 @@ import 'package:artemis/generator/data/data.dart'; +import 'package:artemis/generator/data/enum_value_definition.dart'; import 'package:artemis/generator/print_helpers.dart'; import 'package:gql/language.dart'; import 'package:test/test.dart'; @@ -27,10 +28,18 @@ void main() { test('It will generate an Enum declaration.', () { final definition = EnumDefinition(name: EnumName(name: 'Name'), values: [ - EnumValue(name: 'Option'), - EnumValue(name: 'anotherOption'), - EnumValue(name: 'third_option'), - EnumValue(name: 'FORTH_OPTION'), + EnumValueDefinition( + name: EnumValueName(name: 'Option'), + ), + EnumValueDefinition( + name: EnumValueName(name: 'anotherOption'), + ), + EnumValueDefinition( + name: EnumValueName(name: 'third_option'), + ), + EnumValueDefinition( + name: EnumValueName(name: 'FORTH_OPTION'), + ), ]); final str = specToString(enumDefinitionToSpec(definition)); @@ -50,10 +59,18 @@ void main() { test('It will ignore duplicate options.', () { final definition = EnumDefinition(name: EnumName(name: 'Name'), values: [ - EnumValue(name: 'Option'), - EnumValue(name: 'AnotherOption'), - EnumValue(name: 'Option'), - EnumValue(name: 'AnotherOption'), + EnumValueDefinition( + name: EnumValueName(name: 'Option'), + ), + EnumValueDefinition( + name: EnumValueName(name: 'AnotherOption'), + ), + EnumValueDefinition( + name: EnumValueName(name: 'Option'), + ), + EnumValueDefinition( + name: EnumValueName(name: 'AnotherOption'), + ), ]); final str = specToString(enumDefinitionToSpec(definition)); @@ -637,9 +654,11 @@ class TestQueryArguments extends JsonSerializable with EquatableMixin { operationName: 'test_query', document: parseString('query test_query {}'), classes: [ - EnumDefinition( - name: EnumName(name: 'Enum'), - values: [EnumValue(name: 'Value')]), + EnumDefinition(name: EnumName(name: 'Enum'), values: [ + EnumValueDefinition( + name: EnumValueName(name: 'Value'), + ) + ]), ClassDefinition(name: ClassName(name: 'AClass'), properties: []) ], ), diff --git a/test/query_generator/aliases/alias_on_leaves_test.dart b/test/query_generator/aliases/alias_on_leaves_test.dart index 30e17273..e04541c4 100644 --- a/test/query_generator/aliases/alias_on_leaves_test.dart +++ b/test/query_generator/aliases/alias_on_leaves_test.dart @@ -1,4 +1,5 @@ import 'package:artemis/generator/data/data.dart'; +import 'package:artemis/generator/data/enum_value_definition.dart'; import 'package:test/test.dart'; import '../../helpers.dart'; @@ -52,9 +53,15 @@ final LibraryDefinition libraryDefinition = operationName: r'some_query', classes: [ EnumDefinition(name: EnumName(name: r'MyEnum'), values: [ - EnumValue(name: r'A'), - EnumValue(name: r'B'), - EnumValue(name: r'ARTEMIS_UNKNOWN') + EnumValueDefinition( + name: EnumValueName(name: r'A'), + ), + EnumValueDefinition( + name: EnumValueName(name: r'B'), + ), + EnumValueDefinition( + name: EnumValueName(name: r'ARTEMIS_UNKNOWN'), + ), ]), ClassDefinition( name: ClassName(name: r'SomeQuery$_Response$_SomeObject'), diff --git a/test/query_generator/deprecated/deprecated_enum_value_test.dart b/test/query_generator/deprecated/deprecated_enum_value_test.dart index bf527d6f..d5e2d6f9 100644 --- a/test/query_generator/deprecated/deprecated_enum_value_test.dart +++ b/test/query_generator/deprecated/deprecated_enum_value_test.dart @@ -1,4 +1,5 @@ import 'package:artemis/generator/data/data.dart'; +import 'package:artemis/generator/data/enum_value_definition.dart'; import 'package:gql/language.dart'; import 'package:test/test.dart'; @@ -49,15 +50,21 @@ final LibraryDefinition libraryDefinition = EnumDefinition( name: EnumName(name: r'StarWarsMovies'), values: [ - EnumValue( - name: 'NEW_HOPE', + EnumValueDefinition( + name: EnumValueName(name: 'NEW_HOPE'), annotations: [ r"Deprecated('deprecated movie')", ], ), - EnumValue(name: 'EMPIRE'), - EnumValue(name: 'JEDI'), - EnumValue(name: 'ARTEMIS_UNKNOWN'), + EnumValueDefinition( + name: EnumValueName(name: 'EMPIRE'), + ), + EnumValueDefinition( + name: EnumValueName(name: 'JEDI'), + ), + EnumValueDefinition( + name: EnumValueName(name: 'ARTEMIS_UNKNOWN'), + ), ], ), ClassDefinition( diff --git a/test/query_generator/deprecated/deprecated_field_test.dart b/test/query_generator/deprecated/deprecated_field_test.dart index e75acc36..a61d807f 100644 --- a/test/query_generator/deprecated/deprecated_field_test.dart +++ b/test/query_generator/deprecated/deprecated_field_test.dart @@ -94,7 +94,8 @@ final LibraryDefinition libraryDefinition = name: ClassName(name: r'SomeQuery$_QueryResponse'), properties: [ ClassProperty( - type: TypeName(name: r'SomeQuery$QueryResponse$DeprecatedObject'), + type: + TypeName(name: r'SomeQuery$_QueryResponse$_deprecatedObject'), name: ClassPropertyName(name: r'deprecatedObject'), isNonNull: false, annotations: [r"Deprecated('message')"], diff --git a/test/query_generator/deprecated/deprecated_input_object_field_test.dart b/test/query_generator/deprecated/deprecated_input_object_field_test.dart index b3297eb4..ee08033d 100644 --- a/test/query_generator/deprecated/deprecated_input_object_field_test.dart +++ b/test/query_generator/deprecated/deprecated_input_object_field_test.dart @@ -67,7 +67,7 @@ final LibraryDefinition libraryDefinition = LibraryDefinition( name: ClassName(name: r'Custom$_MutationRoot'), properties: [ ClassProperty( - type: TypeName(name: r'Custom$MutationRoot$MutationResponse'), + type: TypeName(name: r'Custom$_MutationRoot$_MutationResponse'), name: ClassPropertyName(name: r'mut'), isNonNull: false, ), diff --git a/test/query_generator/deprecated/deprecated_interface_field_test.dart b/test/query_generator/deprecated/deprecated_interface_field_test.dart index 40a43f1f..c305e4d9 100644 --- a/test/query_generator/deprecated/deprecated_interface_field_test.dart +++ b/test/query_generator/deprecated/deprecated_interface_field_test.dart @@ -104,7 +104,7 @@ final LibraryDefinition libraryDefinition = LibraryDefinition( isResolveType: false, ), ClassProperty( - type: TypeName(name: r'Custom$Query$Node$ChatMessage$User'), + type: TypeName(name: r'Custom$_Query$_Node$_ChatMessage$_User'), name: ClassPropertyName(name: r'user'), isNonNull: true, isResolveType: false, @@ -145,7 +145,7 @@ final LibraryDefinition libraryDefinition = LibraryDefinition( name: ClassName(name: r'Custom$_Query'), properties: [ ClassProperty( - type: TypeName(name: r'Custom$Query$Node'), + type: TypeName(name: r'Custom$_Query$_Node'), name: ClassPropertyName(name: r'nodeById'), isNonNull: false, isResolveType: false, diff --git a/test/query_generator/enums/enum_duplication_test.dart b/test/query_generator/enums/enum_duplication_test.dart index 6c0e2444..8c439fb5 100644 --- a/test/query_generator/enums/enum_duplication_test.dart +++ b/test/query_generator/enums/enum_duplication_test.dart @@ -1,4 +1,5 @@ import 'package:artemis/generator/data/data.dart'; +import 'package:artemis/generator/data/enum_value_definition.dart'; import 'package:test/test.dart'; import '../../helpers.dart'; @@ -62,9 +63,16 @@ final LibraryDefinition libraryDefinition = operationName: r'custom', classes: [ EnumDefinition(name: EnumName(name: r'MyEnum'), values: [ - EnumValue(name: r'A'), - EnumValue(name: r'B'), - EnumValue(name: r'ARTEMIS_UNKNOWN') + EnumValueDefinition( + name: EnumValueName(name: r'A'), + ), + EnumValueDefinition( + name: EnumValueName(name: r'B'), + ), + EnumValueDefinition( + name: EnumValueName( + name: r'ARTEMIS_UNKNOWN', + )) ]), ClassDefinition( name: ClassName(name: r'Custom$_Query$_q'), @@ -101,9 +109,16 @@ final LibraryDefinition libraryDefinition = operationName: r'customList', classes: [ EnumDefinition(name: EnumName(name: r'MyEnum'), values: [ - EnumValue(name: r'A'), - EnumValue(name: r'B'), - EnumValue(name: r'ARTEMIS_UNKNOWN') + EnumValueDefinition( + name: EnumValueName(name: r'A'), + ), + EnumValueDefinition( + name: EnumValueName(name: r'B'), + ), + EnumValueDefinition( + name: EnumValueName( + name: r'ARTEMIS_UNKNOWN', + )) ]), ClassDefinition( name: ClassName(name: r'CustomList$_Query$_qList'), diff --git a/test/query_generator/enums/enum_list_test.dart b/test/query_generator/enums/enum_list_test.dart index e771ac97..17e8ff22 100644 --- a/test/query_generator/enums/enum_list_test.dart +++ b/test/query_generator/enums/enum_list_test.dart @@ -1,4 +1,5 @@ import 'package:artemis/generator/data/data.dart'; +import 'package:artemis/generator/data/enum_value_definition.dart'; import 'package:test/test.dart'; import '../../helpers.dart'; @@ -48,9 +49,16 @@ final LibraryDefinition libraryDefinition = operationName: r'custom', classes: [ EnumDefinition(name: EnumName(name: r'MyEnum'), values: [ - EnumValue(name: r'A'), - EnumValue(name: r'B'), - EnumValue(name: r'ARTEMIS_UNKNOWN') + EnumValueDefinition( + name: EnumValueName(name: r'A'), + ), + EnumValueDefinition( + name: EnumValueName(name: r'B'), + ), + EnumValueDefinition( + name: EnumValueName( + name: r'ARTEMIS_UNKNOWN', + )) ]), ClassDefinition( name: ClassName(name: r'Custom$_QueryRoot$_QueryResponse'), diff --git a/test/query_generator/enums/filter_enum_test.dart b/test/query_generator/enums/filter_enum_test.dart index 6e55c25e..4eb41cc3 100644 --- a/test/query_generator/enums/filter_enum_test.dart +++ b/test/query_generator/enums/filter_enum_test.dart @@ -1,4 +1,5 @@ import 'package:artemis/generator/data/data.dart'; +import 'package:artemis/generator/data/enum_value_definition.dart'; import 'package:test/test.dart'; import '../../helpers.dart'; @@ -78,21 +79,46 @@ final LibraryDefinition libraryDefinition = operationName: r'custom', classes: [ EnumDefinition(name: EnumName(name: r'MyEnum'), values: [ - EnumValue(name: r'A'), - EnumValue(name: r'B'), - EnumValue(name: r'ARTEMIS_UNKNOWN') + EnumValueDefinition( + name: EnumValueName(name: r'A'), + ), + EnumValueDefinition( + name: EnumValueName(name: r'B'), + ), + EnumValueDefinition( + name: EnumValueName( + name: r'ARTEMIS_UNKNOWN', + )) ]), EnumDefinition(name: EnumName(name: r'InputEnum'), values: [ - EnumValue(name: r'C'), - EnumValue(name: r'D'), - EnumValue(name: r'ARTEMIS_UNKNOWN') + EnumValueDefinition( + name: EnumValueName(name: r'C'), + ), + EnumValueDefinition( + name: EnumValueName(name: r'D'), + ), + EnumValueDefinition( + name: EnumValueName( + name: r'ARTEMIS_UNKNOWN', + )) ]), EnumDefinition(name: EnumName(name: r'_InputInputEnum'), values: [ - EnumValue(name: r'_E'), - EnumValue(name: r'_F'), - EnumValue(name: r'_new'), - EnumValue(name: r'new'), - EnumValue(name: r'ARTEMIS_UNKNOWN') + EnumValueDefinition( + name: EnumValueName(name: r'_E'), + ), + EnumValueDefinition( + name: EnumValueName(name: r'_F'), + ), + EnumValueDefinition( + name: EnumValueName(name: r'_new'), + ), + EnumValueDefinition( + name: EnumValueName(name: r'new'), + ), + EnumValueDefinition( + name: EnumValueName( + name: r'ARTEMIS_UNKNOWN', + )) ]), ClassDefinition( name: ClassName(name: r'Custom$_QueryRoot$_QueryResponse'), diff --git a/test/query_generator/enums/input_enum_test.dart b/test/query_generator/enums/input_enum_test.dart index 274fd599..6a17971c 100644 --- a/test/query_generator/enums/input_enum_test.dart +++ b/test/query_generator/enums/input_enum_test.dart @@ -1,4 +1,5 @@ import 'package:artemis/generator/data/data.dart'; +import 'package:artemis/generator/data/enum_value_definition.dart'; import 'package:test/test.dart'; import '../../helpers.dart'; @@ -63,14 +64,28 @@ final LibraryDefinition libraryDefinition = operationName: r'custom', classes: [ EnumDefinition(name: EnumName(name: r'MyEnum'), values: [ - EnumValue(name: r'A'), - EnumValue(name: r'B'), - EnumValue(name: r'ARTEMIS_UNKNOWN') + EnumValueDefinition( + name: EnumValueName(name: r'A'), + ), + EnumValueDefinition( + name: EnumValueName(name: r'B'), + ), + EnumValueDefinition( + name: EnumValueName( + name: r'ARTEMIS_UNKNOWN', + )) ]), EnumDefinition(name: EnumName(name: r'OtherEnum'), values: [ - EnumValue(name: r'O1'), - EnumValue(name: r'O2'), - EnumValue(name: r'ARTEMIS_UNKNOWN') + EnumValueDefinition( + name: EnumValueName(name: r'O1'), + ), + EnumValueDefinition( + name: EnumValueName(name: r'O2'), + ), + EnumValueDefinition( + name: EnumValueName( + name: r'ARTEMIS_UNKNOWN', + )) ]), ClassDefinition( name: ClassName(name: r'Custom$_QueryRoot$_QueryResponse'), diff --git a/test/query_generator/enums/query_enum_test.dart b/test/query_generator/enums/query_enum_test.dart index ee1288b1..82e06f6c 100644 --- a/test/query_generator/enums/query_enum_test.dart +++ b/test/query_generator/enums/query_enum_test.dart @@ -1,4 +1,5 @@ import 'package:artemis/generator/data/data.dart'; +import 'package:artemis/generator/data/enum_value_definition.dart'; import 'package:test/test.dart'; import '../../helpers.dart'; @@ -49,9 +50,16 @@ final LibraryDefinition libraryDefinition = operationName: r'custom', classes: [ EnumDefinition(name: EnumName(name: r'MyEnum'), values: [ - EnumValue(name: r'A'), - EnumValue(name: r'B'), - EnumValue(name: r'ARTEMIS_UNKNOWN') + EnumValueDefinition( + name: EnumValueName(name: 'A'), + ), + EnumValueDefinition( + name: EnumValueName(name: 'B'), + ), + EnumValueDefinition( + name: EnumValueName( + name: 'ARTEMIS_UNKNOWN', + )) ]), ClassDefinition( name: ClassName(name: r'Custom$_QueryRoot$_QueryResponse'), diff --git a/test/query_generator/mutations_and_inputs/complex_input_objects_test.dart b/test/query_generator/mutations_and_inputs/complex_input_objects_test.dart index 6148e55f..c6aa8679 100644 --- a/test/query_generator/mutations_and_inputs/complex_input_objects_test.dart +++ b/test/query_generator/mutations_and_inputs/complex_input_objects_test.dart @@ -1,4 +1,5 @@ import 'package:artemis/generator/data/data.dart'; +import 'package:artemis/generator/data/enum_value_definition.dart'; import 'package:test/test.dart'; import '../../helpers.dart'; @@ -54,9 +55,15 @@ final LibraryDefinition libraryDefinition = operationName: r'some_query', classes: [ EnumDefinition(name: EnumName(name: r'MyEnum'), values: [ - EnumValue(name: r'value1'), - EnumValue(name: r'value2'), - EnumValue(name: r'ARTEMIS_UNKNOWN') + EnumValueDefinition( + name: EnumValueName(name: r'value1'), + ), + EnumValueDefinition( + name: EnumValueName(name: r'value2'), + ), + EnumValueDefinition( + name: EnumValueName(name: r'ARTEMIS_UNKNOWN'), + ), ]), ClassDefinition( name: ClassName(name: r'SomeQuery$_QueryRoot$_SomeObject'), diff --git a/test/query_generator/naming/casing_conversion_test.dart b/test/query_generator/naming/casing_conversion_test.dart index 8bd22066..2b36aad6 100644 --- a/test/query_generator/naming/casing_conversion_test.dart +++ b/test/query_generator/naming/casing_conversion_test.dart @@ -1,4 +1,5 @@ import 'package:artemis/generator/data/data.dart'; +import 'package:artemis/generator/data/enum_value_definition.dart'; import 'package:test/test.dart'; import '../../helpers.dart'; @@ -94,11 +95,21 @@ final LibraryDefinition libraryDefinition = operationName: r'some_query', classes: [ EnumDefinition(name: EnumName(name: r'MyEnum'), values: [ - EnumValue(name: r'camelCase'), - EnumValue(name: r'PascalCase'), - EnumValue(name: r'snake_case'), - EnumValue(name: r'SCREAMING_SNAKE_CASE'), - EnumValue(name: r'ARTEMIS_UNKNOWN') + EnumValueDefinition( + name: EnumValueName(name: r'camelCase'), + ), + EnumValueDefinition( + name: EnumValueName(name: r'PascalCase'), + ), + EnumValueDefinition( + name: EnumValueName(name: r'snake_case'), + ), + EnumValueDefinition( + name: EnumValueName(name: r'SCREAMING_SNAKE_CASE'), + ), + EnumValueDefinition( + name: EnumValueName(name: r'ARTEMIS_UNKNOWN'), + ), ]), ClassDefinition( name: ClassName(name: r'SomeObject'), From ff47f1f4a951fa92ae1a331af851e2764e88d572 Mon Sep 17 00:00:00 2001 From: Igor Borges Date: Fri, 10 Jul 2020 12:15:41 -0300 Subject: [PATCH 06/13] Create debug flag --- .../check-version-and-changelog/entrypoint.sh | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/.github/actions/check-version-and-changelog/entrypoint.sh b/.github/actions/check-version-and-changelog/entrypoint.sh index e914c06c..5b7a34b9 100755 --- a/.github/actions/check-version-and-changelog/entrypoint.sh +++ b/.github/actions/check-version-and-changelog/entrypoint.sh @@ -1,10 +1,16 @@ #!/bin/ash +function debug { + echo "$1" +} + cd "$GITHUB_WORKSPACE" REPO_TOKEN="$1" github_ref="$2" +debug "$(env)" +debug "$(cat "$GITHUB_EVENT_PATH" | jq .)" PR_HREF=$(cat "$GITHUB_EVENT_PATH" | jq -r '.pull_request._links.self.href') function send_message_and_bail { @@ -22,11 +28,11 @@ function send_message_and_bail { exit 1 } -# echo "PARAM GITHUB REF: $github_ref" -# echo "GITHUB EVENT NAME: $GITHUB_EVENT_NAME" -# echo "GITHUB REF: $GITHUB_REF" -# echo "GITHUB BASE REF: $GITHUB_BASE_REF" -# echo "GITHUB HEAD REF: $GITHUB_HEAD_REF" +debug "PARAM GITHUB REF: $github_ref" +debug "GITHUB EVENT NAME: $GITHUB_EVENT_NAME" +debug "GITHUB REF: $GITHUB_REF" +debug "GITHUB BASE REF: $GITHUB_BASE_REF" +debug "GITHUB HEAD REF: $GITHUB_HEAD_REF" git fetch --prune --unshallow From ee9d08cc6174e85d8c9289335a09079db16f5908 Mon Sep 17 00:00:00 2001 From: Igor Borges Date: Fri, 10 Jul 2020 12:27:35 -0300 Subject: [PATCH 07/13] Start using ACTIONS_USER_TOKEN --- .../check-version-and-changelog/action.yaml | 6 ++--- .../check-version-and-changelog/entrypoint.sh | 25 +++++++++++++------ .github/workflows/pull_request.yaml | 2 +- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/.github/actions/check-version-and-changelog/action.yaml b/.github/actions/check-version-and-changelog/action.yaml index 7d7e4a98..c57d9b0d 100644 --- a/.github/actions/check-version-and-changelog/action.yaml +++ b/.github/actions/check-version-and-changelog/action.yaml @@ -1,8 +1,8 @@ name: "Check version and changelog" description: "Make sure the version is bumped and it has a changelog entry" inputs: - repo_token: - description: "Access token for sending errors as a PR message" + actions_user_token: + description: "User access token for sending errors as a PR message. This is not default repo token for actions, or else non-maintainers will not see the comments." required: false default: "" base_ref: @@ -16,5 +16,5 @@ runs: using: "docker" image: "Dockerfile" args: - - "${{ inputs.repo_token }}" + - "${{ inputs.actions_user_token }}" - "${{ inputs.base_ref }}" diff --git a/.github/actions/check-version-and-changelog/entrypoint.sh b/.github/actions/check-version-and-changelog/entrypoint.sh index 5b7a34b9..cfe4fc1e 100755 --- a/.github/actions/check-version-and-changelog/entrypoint.sh +++ b/.github/actions/check-version-and-changelog/entrypoint.sh @@ -6,23 +6,34 @@ function debug { cd "$GITHUB_WORKSPACE" -REPO_TOKEN="$1" +ACTIONS_USER_TOKEN="$1" github_ref="$2" debug "$(env)" debug "$(cat "$GITHUB_EVENT_PATH" | jq .)" + +PR_CREATOR=$(cat "$GITHUB_EVENT_PATH" | jq -r '.pull_request.user.login') +[ "$PR_CREATOR" = "comigor" ] && EVENT_TYPE="COMMENT" || EVENT_TYPE="REQUEST_CHANGES" + PR_HREF=$(cat "$GITHUB_EVENT_PATH" | jq -r '.pull_request._links.self.href') function send_message_and_bail { - if [ ! -z "$REPO_TOKEN" ]; then - ERROR="$1" - - jq -c -n --arg body "$ERROR" '{"event":"COMMENT", "body":$body}' > /tmp/payload.json + ERROR="$1" + echo "-------------------------------------------------" + echo "$ERROR" + echo "-------------------------------------------------" + + if [ ! -z "$ACTIONS_USER_TOKEN" ]; then + jq -c -n --arg body "$ERROR" --arg event_type "$EVENT_TYPE" '{"event":$event_type, "body":$body}' > /tmp/payload.json + echo "CURL" + cat /tmp/payload.json curl -f -X POST \ - -H 'Content-Type: application/json' \ - -H "Authorization: Bearer $REPO_TOKEN" \ + -H 'Content-Type: application/vnd.github.v3.full+json' \ + -H "Authorization: Bearer $ACTIONS_USER_TOKEN" \ --data "@/tmp/payload.json" \ "$PR_HREF/reviews" -vv + # || true + fi exit 1 diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml index 1173efe1..24f89119 100644 --- a/.github/workflows/pull_request.yaml +++ b/.github/workflows/pull_request.yaml @@ -9,7 +9,7 @@ jobs: - uses: actions/checkout@master - uses: ./.github/actions/check-version-and-changelog with: - repo_token: "${{ secrets.GITHUB_TOKEN }}" + actions_user_token: "${{ secrets.ACTIONS_USER_TOKEN }}" base_ref: "${{ github.base_ref }}" test: runs-on: ubuntu-latest From a8fac31be435af56a2337ac2b05406688ecdcfe0 Mon Sep 17 00:00:00 2001 From: Igor Borges Date: Fri, 10 Jul 2020 12:41:45 -0300 Subject: [PATCH 08/13] force pushing are not working --- .github/actions/check-version-and-changelog/entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/check-version-and-changelog/entrypoint.sh b/.github/actions/check-version-and-changelog/entrypoint.sh index cfe4fc1e..c05ba950 100755 --- a/.github/actions/check-version-and-changelog/entrypoint.sh +++ b/.github/actions/check-version-and-changelog/entrypoint.sh @@ -25,7 +25,7 @@ function send_message_and_bail { if [ ! -z "$ACTIONS_USER_TOKEN" ]; then jq -c -n --arg body "$ERROR" --arg event_type "$EVENT_TYPE" '{"event":$event_type, "body":$body}' > /tmp/payload.json - echo "CURL" + echo "CURL::" cat /tmp/payload.json curl -f -X POST \ -H 'Content-Type: application/vnd.github.v3.full+json' \ From 3e66bb4fd4b4856c0e84d5a47a404e4bb89a8a3c Mon Sep 17 00:00:00 2001 From: Igor Borges Date: Fri, 10 Jul 2020 12:45:04 -0300 Subject: [PATCH 09/13] Pass token into push --- .github/actions/check-version-and-changelog/entrypoint.sh | 1 + .github/workflows/push.yaml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/actions/check-version-and-changelog/entrypoint.sh b/.github/actions/check-version-and-changelog/entrypoint.sh index c05ba950..ea402266 100755 --- a/.github/actions/check-version-and-changelog/entrypoint.sh +++ b/.github/actions/check-version-and-changelog/entrypoint.sh @@ -7,6 +7,7 @@ function debug { cd "$GITHUB_WORKSPACE" ACTIONS_USER_TOKEN="$1" +echo "LENGTH $(echo "$ACTIONS_USER_TOKEN" | wc -c)" github_ref="$2" debug "$(env)" diff --git a/.github/workflows/push.yaml b/.github/workflows/push.yaml index 8d92e098..f3e7b173 100644 --- a/.github/workflows/push.yaml +++ b/.github/workflows/push.yaml @@ -27,6 +27,7 @@ jobs: name: Check if version on pubspec.yaml was changed and if there's an entry for this new version on CHANGELOG uses: ./.github/actions/check-version-and-changelog with: + actions_user_token: "${{ secrets.ACTIONS_USER_TOKEN }}" base_ref: "${{ github.ref }}" - name: Push tag uses: anothrNick/github-tag-action@master From fcfb54d387fa61386176ee7b0d2d101859e43065 Mon Sep 17 00:00:00 2001 From: Igor Borges Date: Fri, 10 Jul 2020 12:54:38 -0300 Subject: [PATCH 10/13] Revert all actions changes --- .../check-version-and-changelog/action.yaml | 6 +-- .../check-version-and-changelog/entrypoint.sh | 40 +++++-------------- .github/workflows/pull_request.yaml | 2 +- .github/workflows/push.yaml | 1 - 4 files changed, 15 insertions(+), 34 deletions(-) diff --git a/.github/actions/check-version-and-changelog/action.yaml b/.github/actions/check-version-and-changelog/action.yaml index c57d9b0d..7d7e4a98 100644 --- a/.github/actions/check-version-and-changelog/action.yaml +++ b/.github/actions/check-version-and-changelog/action.yaml @@ -1,8 +1,8 @@ name: "Check version and changelog" description: "Make sure the version is bumped and it has a changelog entry" inputs: - actions_user_token: - description: "User access token for sending errors as a PR message. This is not default repo token for actions, or else non-maintainers will not see the comments." + repo_token: + description: "Access token for sending errors as a PR message" required: false default: "" base_ref: @@ -16,5 +16,5 @@ runs: using: "docker" image: "Dockerfile" args: - - "${{ inputs.actions_user_token }}" + - "${{ inputs.repo_token }}" - "${{ inputs.base_ref }}" diff --git a/.github/actions/check-version-and-changelog/entrypoint.sh b/.github/actions/check-version-and-changelog/entrypoint.sh index ea402266..e914c06c 100755 --- a/.github/actions/check-version-and-changelog/entrypoint.sh +++ b/.github/actions/check-version-and-changelog/entrypoint.sh @@ -1,50 +1,32 @@ #!/bin/ash -function debug { - echo "$1" -} - cd "$GITHUB_WORKSPACE" -ACTIONS_USER_TOKEN="$1" -echo "LENGTH $(echo "$ACTIONS_USER_TOKEN" | wc -c)" +REPO_TOKEN="$1" github_ref="$2" -debug "$(env)" -debug "$(cat "$GITHUB_EVENT_PATH" | jq .)" - -PR_CREATOR=$(cat "$GITHUB_EVENT_PATH" | jq -r '.pull_request.user.login') -[ "$PR_CREATOR" = "comigor" ] && EVENT_TYPE="COMMENT" || EVENT_TYPE="REQUEST_CHANGES" - PR_HREF=$(cat "$GITHUB_EVENT_PATH" | jq -r '.pull_request._links.self.href') function send_message_and_bail { - ERROR="$1" - echo "-------------------------------------------------" - echo "$ERROR" - echo "-------------------------------------------------" + if [ ! -z "$REPO_TOKEN" ]; then + ERROR="$1" - if [ ! -z "$ACTIONS_USER_TOKEN" ]; then - jq -c -n --arg body "$ERROR" --arg event_type "$EVENT_TYPE" '{"event":$event_type, "body":$body}' > /tmp/payload.json - echo "CURL::" - cat /tmp/payload.json + jq -c -n --arg body "$ERROR" '{"event":"COMMENT", "body":$body}' > /tmp/payload.json curl -f -X POST \ - -H 'Content-Type: application/vnd.github.v3.full+json' \ - -H "Authorization: Bearer $ACTIONS_USER_TOKEN" \ + -H 'Content-Type: application/json' \ + -H "Authorization: Bearer $REPO_TOKEN" \ --data "@/tmp/payload.json" \ "$PR_HREF/reviews" -vv - # || true - fi exit 1 } -debug "PARAM GITHUB REF: $github_ref" -debug "GITHUB EVENT NAME: $GITHUB_EVENT_NAME" -debug "GITHUB REF: $GITHUB_REF" -debug "GITHUB BASE REF: $GITHUB_BASE_REF" -debug "GITHUB HEAD REF: $GITHUB_HEAD_REF" +# echo "PARAM GITHUB REF: $github_ref" +# echo "GITHUB EVENT NAME: $GITHUB_EVENT_NAME" +# echo "GITHUB REF: $GITHUB_REF" +# echo "GITHUB BASE REF: $GITHUB_BASE_REF" +# echo "GITHUB HEAD REF: $GITHUB_HEAD_REF" git fetch --prune --unshallow diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml index 24f89119..1173efe1 100644 --- a/.github/workflows/pull_request.yaml +++ b/.github/workflows/pull_request.yaml @@ -9,7 +9,7 @@ jobs: - uses: actions/checkout@master - uses: ./.github/actions/check-version-and-changelog with: - actions_user_token: "${{ secrets.ACTIONS_USER_TOKEN }}" + repo_token: "${{ secrets.GITHUB_TOKEN }}" base_ref: "${{ github.base_ref }}" test: runs-on: ubuntu-latest diff --git a/.github/workflows/push.yaml b/.github/workflows/push.yaml index f3e7b173..8d92e098 100644 --- a/.github/workflows/push.yaml +++ b/.github/workflows/push.yaml @@ -27,7 +27,6 @@ jobs: name: Check if version on pubspec.yaml was changed and if there's an entry for this new version on CHANGELOG uses: ./.github/actions/check-version-and-changelog with: - actions_user_token: "${{ secrets.ACTIONS_USER_TOKEN }}" base_ref: "${{ github.ref }}" - name: Push tag uses: anothrNick/github-tag-action@master From dd037d65b246881df3347babc6048e1492a88a5c Mon Sep 17 00:00:00 2001 From: Igor Borges Date: Fri, 10 Jul 2020 12:55:59 -0300 Subject: [PATCH 11/13] Do not 403 on error --- .../check-version-and-changelog/entrypoint.sh | 9 ++++++--- .github/actions/dart-test/entrypoint.sh | 13 ++++++++----- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/.github/actions/check-version-and-changelog/entrypoint.sh b/.github/actions/check-version-and-changelog/entrypoint.sh index e914c06c..d1898f45 100755 --- a/.github/actions/check-version-and-changelog/entrypoint.sh +++ b/.github/actions/check-version-and-changelog/entrypoint.sh @@ -8,15 +8,18 @@ github_ref="$2" PR_HREF=$(cat "$GITHUB_EVENT_PATH" | jq -r '.pull_request._links.self.href') function send_message_and_bail { - if [ ! -z "$REPO_TOKEN" ]; then - ERROR="$1" + ERROR="$1" + echo "------------------------------------------------" + echo "$ERROR" + echo "------------------------------------------------" + if [ ! -z "$REPO_TOKEN" ]; then jq -c -n --arg body "$ERROR" '{"event":"COMMENT", "body":$body}' > /tmp/payload.json curl -f -X POST \ -H 'Content-Type: application/json' \ -H "Authorization: Bearer $REPO_TOKEN" \ --data "@/tmp/payload.json" \ - "$PR_HREF/reviews" -vv + "$PR_HREF/reviews" -vv || true fi exit 1 diff --git a/.github/actions/dart-test/entrypoint.sh b/.github/actions/dart-test/entrypoint.sh index e4c9d548..a05f1bd5 100755 --- a/.github/actions/dart-test/entrypoint.sh +++ b/.github/actions/dart-test/entrypoint.sh @@ -20,11 +20,14 @@ cd "$GITHUB_WORKSPACE" PR_HREF=$(cat "$GITHUB_EVENT_PATH" | jq -r '.pull_request._links.self.href') function send_message_and_bail { - if [ ! -z "$REPO_TOKEN" ]; then - ERROR="$1" - DETAIL="$2" - # DETAIL=$(echo "$2" | sed -zE 's/\n/\\n/g') + ERROR="$1" + DETAIL="$2" + echo "------------------------------------------------" + echo "$ERROR" + echo "$DETAIL" + echo "------------------------------------------------" + if [ ! -z "$REPO_TOKEN" ]; then BODY=$(cat < Date: Fri, 10 Jul 2020 12:57:52 -0300 Subject: [PATCH 12/13] Have error as last output before bail --- .github/actions/check-version-and-changelog/entrypoint.sh | 6 +++--- .github/actions/dart-test/entrypoint.sh | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/actions/check-version-and-changelog/entrypoint.sh b/.github/actions/check-version-and-changelog/entrypoint.sh index d1898f45..4c5cd2a7 100755 --- a/.github/actions/check-version-and-changelog/entrypoint.sh +++ b/.github/actions/check-version-and-changelog/entrypoint.sh @@ -9,9 +9,6 @@ PR_HREF=$(cat "$GITHUB_EVENT_PATH" | jq -r '.pull_request._links.self.href') function send_message_and_bail { ERROR="$1" - echo "------------------------------------------------" - echo "$ERROR" - echo "------------------------------------------------" if [ ! -z "$REPO_TOKEN" ]; then jq -c -n --arg body "$ERROR" '{"event":"COMMENT", "body":$body}' > /tmp/payload.json @@ -22,6 +19,9 @@ function send_message_and_bail { "$PR_HREF/reviews" -vv || true fi + echo "------------------------------------------------" + echo "$ERROR" + echo "------------------------------------------------" exit 1 } diff --git a/.github/actions/dart-test/entrypoint.sh b/.github/actions/dart-test/entrypoint.sh index a05f1bd5..86c90b7c 100755 --- a/.github/actions/dart-test/entrypoint.sh +++ b/.github/actions/dart-test/entrypoint.sh @@ -22,10 +22,6 @@ PR_HREF=$(cat "$GITHUB_EVENT_PATH" | jq -r '.pull_request._links.self.href') function send_message_and_bail { ERROR="$1" DETAIL="$2" - echo "------------------------------------------------" - echo "$ERROR" - echo "$DETAIL" - echo "------------------------------------------------" if [ ! -z "$REPO_TOKEN" ]; then BODY=$(cat < Date: Fri, 10 Jul 2020 13:03:15 -0300 Subject: [PATCH 13/13] 6.5.0 and fix linter --- CHANGELOG.md | 3 +++ lib/generator/data/enum_value_definition.dart | 1 - pubspec.yaml | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3dff0789..20f8acb8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # CHANGELOG +## 6.5.0-beta.1 +- Add deprecated annotations in fields. + ## 6.4.4-beta.1 - Build type name recursively, considering casing changes. diff --git a/lib/generator/data/enum_value_definition.dart b/lib/generator/data/enum_value_definition.dart index df87bb23..d582ce5a 100644 --- a/lib/generator/data/enum_value_definition.dart +++ b/lib/generator/data/enum_value_definition.dart @@ -1,6 +1,5 @@ import 'package:artemis/generator/data/definition.dart'; import 'package:artemis/generator/data_printer.dart'; -import 'package:artemis/generator/helpers.dart'; import 'package:meta/meta.dart'; import 'package:recase/recase.dart'; diff --git a/pubspec.yaml b/pubspec.yaml index 406540b4..c996c8a7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: artemis -version: 6.4.4-beta.1 +version: 6.5.0-beta.1 authors: - Igor Borges