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

Commit

Permalink
Merge pull request #258 from ANVLCO/feat/json-serializable
Browse files Browse the repository at this point in the history
Allow for auto generated response and inputs to extend JsonSerializable
  • Loading branch information
vasilich6107 authored Feb 1, 2021
2 parents 3aca1cd + 199d4cc commit 912bb04
Show file tree
Hide file tree
Showing 48 changed files with 196 additions and 151 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# CHANGELOG

## 6.20.1-beta.1
- Allow for auto generated response and inputs to extend JsonSerializable

## 6.19.3-beta.1
- bugfix of append typename - common fragments

Expand Down
2 changes: 1 addition & 1 deletion lib/generator/print_helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ Spec classDefinitionToSpec(
..methods.add(_propsMethod('[${props.join(',')}]'))
..extend = definition.extension != null
? refer(definition.extension.namePrintable)
: null
: refer('JsonSerializable')
..implements.addAll(definition.implementations.map((i) => refer(i)))
..constructors.add(Constructor((b) {
if (definition.isInput) {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: artemis
version: 6.19.3-beta.1
version: 6.20.1-beta.1

description: Build dart types from GraphQL schemas and queries (using Introspection Query).
homepage: https://github.com/comigor/artemis
Expand Down
14 changes: 7 additions & 7 deletions test/generator/print_helpers_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ void main() {
final str = specToString(classDefinitionToSpec(definition, [], []));

expect(str, '''@JsonSerializable(explicitToJson: true)
class AClass with EquatableMixin {
class AClass extends JsonSerializable with EquatableMixin {
AClass();
factory AClass.fromJson(Map<String, dynamic> json) => _\$AClassFromJson(json);
Expand Down Expand Up @@ -199,7 +199,7 @@ class AClass extends AnotherClass with EquatableMixin {
final str = specToString(classDefinitionToSpec(definition, [], []));

expect(str, r'''@JsonSerializable(explicitToJson: true)
class AClass with EquatableMixin {
class AClass extends JsonSerializable with EquatableMixin {
AClass();
factory AClass.fromJson(Map<String, dynamic> json) {
Expand Down Expand Up @@ -243,7 +243,7 @@ class AClass with EquatableMixin {
final str = specToString(classDefinitionToSpec(definition, [], []));

expect(str, '''@JsonSerializable(explicitToJson: true)
class AClass with EquatableMixin {
class AClass extends JsonSerializable with EquatableMixin {
AClass();
factory AClass.fromJson(Map<String, dynamic> json) => _\$AClassFromJson(json);
Expand Down Expand Up @@ -284,7 +284,7 @@ class AClass with EquatableMixin {
final str = specToString(classDefinitionToSpec(definition, [], []));

expect(str, '''@JsonSerializable(explicitToJson: true)
class AClass with EquatableMixin {
class AClass extends JsonSerializable with EquatableMixin {
AClass();
factory AClass.fromJson(Map<String, dynamic> json) => _\$AClassFromJson(json);
Expand Down Expand Up @@ -327,7 +327,7 @@ class AClass with EquatableMixin {
], []));

expect(str, '''@JsonSerializable(explicitToJson: true)
class AClass with EquatableMixin, FragmentMixin {
class AClass extends JsonSerializable with EquatableMixin, FragmentMixin {
AClass();
factory AClass.fromJson(Map<String, dynamic> json) => _\$AClassFromJson(json);
Expand Down Expand Up @@ -358,7 +358,7 @@ class AClass with EquatableMixin, FragmentMixin {
final str = specToString(classDefinitionToSpec(definition, [], []));

expect(str, '''@JsonSerializable(explicitToJson: true)
class AClass with EquatableMixin {
class AClass extends JsonSerializable with EquatableMixin {
AClass({this.name, @required this.anotherName});
factory AClass.fromJson(Map<String, dynamic> json) => _\$AClassFromJson(json);
Expand Down Expand Up @@ -686,7 +686,7 @@ import 'package:gql/ast.dart';
part 'test_query.graphql.g.dart';
@JsonSerializable(explicitToJson: true)
class AClass with EquatableMixin {
class AClass extends JsonSerializable with EquatableMixin {
AClass();
factory AClass.fromJson(Map<String, dynamic> json) => _\$AClassFromJson(json);
Expand Down
5 changes: 3 additions & 2 deletions test/query_generator/aliases/alias_on_leaves_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ import 'package:gql/ast.dart';
part 'query.graphql.g.dart';
@JsonSerializable(explicitToJson: true)
class SomeQuery$Response$SomeObject with EquatableMixin {
class SomeQuery$Response$SomeObject extends JsonSerializable
with EquatableMixin {
SomeQuery$Response$SomeObject();
factory SomeQuery$Response$SomeObject.fromJson(Map<String, dynamic> json) =>
Expand All @@ -125,7 +126,7 @@ class SomeQuery$Response$SomeObject with EquatableMixin {
}
@JsonSerializable(explicitToJson: true)
class SomeQuery$Response with EquatableMixin {
class SomeQuery$Response extends JsonSerializable with EquatableMixin {
SomeQuery$Response();
factory SomeQuery$Response.fromJson(Map<String, dynamic> json) =>
Expand Down
8 changes: 5 additions & 3 deletions test/query_generator/aliases/alias_on_object_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ import 'package:gql/ast.dart';
part 'query.graphql.g.dart';
@JsonSerializable(explicitToJson: true)
class SomeQuery$QueryResponse$SomeObject with EquatableMixin {
class SomeQuery$QueryResponse$SomeObject extends JsonSerializable
with EquatableMixin {
SomeQuery$QueryResponse$SomeObject();
factory SomeQuery$QueryResponse$SomeObject.fromJson(
Expand All @@ -128,7 +129,8 @@ class SomeQuery$QueryResponse$SomeObject with EquatableMixin {
}
@JsonSerializable(explicitToJson: true)
class SomeQuery$QueryResponse$AnotherObject with EquatableMixin {
class SomeQuery$QueryResponse$AnotherObject extends JsonSerializable
with EquatableMixin {
SomeQuery$QueryResponse$AnotherObject();
factory SomeQuery$QueryResponse$AnotherObject.fromJson(
Expand All @@ -144,7 +146,7 @@ class SomeQuery$QueryResponse$AnotherObject with EquatableMixin {
}
@JsonSerializable(explicitToJson: true)
class SomeQuery$QueryResponse with EquatableMixin {
class SomeQuery$QueryResponse extends JsonSerializable with EquatableMixin {
SomeQuery$QueryResponse();
factory SomeQuery$QueryResponse.fromJson(Map<String, dynamic> json) =>
Expand Down
22 changes: 12 additions & 10 deletions test/query_generator/append_type_name_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ import 'package:gql/ast.dart';
part 'query.graphql.g.dart';
@JsonSerializable(explicitToJson: true)
class Custom$QueryRoot$Q with EquatableMixin {
class Custom$QueryRoot$Q extends JsonSerializable with EquatableMixin {
Custom$QueryRoot$Q();
factory Custom$QueryRoot$Q.fromJson(Map<String, dynamic> json) =>
Expand All @@ -107,7 +107,7 @@ class Custom$QueryRoot$Q with EquatableMixin {
}
@JsonSerializable(explicitToJson: true)
class Custom$QueryRoot with EquatableMixin {
class Custom$QueryRoot extends JsonSerializable with EquatableMixin {
Custom$QueryRoot();
factory Custom$QueryRoot.fromJson(Map<String, dynamic> json) =>
Expand Down Expand Up @@ -206,7 +206,7 @@ import 'package:gql/ast.dart';
part 'query.graphql.g.dart';
@JsonSerializable(explicitToJson: true)
class Custom$QueryRoot$Q with EquatableMixin {
class Custom$QueryRoot$Q extends JsonSerializable with EquatableMixin {
Custom$QueryRoot$Q();
factory Custom$QueryRoot$Q.fromJson(Map<String, dynamic> json) =>
Expand All @@ -223,7 +223,7 @@ class Custom$QueryRoot$Q with EquatableMixin {
}
@JsonSerializable(explicitToJson: true)
class Custom$QueryRoot with EquatableMixin {
class Custom$QueryRoot extends JsonSerializable with EquatableMixin {
Custom$QueryRoot();
factory Custom$QueryRoot.fromJson(Map<String, dynamic> json) =>
Expand Down Expand Up @@ -341,7 +341,8 @@ mixin QueryResponseMixin {
}
@JsonSerializable(explicitToJson: true)
class Custom$QueryRoot$Q with EquatableMixin, QueryResponseMixin {
class Custom$QueryRoot$Q extends JsonSerializable
with EquatableMixin, QueryResponseMixin {
Custom$QueryRoot$Q();
factory Custom$QueryRoot$Q.fromJson(Map<String, dynamic> json) =>
Expand All @@ -356,7 +357,7 @@ class Custom$QueryRoot$Q with EquatableMixin, QueryResponseMixin {
}
@JsonSerializable(explicitToJson: true)
class Custom$QueryRoot with EquatableMixin {
class Custom$QueryRoot extends JsonSerializable with EquatableMixin {
Custom$QueryRoot();
factory Custom$QueryRoot.fromJson(Map<String, dynamic> json) =>
Expand Down Expand Up @@ -538,7 +539,7 @@ class Custom$QueryRoot$Q$TypeB extends Custom$QueryRoot$Q with EquatableMixin {
}
@JsonSerializable(explicitToJson: true)
class Custom$QueryRoot$Q with EquatableMixin {
class Custom$QueryRoot$Q extends JsonSerializable with EquatableMixin {
Custom$QueryRoot$Q();
factory Custom$QueryRoot$Q.fromJson(Map<String, dynamic> json) {
Expand Down Expand Up @@ -570,7 +571,7 @@ class Custom$QueryRoot$Q with EquatableMixin {
}
@JsonSerializable(explicitToJson: true)
class Custom$QueryRoot with EquatableMixin {
class Custom$QueryRoot extends JsonSerializable with EquatableMixin {
Custom$QueryRoot();
factory Custom$QueryRoot.fromJson(Map<String, dynamic> json) =>
Expand Down Expand Up @@ -685,7 +686,8 @@ mixin QueryResponseMixin {
}
@JsonSerializable(explicitToJson: true)
class Custom$QueryRoot$QueryResponse with EquatableMixin, QueryResponseMixin {
class Custom$QueryRoot$QueryResponse extends JsonSerializable
with EquatableMixin, QueryResponseMixin {
Custom$QueryRoot$QueryResponse();
factory Custom$QueryRoot$QueryResponse.fromJson(Map<String, dynamic> json) =>
Expand All @@ -700,7 +702,7 @@ class Custom$QueryRoot$QueryResponse with EquatableMixin, QueryResponseMixin {
}
@JsonSerializable(explicitToJson: true)
class Custom$QueryRoot with EquatableMixin {
class Custom$QueryRoot extends JsonSerializable with EquatableMixin {
Custom$QueryRoot();
factory Custom$QueryRoot.fromJson(Map<String, dynamic> json) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ import 'package:gql/ast.dart';
part 'query.graphql.g.dart';
@JsonSerializable(explicitToJson: true)
class CreateThing$MutationRoot$CreateThingResponse$Thing with EquatableMixin {
class CreateThing$MutationRoot$CreateThingResponse$Thing
extends JsonSerializable with EquatableMixin {
CreateThing$MutationRoot$CreateThingResponse$Thing();
factory CreateThing$MutationRoot$CreateThingResponse$Thing.fromJson(
Expand All @@ -159,7 +160,8 @@ class CreateThing$MutationRoot$CreateThingResponse$Thing with EquatableMixin {
}
@JsonSerializable(explicitToJson: true)
class CreateThing$MutationRoot$CreateThingResponse with EquatableMixin {
class CreateThing$MutationRoot$CreateThingResponse extends JsonSerializable
with EquatableMixin {
CreateThing$MutationRoot$CreateThingResponse();
factory CreateThing$MutationRoot$CreateThingResponse.fromJson(
Expand All @@ -175,7 +177,7 @@ class CreateThing$MutationRoot$CreateThingResponse with EquatableMixin {
}
@JsonSerializable(explicitToJson: true)
class CreateThing$MutationRoot with EquatableMixin {
class CreateThing$MutationRoot extends JsonSerializable with EquatableMixin {
CreateThing$MutationRoot();
factory CreateThing$MutationRoot.fromJson(Map<String, dynamic> json) =>
Expand All @@ -189,7 +191,7 @@ class CreateThing$MutationRoot with EquatableMixin {
}
@JsonSerializable(explicitToJson: true)
class CreateThingInput with EquatableMixin {
class CreateThingInput extends JsonSerializable with EquatableMixin {
CreateThingInput({@required this.clientId, this.message});
factory CreateThingInput.fromJson(Map<String, dynamic> json) =>
Expand Down
12 changes: 7 additions & 5 deletions test/query_generator/ast_schema/input_types_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ import 'package:gql/ast.dart';
part 'query.graphql.g.dart';
@JsonSerializable(explicitToJson: true)
class CreateThing$MutationRoot$CreateThingResponse$Thing with EquatableMixin {
class CreateThing$MutationRoot$CreateThingResponse$Thing
extends JsonSerializable with EquatableMixin {
CreateThing$MutationRoot$CreateThingResponse$Thing();
factory CreateThing$MutationRoot$CreateThingResponse$Thing.fromJson(
Expand All @@ -181,7 +182,8 @@ class CreateThing$MutationRoot$CreateThingResponse$Thing with EquatableMixin {
}
@JsonSerializable(explicitToJson: true)
class CreateThing$MutationRoot$CreateThingResponse with EquatableMixin {
class CreateThing$MutationRoot$CreateThingResponse extends JsonSerializable
with EquatableMixin {
CreateThing$MutationRoot$CreateThingResponse();
factory CreateThing$MutationRoot$CreateThingResponse.fromJson(
Expand All @@ -197,7 +199,7 @@ class CreateThing$MutationRoot$CreateThingResponse with EquatableMixin {
}
@JsonSerializable(explicitToJson: true)
class CreateThing$MutationRoot with EquatableMixin {
class CreateThing$MutationRoot extends JsonSerializable with EquatableMixin {
CreateThing$MutationRoot();
factory CreateThing$MutationRoot.fromJson(Map<String, dynamic> json) =>
Expand All @@ -211,7 +213,7 @@ class CreateThing$MutationRoot with EquatableMixin {
}
@JsonSerializable(explicitToJson: true)
class OtherObjectInput with EquatableMixin {
class OtherObjectInput extends JsonSerializable with EquatableMixin {
OtherObjectInput({@required this.id});
factory OtherObjectInput.fromJson(Map<String, dynamic> json) =>
Expand All @@ -225,7 +227,7 @@ class OtherObjectInput with EquatableMixin {
}
@JsonSerializable(explicitToJson: true)
class CreateThingInput with EquatableMixin {
class CreateThingInput extends JsonSerializable with EquatableMixin {
CreateThingInput({@required this.clientId, this.message, this.shares});
factory CreateThingInput.fromJson(Map<String, dynamic> json) =>
Expand Down
2 changes: 1 addition & 1 deletion test/query_generator/ast_schema/missing_schema_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ import 'package:gql/ast.dart';
part 'query.graphql.g.dart';
@JsonSerializable(explicitToJson: true)
class Query$Query with EquatableMixin {
class Query$Query extends JsonSerializable with EquatableMixin {
Query$Query();
factory Query$Query.fromJson(Map<String, dynamic> json) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,8 @@ import 'package:gql/ast.dart';
part 'outputA.graphql.g.dart';
@JsonSerializable(explicitToJson: true)
class BrowseArticles$Query$Articles with EquatableMixin {
class BrowseArticles$Query$Articles extends JsonSerializable
with EquatableMixin {
BrowseArticles$Query$Articles();
factory BrowseArticles$Query$Articles.fromJson(Map<String, dynamic> json) =>
Expand All @@ -328,7 +329,7 @@ class BrowseArticles$Query$Articles with EquatableMixin {
}
@JsonSerializable(explicitToJson: true)
class BrowseArticles$Query with EquatableMixin {
class BrowseArticles$Query extends JsonSerializable with EquatableMixin {
BrowseArticles$Query();
factory BrowseArticles$Query.fromJson(Map<String, dynamic> json) =>
Expand Down Expand Up @@ -410,7 +411,8 @@ import 'package:gql/ast.dart';
part 'outputB.graphql.g.dart';
@JsonSerializable(explicitToJson: true)
class BrowseRepositories$Query$Repositories with EquatableMixin {
class BrowseRepositories$Query$Repositories extends JsonSerializable
with EquatableMixin {
BrowseRepositories$Query$Repositories();
factory BrowseRepositories$Query$Repositories.fromJson(
Expand All @@ -434,7 +436,7 @@ class BrowseRepositories$Query$Repositories with EquatableMixin {
}
@JsonSerializable(explicitToJson: true)
class BrowseRepositories$Query with EquatableMixin {
class BrowseRepositories$Query extends JsonSerializable with EquatableMixin {
BrowseRepositories$Query();
factory BrowseRepositories$Query.fromJson(Map<String, dynamic> json) =>
Expand All @@ -448,7 +450,7 @@ class BrowseRepositories$Query with EquatableMixin {
}
@JsonSerializable(explicitToJson: true)
class NotificationOptionInput with EquatableMixin {
class NotificationOptionInput extends JsonSerializable with EquatableMixin {
NotificationOptionInput({this.type, this.enabled});
factory NotificationOptionInput.fromJson(Map<String, dynamic> json) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ import 'package:gql/ast.dart';
part 'query.graphql.g.dart';
@JsonSerializable(explicitToJson: true)
class SomeQuery$QueryResponse with EquatableMixin {
class SomeQuery$QueryResponse extends JsonSerializable with EquatableMixin {
SomeQuery$QueryResponse();
factory SomeQuery$QueryResponse.fromJson(Map<String, dynamic> json) =>
Expand Down
Loading

0 comments on commit 912bb04

Please sign in to comment.