Skip to content

Commit 05f95f7

Browse files
authored
refactor(api): use fragments for nested types (#2471)
Signed-off-by: Adam Setch <[email protected]>
1 parent 95f85a7 commit 05f95f7

File tree

8 files changed

+114
-67
lines changed

8 files changed

+114
-67
lines changed

src/renderer/utils/api/graphql/common.graphql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@ fragment AuthorFields on Actor {
44
avatar_url: avatarUrl
55
type: __typename
66
}
7+
8+
fragment MilestoneFields on Milestone {
9+
state
10+
title
11+
}

src/renderer/utils/api/graphql/discussion.graphql

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,7 @@ query FetchDiscussionByNumber(
2121
comments(last: $lastComments) {
2222
totalCount
2323
nodes {
24-
...CommentFields
25-
replies(last: $lastReplies) {
26-
totalCount
27-
nodes {
28-
...CommentFields
29-
}
30-
}
24+
...DiscussionCommentFields
3125
}
3226
}
3327
labels(first: $firstLabels) {
@@ -47,3 +41,13 @@ fragment CommentFields on DiscussionComment {
4741
}
4842
url
4943
}
44+
45+
fragment DiscussionCommentFields on DiscussionComment {
46+
...CommentFields
47+
replies(last: $lastReplies) {
48+
totalCount
49+
nodes {
50+
...CommentFields
51+
}
52+
}
53+
}

src/renderer/utils/api/graphql/generated/gql.ts

Lines changed: 12 additions & 12 deletions
Large diffs are not rendered by default.

src/renderer/utils/api/graphql/generated/graphql.ts

Lines changed: 77 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35912,6 +35912,8 @@ export type AuthorFieldsFragment =
3591235912
| AuthorFields_User_Fragment
3591335913
;
3591435914

35915+
export type MilestoneFieldsFragment = { __typename?: 'Milestone', state: MilestoneState, title: string };
35916+
3591535917
export type FetchDiscussionByNumberQueryVariables = Exact<{
3591635918
owner: Scalars['String']['input'];
3591735919
name: Scalars['String']['input'];
@@ -35951,6 +35953,20 @@ export type CommentFieldsFragment = { __typename?: 'DiscussionComment', database
3595135953
| { __typename?: 'User', login: string, html_url: any, avatar_url: any, type: 'User' }
3595235954
| null };
3595335955

35956+
export type DiscussionCommentFieldsFragment = { __typename?: 'DiscussionComment', databaseId?: number | null, createdAt: any, url: any, replies: { __typename?: 'DiscussionCommentConnection', totalCount: number, nodes?: Array<{ __typename?: 'DiscussionComment', databaseId?: number | null, createdAt: any, url: any, author?:
35957+
| { __typename?: 'Bot', login: string, html_url: any, avatar_url: any, type: 'Bot' }
35958+
| { __typename?: 'EnterpriseUserAccount', login: string, html_url: any, avatar_url: any, type: 'EnterpriseUserAccount' }
35959+
| { __typename?: 'Mannequin', login: string, html_url: any, avatar_url: any, type: 'Mannequin' }
35960+
| { __typename?: 'Organization', login: string, html_url: any, avatar_url: any, type: 'Organization' }
35961+
| { __typename?: 'User', login: string, html_url: any, avatar_url: any, type: 'User' }
35962+
| null } | null> | null }, author?:
35963+
| { __typename?: 'Bot', login: string, html_url: any, avatar_url: any, type: 'Bot' }
35964+
| { __typename?: 'EnterpriseUserAccount', login: string, html_url: any, avatar_url: any, type: 'EnterpriseUserAccount' }
35965+
| { __typename?: 'Mannequin', login: string, html_url: any, avatar_url: any, type: 'Mannequin' }
35966+
| { __typename?: 'Organization', login: string, html_url: any, avatar_url: any, type: 'Organization' }
35967+
| { __typename?: 'User', login: string, html_url: any, avatar_url: any, type: 'User' }
35968+
| null };
35969+
3595435970
export type FetchIssueByNumberQueryVariables = Exact<{
3595535971
owner: Scalars['String']['input'];
3595635972
name: Scalars['String']['input'];
@@ -35974,8 +35990,6 @@ export type FetchIssueByNumberQuery = { __typename?: 'Query', repository?: { __t
3597435990
| { __typename?: 'User', login: string, html_url: any, avatar_url: any, type: 'User' }
3597535991
| null } | null> | null }, labels?: { __typename?: 'LabelConnection', nodes?: Array<{ __typename?: 'Label', name: string } | null> | null } | null } | null } | null };
3597635992

35977-
export type MilestoneFieldsFragment = { __typename?: 'Milestone', state: MilestoneState, title: string };
35978-
3597935993
export type FetchPullRequestByNumberQueryVariables = Exact<{
3598035994
owner: Scalars['String']['input'];
3598135995
name: Scalars['String']['input'];
@@ -36007,6 +36021,14 @@ export type FetchPullRequestByNumberQuery = { __typename?: 'Query', repository?:
3600736021
| { __typename?: 'User', login: string }
3600836022
| null } | null> | null } | null, labels?: { __typename?: 'LabelConnection', nodes?: Array<{ __typename?: 'Label', name: string } | null> | null } | null, closingIssuesReferences?: { __typename?: 'IssueConnection', nodes?: Array<{ __typename?: 'Issue', number: number } | null> | null } | null } | null } | null };
3600936023

36024+
export type PullRequestReviewFieldsFragment = { __typename?: 'PullRequestReview', state: PullRequestReviewState, author?:
36025+
| { __typename?: 'Bot', login: string }
36026+
| { __typename?: 'EnterpriseUserAccount', login: string }
36027+
| { __typename?: 'Mannequin', login: string }
36028+
| { __typename?: 'Organization', login: string }
36029+
| { __typename?: 'User', login: string }
36030+
| null };
36031+
3601036032
export class TypedDocumentString<TResult, TVariables>
3601136033
extends String
3601236034
implements DocumentTypeDecoration<TResult, TVariables>
@@ -36025,6 +36047,12 @@ export class TypedDocumentString<TResult, TVariables>
3602536047
return this.value;
3602636048
}
3602736049
}
36050+
export const MilestoneFieldsFragmentDoc = new TypedDocumentString(`
36051+
fragment MilestoneFields on Milestone {
36052+
state
36053+
title
36054+
}
36055+
`, {"fragmentName":"MilestoneFields"}) as unknown as TypedDocumentString<MilestoneFieldsFragment, unknown>;
3602836056
export const AuthorFieldsFragmentDoc = new TypedDocumentString(`
3602936057
fragment AuthorFields on Actor {
3603036058
login
@@ -36048,12 +36076,38 @@ export const CommentFieldsFragmentDoc = new TypedDocumentString(`
3604836076
avatar_url: avatarUrl
3604936077
type: __typename
3605036078
}`, {"fragmentName":"CommentFields"}) as unknown as TypedDocumentString<CommentFieldsFragment, unknown>;
36051-
export const MilestoneFieldsFragmentDoc = new TypedDocumentString(`
36052-
fragment MilestoneFields on Milestone {
36079+
export const DiscussionCommentFieldsFragmentDoc = new TypedDocumentString(`
36080+
fragment DiscussionCommentFields on DiscussionComment {
36081+
...CommentFields
36082+
replies(last: $lastReplies) {
36083+
totalCount
36084+
nodes {
36085+
...CommentFields
36086+
}
36087+
}
36088+
}
36089+
fragment AuthorFields on Actor {
36090+
login
36091+
html_url: url
36092+
avatar_url: avatarUrl
36093+
type: __typename
36094+
}
36095+
fragment CommentFields on DiscussionComment {
36096+
databaseId
36097+
createdAt
36098+
author {
36099+
...AuthorFields
36100+
}
36101+
url
36102+
}`, {"fragmentName":"DiscussionCommentFields"}) as unknown as TypedDocumentString<DiscussionCommentFieldsFragment, unknown>;
36103+
export const PullRequestReviewFieldsFragmentDoc = new TypedDocumentString(`
36104+
fragment PullRequestReviewFields on PullRequestReview {
3605336105
state
36054-
title
36106+
author {
36107+
login
36108+
}
3605536109
}
36056-
`, {"fragmentName":"MilestoneFields"}) as unknown as TypedDocumentString<MilestoneFieldsFragment, unknown>;
36110+
`, {"fragmentName":"PullRequestReviewFields"}) as unknown as TypedDocumentString<PullRequestReviewFieldsFragment, unknown>;
3605736111
export const FetchDiscussionByNumberDocument = new TypedDocumentString(`
3605836112
query FetchDiscussionByNumber($owner: String!, $name: String!, $number: Int!, $lastComments: Int, $lastReplies: Int, $firstLabels: Int, $includeIsAnswered: Boolean!) {
3605936113
repository(owner: $owner, name: $name) {
@@ -36070,13 +36124,7 @@ export const FetchDiscussionByNumberDocument = new TypedDocumentString(`
3607036124
comments(last: $lastComments) {
3607136125
totalCount
3607236126
nodes {
36073-
...CommentFields
36074-
replies(last: $lastReplies) {
36075-
totalCount
36076-
nodes {
36077-
...CommentFields
36078-
}
36079-
}
36127+
...DiscussionCommentFields
3608036128
}
3608136129
}
3608236130
labels(first: $firstLabels) {
@@ -36100,6 +36148,15 @@ fragment CommentFields on DiscussionComment {
3610036148
...AuthorFields
3610136149
}
3610236150
url
36151+
}
36152+
fragment DiscussionCommentFields on DiscussionComment {
36153+
...CommentFields
36154+
replies(last: $lastReplies) {
36155+
totalCount
36156+
nodes {
36157+
...CommentFields
36158+
}
36159+
}
3610336160
}`) as unknown as TypedDocumentString<FetchDiscussionByNumberQuery, FetchDiscussionByNumberQueryVariables>;
3610436161
export const FetchIssueByNumberDocument = new TypedDocumentString(`
3610536162
query FetchIssueByNumber($owner: String!, $name: String!, $number: Int!, $lastComments: Int, $firstLabels: Int) {
@@ -36174,10 +36231,7 @@ export const FetchPullRequestByNumberDocument = new TypedDocumentString(`
3617436231
reviews(last: $lastReviews) {
3617536232
totalCount
3617636233
nodes {
36177-
state
36178-
author {
36179-
login
36180-
}
36234+
...PullRequestReviewFields
3618136235
}
3618236236
}
3618336237
labels(first: $firstLabels) {
@@ -36202,4 +36256,10 @@ export const FetchPullRequestByNumberDocument = new TypedDocumentString(`
3620236256
fragment MilestoneFields on Milestone {
3620336257
state
3620436258
title
36259+
}
36260+
fragment PullRequestReviewFields on PullRequestReview {
36261+
state
36262+
author {
36263+
login
36264+
}
3620536265
}`) as unknown as TypedDocumentString<FetchPullRequestByNumberQuery, FetchPullRequestByNumberQueryVariables>;

src/renderer/utils/api/graphql/issue.graphql

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,3 @@ query FetchIssueByNumber(
3636
}
3737
}
3838
}
39-
40-
fragment MilestoneFields on Milestone {
41-
state
42-
title
43-
}

src/renderer/utils/api/graphql/pull.graphql

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@ query FetchPullRequestByNumber(
3535
reviews(last: $lastReviews) {
3636
totalCount
3737
nodes {
38-
state
39-
author {
40-
login
41-
}
38+
...PullRequestReviewFields
4239
}
4340
}
4441
labels(first: $firstLabels) {
@@ -55,7 +52,9 @@ query FetchPullRequestByNumber(
5552
}
5653
}
5754

58-
fragment MilestoneFields on Milestone {
55+
fragment PullRequestReviewFields on PullRequestReview {
5956
state
60-
title
57+
author {
58+
login
59+
}
6160
}

src/renderer/utils/notifications/handlers/discussion.ts

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,11 @@ import type { Notification, Subject } from '../../../typesGitHub';
2121
import { fetchDiscussionByNumber } from '../../api/client';
2222
import type {
2323
CommentFieldsFragment,
24-
FetchDiscussionByNumberQuery,
24+
DiscussionCommentFieldsFragment,
2525
} from '../../api/graphql/generated/graphql';
2626
import { DefaultHandler, defaultHandler } from './default';
2727
import { getNotificationAuthor } from './utils';
2828

29-
type DiscussionComment = NonNullable<
30-
NonNullable<
31-
NonNullable<
32-
NonNullable<
33-
Extract<
34-
NonNullable<FetchDiscussionByNumberQuery['repository']>,
35-
{ __typename?: 'Repository' }
36-
>['discussion']
37-
>
38-
>['comments']['nodes']
39-
>[number]
40-
>;
41-
4229
class DiscussionHandler extends DefaultHandler {
4330
readonly type = 'Discussion';
4431

@@ -112,7 +99,7 @@ export const discussionHandler = new DiscussionHandler();
11299

113100
export function getClosestDiscussionCommentOrReply(
114101
notification: Notification,
115-
comments: DiscussionComment[],
102+
comments: DiscussionCommentFieldsFragment[],
116103
): CommentFieldsFragment | null {
117104
if (!comments || comments.length === 0) {
118105
return null;

src/renderer/utils/notifications/handlers/pullRequest.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,10 @@ import {
1919
} from '../../../types';
2020
import type { Notification, Subject } from '../../../typesGitHub';
2121
import { fetchPullByNumber } from '../../api/client';
22-
import type { FetchPullRequestByNumberQuery } from '../../api/graphql/generated/graphql';
22+
import type { PullRequestReviewFieldsFragment } from '../../api/graphql/generated/graphql';
2323
import { DefaultHandler, defaultHandler } from './default';
2424
import { getNotificationAuthor } from './utils';
2525

26-
type PullRequestReviews =
27-
FetchPullRequestByNumberQuery['repository']['pullRequest']['reviews']['nodes'];
28-
2926
class PullRequestHandler extends DefaultHandler {
3027
readonly type = 'PullRequest' as const;
3128

@@ -104,7 +101,7 @@ class PullRequestHandler extends DefaultHandler {
104101
export const pullRequestHandler = new PullRequestHandler();
105102

106103
export function getLatestReviewForReviewers(
107-
reviews: PullRequestReviews,
104+
reviews: PullRequestReviewFieldsFragment[],
108105
): GitifyPullRequestReview[] {
109106
if (!reviews.length) {
110107
return null;

0 commit comments

Comments
 (0)