From 6b08ceae9e16766683c4484711a4f82a3a6dedb7 Mon Sep 17 00:00:00 2001 From: Rongjian Zhang Date: Fri, 13 Dec 2019 23:44:49 +0800 Subject: [PATCH] refactor: commits screen type --- build.yaml | 7 + lib/graphql/github_commits.dart | 765 +++++++++++++++++++++++++++++ lib/graphql/github_commits.g.dart | 353 +++++++++++++ lib/graphql/github_commits.graphql | 60 +++ lib/screens/commits.dart | 87 +--- 5 files changed, 1211 insertions(+), 61 deletions(-) create mode 100644 lib/graphql/github_commits.dart create mode 100644 lib/graphql/github_commits.g.dart create mode 100644 lib/graphql/github_commits.graphql diff --git a/build.yaml b/build.yaml index 8ebb048..91a751c 100644 --- a/build.yaml +++ b/build.yaml @@ -49,6 +49,13 @@ targets: queries_glob: lib/graphql/github_users.graphql resolve_type_field: __typename add_query_prefix: true + - schema: lib/github.schema.json + output: lib/graphql/github_commits.dart + queries_glob: lib/graphql/github_commits.graphql + resolve_type_field: __typename + add_query_prefix: true scalar_mapping: - graphql_type: URI dart_type: String + - graphql_type: GitObjectID + dart_type: String diff --git a/lib/graphql/github_commits.dart b/lib/graphql/github_commits.dart new file mode 100644 index 0000000..3fd2968 --- /dev/null +++ b/lib/graphql/github_commits.dart @@ -0,0 +1,765 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +import 'package:artemis/artemis.dart'; +import 'package:json_annotation/json_annotation.dart'; +import 'package:equatable/equatable.dart'; +import 'package:gql/ast.dart'; +part 'github_commits.g.dart'; + +mixin TMixin { + GithubCommitsGitObject target; +} + +@JsonSerializable(explicitToJson: true) +class GithubCommits with EquatableMixin { + GithubCommits(); + + factory GithubCommits.fromJson(Map json) => + _$GithubCommitsFromJson(json); + + GithubCommitsRepository repository; + + @override + List get props => [repository]; + Map toJson() => _$GithubCommitsToJson(this); +} + +@JsonSerializable(explicitToJson: true) +class GithubCommitsRepository extends GithubCommitsPinnableItem + with EquatableMixin + implements + GithubCommitsNode, + GithubCommitsProjectOwner, + GithubCommitsRegistryPackageOwner, + GithubCommitsRegistryPackageSearch, + GithubCommitsSubscribable, + GithubCommitsStarrable, + GithubCommitsUniformResourceLocatable, + GithubCommitsRepositoryInfo { + GithubCommitsRepository(); + + factory GithubCommitsRepository.fromJson(Map json) => + _$GithubCommitsRepositoryFromJson(json); + + GithubCommitsRef defaultBranchRef; + + GithubCommitsRef ref; + + @override + @JsonKey(name: '__typename') + String resolveType; + + @override + List get props => [defaultBranchRef, ref, resolveType]; + Map toJson() => _$GithubCommitsRepositoryToJson(this); +} + +@JsonSerializable(explicitToJson: true) +class GithubCommitsRef + with EquatableMixin, TMixin + implements GithubCommitsNode { + GithubCommitsRef(); + + factory GithubCommitsRef.fromJson(Map json) => + _$GithubCommitsRefFromJson(json); + + @override + @JsonKey(name: '__typename') + String resolveType; + + @override + List get props => [target, resolveType]; + Map toJson() => _$GithubCommitsRefToJson(this); +} + +@JsonSerializable(explicitToJson: true) +class GithubCommitsGitObject with EquatableMixin { + GithubCommitsGitObject(); + + factory GithubCommitsGitObject.fromJson(Map json) { + switch (json['__typename'].toString()) { + case 'Commit': + return GithubCommitsCommit.fromJson(json); + default: + } + return _$GithubCommitsGitObjectFromJson(json); + } + + @JsonKey(name: '__typename') + String resolveType; + + @override + List get props => [resolveType]; + Map toJson() { + switch (resolveType) { + case 'Commit': + return (this as GithubCommitsCommit).toJson(); + default: + } + return _$GithubCommitsGitObjectToJson(this); + } +} + +@JsonSerializable(explicitToJson: true) +class GithubCommitsCommit extends GithubCommitsPullRequestTimelineItem + with EquatableMixin + implements + GithubCommitsNode, + GithubCommitsGitObject, + GithubCommitsSubscribable, + GithubCommitsUniformResourceLocatable { + GithubCommitsCommit(); + + factory GithubCommitsCommit.fromJson(Map json) => + _$GithubCommitsCommitFromJson(json); + + String oid; + + String url; + + String messageHeadline; + + DateTime committedDate; + + GithubCommitsGitActor author; + + GithubCommitsCommitHistoryConnection history; + + @override + @JsonKey(name: '__typename') + String resolveType; + + @override + List get props => + [oid, url, messageHeadline, committedDate, author, history, resolveType]; + Map toJson() => _$GithubCommitsCommitToJson(this); +} + +@JsonSerializable(explicitToJson: true) +class GithubCommitsGitActor with EquatableMixin { + GithubCommitsGitActor(); + + factory GithubCommitsGitActor.fromJson(Map json) => + _$GithubCommitsGitActorFromJson(json); + + String name; + + String avatarUrl; + + GithubCommitsUser user; + + @override + List get props => [name, avatarUrl, user]; + Map toJson() => _$GithubCommitsGitActorToJson(this); +} + +@JsonSerializable(explicitToJson: true) +class GithubCommitsUser extends GithubCommitsAuditEntryActor + with EquatableMixin + implements + GithubCommitsNode, + GithubCommitsActor, + GithubCommitsRegistryPackageOwner, + GithubCommitsRegistryPackageSearch, + GithubCommitsProjectOwner, + GithubCommitsRepositoryOwner, + GithubCommitsUniformResourceLocatable, + GithubCommitsProfileOwner, + GithubCommitsSponsorable { + GithubCommitsUser(); + + factory GithubCommitsUser.fromJson(Map json) => + _$GithubCommitsUserFromJson(json); + + @override + String login; + + @override + @JsonKey(name: '__typename') + String resolveType; + + @override + List get props => [login, resolveType]; + Map toJson() => _$GithubCommitsUserToJson(this); +} + +@JsonSerializable(explicitToJson: true) +class GithubCommitsAuditEntryActor with EquatableMixin { + GithubCommitsAuditEntryActor(); + + factory GithubCommitsAuditEntryActor.fromJson(Map json) => + _$GithubCommitsAuditEntryActorFromJson(json); + + @override + List get props => []; + Map toJson() => _$GithubCommitsAuditEntryActorToJson(this); +} + +@JsonSerializable(explicitToJson: true) +class GithubCommitsNode with EquatableMixin { + GithubCommitsNode(); + + factory GithubCommitsNode.fromJson(Map json) => + _$GithubCommitsNodeFromJson(json); + + @JsonKey(name: '__typename') + String resolveType; + + @override + List get props => [resolveType]; + Map toJson() => _$GithubCommitsNodeToJson(this); +} + +@JsonSerializable(explicitToJson: true) +class GithubCommitsActor with EquatableMixin { + GithubCommitsActor(); + + factory GithubCommitsActor.fromJson(Map json) => + _$GithubCommitsActorFromJson(json); + + String login; + + @JsonKey(name: '__typename') + String resolveType; + + @override + List get props => [login, resolveType]; + Map toJson() => _$GithubCommitsActorToJson(this); +} + +@JsonSerializable(explicitToJson: true) +class GithubCommitsRegistryPackageOwner with EquatableMixin { + GithubCommitsRegistryPackageOwner(); + + factory GithubCommitsRegistryPackageOwner.fromJson( + Map json) => + _$GithubCommitsRegistryPackageOwnerFromJson(json); + + @JsonKey(name: '__typename') + String resolveType; + + @override + List get props => [resolveType]; + Map toJson() => + _$GithubCommitsRegistryPackageOwnerToJson(this); +} + +@JsonSerializable(explicitToJson: true) +class GithubCommitsRegistryPackageSearch with EquatableMixin { + GithubCommitsRegistryPackageSearch(); + + factory GithubCommitsRegistryPackageSearch.fromJson( + Map json) => + _$GithubCommitsRegistryPackageSearchFromJson(json); + + @JsonKey(name: '__typename') + String resolveType; + + @override + List get props => [resolveType]; + Map toJson() => + _$GithubCommitsRegistryPackageSearchToJson(this); +} + +@JsonSerializable(explicitToJson: true) +class GithubCommitsProjectOwner with EquatableMixin { + GithubCommitsProjectOwner(); + + factory GithubCommitsProjectOwner.fromJson(Map json) => + _$GithubCommitsProjectOwnerFromJson(json); + + @JsonKey(name: '__typename') + String resolveType; + + @override + List get props => [resolveType]; + Map toJson() => _$GithubCommitsProjectOwnerToJson(this); +} + +@JsonSerializable(explicitToJson: true) +class GithubCommitsRepositoryOwner with EquatableMixin { + GithubCommitsRepositoryOwner(); + + factory GithubCommitsRepositoryOwner.fromJson(Map json) => + _$GithubCommitsRepositoryOwnerFromJson(json); + + String login; + + @JsonKey(name: '__typename') + String resolveType; + + @override + List get props => [login, resolveType]; + Map toJson() => _$GithubCommitsRepositoryOwnerToJson(this); +} + +@JsonSerializable(explicitToJson: true) +class GithubCommitsUniformResourceLocatable with EquatableMixin { + GithubCommitsUniformResourceLocatable(); + + factory GithubCommitsUniformResourceLocatable.fromJson( + Map json) => + _$GithubCommitsUniformResourceLocatableFromJson(json); + + @JsonKey(name: '__typename') + String resolveType; + + @override + List get props => [resolveType]; + Map toJson() => + _$GithubCommitsUniformResourceLocatableToJson(this); +} + +@JsonSerializable(explicitToJson: true) +class GithubCommitsProfileOwner with EquatableMixin { + GithubCommitsProfileOwner(); + + factory GithubCommitsProfileOwner.fromJson(Map json) => + _$GithubCommitsProfileOwnerFromJson(json); + + String login; + + @JsonKey(name: '__typename') + String resolveType; + + @override + List get props => [login, resolveType]; + Map toJson() => _$GithubCommitsProfileOwnerToJson(this); +} + +@JsonSerializable(explicitToJson: true) +class GithubCommitsSponsorable with EquatableMixin { + GithubCommitsSponsorable(); + + factory GithubCommitsSponsorable.fromJson(Map json) => + _$GithubCommitsSponsorableFromJson(json); + + @JsonKey(name: '__typename') + String resolveType; + + @override + List get props => [resolveType]; + Map toJson() => _$GithubCommitsSponsorableToJson(this); +} + +@JsonSerializable(explicitToJson: true) +class GithubCommitsCommitHistoryConnection with EquatableMixin { + GithubCommitsCommitHistoryConnection(); + + factory GithubCommitsCommitHistoryConnection.fromJson( + Map json) => + _$GithubCommitsCommitHistoryConnectionFromJson(json); + + GithubCommitsPageInfo pageInfo; + + List nodes; + + @override + List get props => [pageInfo, nodes]; + Map toJson() => + _$GithubCommitsCommitHistoryConnectionToJson(this); +} + +@JsonSerializable(explicitToJson: true) +class GithubCommitsPageInfo with EquatableMixin { + GithubCommitsPageInfo(); + + factory GithubCommitsPageInfo.fromJson(Map json) => + _$GithubCommitsPageInfoFromJson(json); + + bool hasNextPage; + + String endCursor; + + @override + List get props => [hasNextPage, endCursor]; + Map toJson() => _$GithubCommitsPageInfoToJson(this); +} + +@JsonSerializable(explicitToJson: true) +class GithubCommitsPullRequestTimelineItem with EquatableMixin { + GithubCommitsPullRequestTimelineItem(); + + factory GithubCommitsPullRequestTimelineItem.fromJson( + Map json) => + _$GithubCommitsPullRequestTimelineItemFromJson(json); + + @override + List get props => []; + Map toJson() => + _$GithubCommitsPullRequestTimelineItemToJson(this); +} + +@JsonSerializable(explicitToJson: true) +class GithubCommitsSubscribable with EquatableMixin { + GithubCommitsSubscribable(); + + factory GithubCommitsSubscribable.fromJson(Map json) => + _$GithubCommitsSubscribableFromJson(json); + + @JsonKey(name: '__typename') + String resolveType; + + @override + List get props => [resolveType]; + Map toJson() => _$GithubCommitsSubscribableToJson(this); +} + +@JsonSerializable(explicitToJson: true) +class GithubCommitsPinnableItem with EquatableMixin { + GithubCommitsPinnableItem(); + + factory GithubCommitsPinnableItem.fromJson(Map json) => + _$GithubCommitsPinnableItemFromJson(json); + + @override + List get props => []; + Map toJson() => _$GithubCommitsPinnableItemToJson(this); +} + +@JsonSerializable(explicitToJson: true) +class GithubCommitsStarrable with EquatableMixin { + GithubCommitsStarrable(); + + factory GithubCommitsStarrable.fromJson(Map json) => + _$GithubCommitsStarrableFromJson(json); + + @JsonKey(name: '__typename') + String resolveType; + + @override + List get props => [resolveType]; + Map toJson() => _$GithubCommitsStarrableToJson(this); +} + +@JsonSerializable(explicitToJson: true) +class GithubCommitsRepositoryInfo with EquatableMixin { + GithubCommitsRepositoryInfo(); + + factory GithubCommitsRepositoryInfo.fromJson(Map json) => + _$GithubCommitsRepositoryInfoFromJson(json); + + @JsonKey(name: '__typename') + String resolveType; + + @override + List get props => [resolveType]; + Map toJson() => _$GithubCommitsRepositoryInfoToJson(this); +} + +@JsonSerializable(explicitToJson: true) +class GithubCommitsArguments extends JsonSerializable with EquatableMixin { + GithubCommitsArguments( + {this.owner, this.name, this.ref, this.hasRef, this.after}); + + factory GithubCommitsArguments.fromJson(Map json) => + _$GithubCommitsArgumentsFromJson(json); + + final String owner; + + final String name; + + final String ref; + + final bool hasRef; + + final String after; + + @override + List get props => [owner, name, ref, hasRef, after]; + Map toJson() => _$GithubCommitsArgumentsToJson(this); +} + +class GithubCommitsQuery + extends GraphQLQuery { + GithubCommitsQuery({this.variables}); + + @override + final DocumentNode document = DocumentNode(definitions: [ + FragmentDefinitionNode( + name: NameNode(value: 'T'), + typeCondition: TypeConditionNode( + on: NamedTypeNode(name: NameNode(value: 'Ref'), isNonNull: false)), + directives: [], + selectionSet: SelectionSetNode(selections: [ + FieldNode( + name: NameNode(value: 'target'), + alias: null, + arguments: [], + directives: [], + selectionSet: SelectionSetNode(selections: [ + InlineFragmentNode( + typeCondition: TypeConditionNode( + on: NamedTypeNode( + name: NameNode(value: 'Commit'), isNonNull: false)), + directives: [], + selectionSet: SelectionSetNode(selections: [ + FieldNode( + name: NameNode(value: 'oid'), + alias: null, + arguments: [], + directives: [], + selectionSet: null), + FieldNode( + name: NameNode(value: 'url'), + alias: null, + arguments: [], + directives: [], + selectionSet: null), + FieldNode( + name: NameNode(value: 'messageHeadline'), + alias: null, + arguments: [], + directives: [], + selectionSet: null), + FieldNode( + name: NameNode(value: 'committedDate'), + alias: null, + arguments: [], + directives: [], + selectionSet: null), + FieldNode( + name: NameNode(value: 'author'), + alias: null, + arguments: [], + directives: [], + selectionSet: SelectionSetNode(selections: [ + FieldNode( + name: NameNode(value: 'name'), + alias: null, + arguments: [], + directives: [], + selectionSet: null), + FieldNode( + name: NameNode(value: 'avatarUrl'), + alias: null, + arguments: [], + directives: [], + selectionSet: null), + FieldNode( + name: NameNode(value: 'user'), + alias: null, + arguments: [], + directives: [], + selectionSet: SelectionSetNode(selections: [ + FieldNode( + name: NameNode(value: 'login'), + alias: null, + arguments: [], + directives: [], + selectionSet: null) + ])) + ])), + FieldNode( + name: NameNode(value: '__typename'), + alias: null, + arguments: [], + directives: [], + selectionSet: null), + FieldNode( + name: NameNode(value: 'history'), + alias: null, + arguments: [ + ArgumentNode( + name: NameNode(value: 'first'), + value: IntValueNode(value: '30')), + ArgumentNode( + name: NameNode(value: 'after'), + value: VariableNode( + name: NameNode(value: 'after'))) + ], + directives: [], + selectionSet: SelectionSetNode(selections: [ + FieldNode( + name: NameNode(value: 'pageInfo'), + alias: null, + arguments: [], + directives: [], + selectionSet: SelectionSetNode(selections: [ + FieldNode( + name: NameNode(value: 'hasNextPage'), + alias: null, + arguments: [], + directives: [], + selectionSet: null), + FieldNode( + name: NameNode(value: 'endCursor'), + alias: null, + arguments: [], + directives: [], + selectionSet: null) + ])), + FieldNode( + name: NameNode(value: 'nodes'), + alias: null, + arguments: [], + directives: [], + selectionSet: SelectionSetNode(selections: [ + FieldNode( + name: NameNode(value: 'oid'), + alias: null, + arguments: [], + directives: [], + selectionSet: null), + FieldNode( + name: NameNode(value: 'url'), + alias: null, + arguments: [], + directives: [], + selectionSet: null), + FieldNode( + name: NameNode(value: 'messageHeadline'), + alias: null, + arguments: [], + directives: [], + selectionSet: null), + FieldNode( + name: NameNode(value: 'committedDate'), + alias: null, + arguments: [], + directives: [], + selectionSet: null), + FieldNode( + name: NameNode(value: 'author'), + alias: null, + arguments: [], + directives: [], + selectionSet: + SelectionSetNode(selections: [ + FieldNode( + name: NameNode(value: 'name'), + alias: null, + arguments: [], + directives: [], + selectionSet: null), + FieldNode( + name: NameNode(value: 'avatarUrl'), + alias: null, + arguments: [], + directives: [], + selectionSet: null), + FieldNode( + name: NameNode(value: 'user'), + alias: null, + arguments: [], + directives: [], + selectionSet: + SelectionSetNode(selections: [ + FieldNode( + name: + NameNode(value: 'login'), + alias: null, + arguments: [], + directives: [], + selectionSet: null) + ])) + ])) + ])) + ])) + ])) + ])) + ])), + OperationDefinitionNode( + type: OperationType.query, + name: null, + variableDefinitions: [ + VariableDefinitionNode( + variable: VariableNode(name: NameNode(value: 'owner')), + type: NamedTypeNode( + name: NameNode(value: 'String'), isNonNull: true), + defaultValue: DefaultValueNode(value: null), + directives: []), + VariableDefinitionNode( + variable: VariableNode(name: NameNode(value: 'name')), + type: NamedTypeNode( + name: NameNode(value: 'String'), isNonNull: true), + defaultValue: DefaultValueNode(value: null), + directives: []), + VariableDefinitionNode( + variable: VariableNode(name: NameNode(value: 'ref')), + type: NamedTypeNode( + name: NameNode(value: 'String'), isNonNull: true), + defaultValue: DefaultValueNode(value: null), + directives: []), + VariableDefinitionNode( + variable: VariableNode(name: NameNode(value: 'hasRef')), + type: NamedTypeNode( + name: NameNode(value: 'Boolean'), isNonNull: true), + defaultValue: DefaultValueNode(value: null), + directives: []), + VariableDefinitionNode( + variable: VariableNode(name: NameNode(value: 'after')), + type: NamedTypeNode( + name: NameNode(value: 'String'), isNonNull: false), + defaultValue: DefaultValueNode(value: null), + directives: []) + ], + directives: [], + selectionSet: SelectionSetNode(selections: [ + FieldNode( + name: NameNode(value: 'repository'), + alias: null, + arguments: [ + ArgumentNode( + name: NameNode(value: 'owner'), + value: VariableNode(name: NameNode(value: 'owner'))), + ArgumentNode( + name: NameNode(value: 'name'), + value: VariableNode(name: NameNode(value: 'name'))) + ], + directives: [], + selectionSet: SelectionSetNode(selections: [ + FieldNode( + name: NameNode(value: 'defaultBranchRef'), + alias: null, + arguments: [], + directives: [ + DirectiveNode(name: NameNode(value: 'skip'), arguments: [ + ArgumentNode( + name: NameNode(value: 'if'), + value: + VariableNode(name: NameNode(value: 'hasRef'))) + ]) + ], + selectionSet: SelectionSetNode(selections: [ + FragmentSpreadNode( + name: NameNode(value: 'T'), directives: []) + ])), + FieldNode( + name: NameNode(value: 'ref'), + alias: null, + arguments: [ + ArgumentNode( + name: NameNode(value: 'qualifiedName'), + value: VariableNode(name: NameNode(value: 'ref'))) + ], + directives: [ + DirectiveNode( + name: NameNode(value: 'include'), + arguments: [ + ArgumentNode( + name: NameNode(value: 'if'), + value: VariableNode( + name: NameNode(value: 'hasRef'))) + ]) + ], + selectionSet: SelectionSetNode(selections: [ + FragmentSpreadNode( + name: NameNode(value: 'T'), directives: []) + ])) + ])) + ])) + ]); + + @override + final String operationName = 'github_commits'; + + @override + final GithubCommitsArguments variables; + + @override + List get props => [document, operationName, variables]; + @override + GithubCommits parse(Map json) => + GithubCommits.fromJson(json); +} diff --git a/lib/graphql/github_commits.g.dart b/lib/graphql/github_commits.g.dart new file mode 100644 index 0000000..1fff11f --- /dev/null +++ b/lib/graphql/github_commits.g.dart @@ -0,0 +1,353 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'github_commits.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +GithubCommits _$GithubCommitsFromJson(Map json) { + return GithubCommits() + ..repository = json['repository'] == null + ? null + : GithubCommitsRepository.fromJson( + json['repository'] as Map); +} + +Map _$GithubCommitsToJson(GithubCommits instance) => + { + 'repository': instance.repository?.toJson(), + }; + +GithubCommitsRepository _$GithubCommitsRepositoryFromJson( + Map json) { + return GithubCommitsRepository() + ..defaultBranchRef = json['defaultBranchRef'] == null + ? null + : GithubCommitsRef.fromJson( + json['defaultBranchRef'] as Map) + ..ref = json['ref'] == null + ? null + : GithubCommitsRef.fromJson(json['ref'] as Map) + ..resolveType = json['__typename'] as String; +} + +Map _$GithubCommitsRepositoryToJson( + GithubCommitsRepository instance) => + { + 'defaultBranchRef': instance.defaultBranchRef?.toJson(), + 'ref': instance.ref?.toJson(), + '__typename': instance.resolveType, + }; + +GithubCommitsRef _$GithubCommitsRefFromJson(Map json) { + return GithubCommitsRef() + ..target = json['target'] == null + ? null + : GithubCommitsGitObject.fromJson( + json['target'] as Map) + ..resolveType = json['__typename'] as String; +} + +Map _$GithubCommitsRefToJson(GithubCommitsRef instance) => + { + 'target': instance.target?.toJson(), + '__typename': instance.resolveType, + }; + +GithubCommitsGitObject _$GithubCommitsGitObjectFromJson( + Map json) { + return GithubCommitsGitObject()..resolveType = json['__typename'] as String; +} + +Map _$GithubCommitsGitObjectToJson( + GithubCommitsGitObject instance) => + { + '__typename': instance.resolveType, + }; + +GithubCommitsCommit _$GithubCommitsCommitFromJson(Map json) { + return GithubCommitsCommit() + ..oid = json['oid'] as String + ..url = json['url'] as String + ..messageHeadline = json['messageHeadline'] as String + ..committedDate = json['committedDate'] == null + ? null + : DateTime.parse(json['committedDate'] as String) + ..author = json['author'] == null + ? null + : GithubCommitsGitActor.fromJson(json['author'] as Map) + ..history = json['history'] == null + ? null + : GithubCommitsCommitHistoryConnection.fromJson( + json['history'] as Map) + ..resolveType = json['__typename'] as String; +} + +Map _$GithubCommitsCommitToJson( + GithubCommitsCommit instance) => + { + 'oid': instance.oid, + 'url': instance.url, + 'messageHeadline': instance.messageHeadline, + 'committedDate': instance.committedDate?.toIso8601String(), + 'author': instance.author?.toJson(), + 'history': instance.history?.toJson(), + '__typename': instance.resolveType, + }; + +GithubCommitsGitActor _$GithubCommitsGitActorFromJson( + Map json) { + return GithubCommitsGitActor() + ..name = json['name'] as String + ..avatarUrl = json['avatarUrl'] as String + ..user = json['user'] == null + ? null + : GithubCommitsUser.fromJson(json['user'] as Map); +} + +Map _$GithubCommitsGitActorToJson( + GithubCommitsGitActor instance) => + { + 'name': instance.name, + 'avatarUrl': instance.avatarUrl, + 'user': instance.user?.toJson(), + }; + +GithubCommitsUser _$GithubCommitsUserFromJson(Map json) { + return GithubCommitsUser() + ..login = json['login'] as String + ..resolveType = json['__typename'] as String; +} + +Map _$GithubCommitsUserToJson(GithubCommitsUser instance) => + { + 'login': instance.login, + '__typename': instance.resolveType, + }; + +GithubCommitsAuditEntryActor _$GithubCommitsAuditEntryActorFromJson( + Map json) { + return GithubCommitsAuditEntryActor(); +} + +Map _$GithubCommitsAuditEntryActorToJson( + GithubCommitsAuditEntryActor instance) => + {}; + +GithubCommitsNode _$GithubCommitsNodeFromJson(Map json) { + return GithubCommitsNode()..resolveType = json['__typename'] as String; +} + +Map _$GithubCommitsNodeToJson(GithubCommitsNode instance) => + { + '__typename': instance.resolveType, + }; + +GithubCommitsActor _$GithubCommitsActorFromJson(Map json) { + return GithubCommitsActor() + ..login = json['login'] as String + ..resolveType = json['__typename'] as String; +} + +Map _$GithubCommitsActorToJson(GithubCommitsActor instance) => + { + 'login': instance.login, + '__typename': instance.resolveType, + }; + +GithubCommitsRegistryPackageOwner _$GithubCommitsRegistryPackageOwnerFromJson( + Map json) { + return GithubCommitsRegistryPackageOwner() + ..resolveType = json['__typename'] as String; +} + +Map _$GithubCommitsRegistryPackageOwnerToJson( + GithubCommitsRegistryPackageOwner instance) => + { + '__typename': instance.resolveType, + }; + +GithubCommitsRegistryPackageSearch _$GithubCommitsRegistryPackageSearchFromJson( + Map json) { + return GithubCommitsRegistryPackageSearch() + ..resolveType = json['__typename'] as String; +} + +Map _$GithubCommitsRegistryPackageSearchToJson( + GithubCommitsRegistryPackageSearch instance) => + { + '__typename': instance.resolveType, + }; + +GithubCommitsProjectOwner _$GithubCommitsProjectOwnerFromJson( + Map json) { + return GithubCommitsProjectOwner() + ..resolveType = json['__typename'] as String; +} + +Map _$GithubCommitsProjectOwnerToJson( + GithubCommitsProjectOwner instance) => + { + '__typename': instance.resolveType, + }; + +GithubCommitsRepositoryOwner _$GithubCommitsRepositoryOwnerFromJson( + Map json) { + return GithubCommitsRepositoryOwner() + ..login = json['login'] as String + ..resolveType = json['__typename'] as String; +} + +Map _$GithubCommitsRepositoryOwnerToJson( + GithubCommitsRepositoryOwner instance) => + { + 'login': instance.login, + '__typename': instance.resolveType, + }; + +GithubCommitsUniformResourceLocatable + _$GithubCommitsUniformResourceLocatableFromJson(Map json) { + return GithubCommitsUniformResourceLocatable() + ..resolveType = json['__typename'] as String; +} + +Map _$GithubCommitsUniformResourceLocatableToJson( + GithubCommitsUniformResourceLocatable instance) => + { + '__typename': instance.resolveType, + }; + +GithubCommitsProfileOwner _$GithubCommitsProfileOwnerFromJson( + Map json) { + return GithubCommitsProfileOwner() + ..login = json['login'] as String + ..resolveType = json['__typename'] as String; +} + +Map _$GithubCommitsProfileOwnerToJson( + GithubCommitsProfileOwner instance) => + { + 'login': instance.login, + '__typename': instance.resolveType, + }; + +GithubCommitsSponsorable _$GithubCommitsSponsorableFromJson( + Map json) { + return GithubCommitsSponsorable()..resolveType = json['__typename'] as String; +} + +Map _$GithubCommitsSponsorableToJson( + GithubCommitsSponsorable instance) => + { + '__typename': instance.resolveType, + }; + +GithubCommitsCommitHistoryConnection + _$GithubCommitsCommitHistoryConnectionFromJson(Map json) { + return GithubCommitsCommitHistoryConnection() + ..pageInfo = json['pageInfo'] == null + ? null + : GithubCommitsPageInfo.fromJson( + json['pageInfo'] as Map) + ..nodes = (json['nodes'] as List) + ?.map((e) => e == null + ? null + : GithubCommitsCommit.fromJson(e as Map)) + ?.toList(); +} + +Map _$GithubCommitsCommitHistoryConnectionToJson( + GithubCommitsCommitHistoryConnection instance) => + { + 'pageInfo': instance.pageInfo?.toJson(), + 'nodes': instance.nodes?.map((e) => e?.toJson())?.toList(), + }; + +GithubCommitsPageInfo _$GithubCommitsPageInfoFromJson( + Map json) { + return GithubCommitsPageInfo() + ..hasNextPage = json['hasNextPage'] as bool + ..endCursor = json['endCursor'] as String; +} + +Map _$GithubCommitsPageInfoToJson( + GithubCommitsPageInfo instance) => + { + 'hasNextPage': instance.hasNextPage, + 'endCursor': instance.endCursor, + }; + +GithubCommitsPullRequestTimelineItem + _$GithubCommitsPullRequestTimelineItemFromJson(Map json) { + return GithubCommitsPullRequestTimelineItem(); +} + +Map _$GithubCommitsPullRequestTimelineItemToJson( + GithubCommitsPullRequestTimelineItem instance) => + {}; + +GithubCommitsSubscribable _$GithubCommitsSubscribableFromJson( + Map json) { + return GithubCommitsSubscribable() + ..resolveType = json['__typename'] as String; +} + +Map _$GithubCommitsSubscribableToJson( + GithubCommitsSubscribable instance) => + { + '__typename': instance.resolveType, + }; + +GithubCommitsPinnableItem _$GithubCommitsPinnableItemFromJson( + Map json) { + return GithubCommitsPinnableItem(); +} + +Map _$GithubCommitsPinnableItemToJson( + GithubCommitsPinnableItem instance) => + {}; + +GithubCommitsStarrable _$GithubCommitsStarrableFromJson( + Map json) { + return GithubCommitsStarrable()..resolveType = json['__typename'] as String; +} + +Map _$GithubCommitsStarrableToJson( + GithubCommitsStarrable instance) => + { + '__typename': instance.resolveType, + }; + +GithubCommitsRepositoryInfo _$GithubCommitsRepositoryInfoFromJson( + Map json) { + return GithubCommitsRepositoryInfo() + ..resolveType = json['__typename'] as String; +} + +Map _$GithubCommitsRepositoryInfoToJson( + GithubCommitsRepositoryInfo instance) => + { + '__typename': instance.resolveType, + }; + +GithubCommitsArguments _$GithubCommitsArgumentsFromJson( + Map json) { + return GithubCommitsArguments( + owner: json['owner'] as String, + name: json['name'] as String, + ref: json['ref'] as String, + hasRef: json['hasRef'] as bool, + after: json['after'] as String, + ); +} + +Map _$GithubCommitsArgumentsToJson( + GithubCommitsArguments instance) => + { + 'owner': instance.owner, + 'name': instance.name, + 'ref': instance.ref, + 'hasRef': instance.hasRef, + 'after': instance.after, + }; diff --git a/lib/graphql/github_commits.graphql b/lib/graphql/github_commits.graphql new file mode 100644 index 0000000..82370d4 --- /dev/null +++ b/lib/graphql/github_commits.graphql @@ -0,0 +1,60 @@ +fragment T on Ref { + target { + ... on Commit { + oid + url + messageHeadline + committedDate + author { + name + avatarUrl + user { + login + } + } + # status { + # state + # } + __typename + history(first: 30, after: $after) { + pageInfo { + hasNextPage + endCursor + } + nodes { + oid + url + messageHeadline + committedDate + author { + name + avatarUrl + user { + login + } + } + # status { + # state + # } + } + } + } + } +} + +query( + $owner: String! + $name: String! + $ref: String! + $hasRef: Boolean! + $after: String +) { + repository(owner: $owner, name: $name) { + defaultBranchRef @skip(if: $hasRef) { + ...T + } + ref(qualifiedName: $ref) @include(if: $hasRef) { + ...T + } + } +} diff --git a/lib/screens/commits.dart b/lib/screens/commits.dart index 27b9fed..b06c8cc 100644 --- a/lib/screens/commits.dart +++ b/lib/screens/commits.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:git_touch/graphql/github_commits.dart'; import 'package:git_touch/models/auth.dart'; import 'package:git_touch/scaffolds/list_stateful.dart'; import 'package:git_touch/utils/utils.dart'; @@ -21,55 +22,22 @@ class CommitsScreen extends StatelessWidget { CommitsScreen(this.owner, this.name, {this.branch}); - Future _query(BuildContext context, [String cursor]) async { - var params = 'first: 30'; - if (cursor != null) { - params += ', after: "$cursor"'; - } - var key = getBranchQueryKey(branch, withParams: true); - var data = await Provider.of(context).query(''' -{ - repository(owner: "$owner", name: "$name") { - $key { - target { - ... on Commit { - history($params) { - pageInfo { - hasNextPage - endCursor - } - nodes { - oid - url - messageHeadline - committedDate - author { - name - email - avatarUrl - user { - login - } - } - status { - state - } - } - } - } - } - } - } -} - '''); - - var history = - data["repository"][getBranchQueryKey(branch)]['target']['history']; - + Future> _query(BuildContext context, + [String cursor]) async { + final res = await Provider.of(context).gqlClient.execute( + GithubCommitsQuery( + variables: GithubCommitsArguments( + owner: owner, + name: name, + hasRef: branch != null, + ref: branch ?? '', + after: cursor))); + final ref = res.data.repository.defaultBranchRef ?? res.data.repository.ref; + final history = (ref.target as GithubCommitsCommit).history; return ListPayload( - cursor: history["pageInfo"]["endCursor"], - hasMore: history['pageInfo']['hasNextPage'], - items: history["nodes"], + cursor: history.pageInfo.endCursor, + hasMore: history.pageInfo.hasNextPage, + items: history.nodes, ); } @@ -87,46 +55,43 @@ class CommitsScreen extends StatelessWidget { @override Widget build(BuildContext context) { - return ListStatefulScaffold( + return ListStatefulScaffold( title: AppBarTitle('Commits'), onRefresh: () => _query(context), onLoadMore: (cursor) => _query(context, cursor), itemBuilder: (payload) { return Link( - url: payload['url'], + url: payload.url, child: Container( padding: CommonStyle.padding, child: Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Avatar.medium(url: payload['author']['avatarUrl']), + Avatar.medium(url: payload.author.avatarUrl), SizedBox(width: 8), Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text(payload['messageHeadline'], + Text(payload.messageHeadline, style: TextStyle( fontWeight: FontWeight.w500, fontSize: 14)), SizedBox(height: 4), Wrap( children: [ Text( - payload['author']['user'] == null - ? payload['author']['name'] - : payload['author']['user']['login'], + payload.author.user?.login ?? payload.author.name, style: TextStyle( fontWeight: FontWeight.w500, fontSize: 14)), Text( ' committed ' + - timeago.format( - DateTime.parse(payload['committedDate'])), + timeago.format(payload.committedDate), style: TextStyle( color: PrimerColors.gray600, fontSize: 14)), - if (payload['status'] != null) ...[ - SizedBox(width: 4), - _buildStatus(payload['status']['state']) - ], + // if (payload['status'] != null) ...[ + // SizedBox(width: 4), + // _buildStatus(payload['status']['state']) + // ], TODO: ], ) ],