Skip to content

Commit 2e3d082

Browse files
committed
feat: graphql codegen
Signed-off-by: Adam Setch <[email protected]>
1 parent a42ed24 commit 2e3d082

File tree

3 files changed

+30
-30
lines changed

3 files changed

+30
-30
lines changed

src/renderer/typesGitHub.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -488,12 +488,8 @@ export interface Release {
488488
published_at: string | null;
489489
}
490490

491-
export interface GraphQLSearch<T> {
492-
data: {
493-
search: {
494-
nodes: T[];
495-
};
496-
};
491+
export interface GitHubGraphQLResponse<TData> {
492+
data: TData;
497493
}
498494

499495
export interface Discussion {

src/renderer/utils/api/__mocks__/response-mocks.ts

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ import type {
88
DiscussionAuthor,
99
DiscussionComments,
1010
DiscussionLabels,
11+
GitHubGraphQLResponse,
1112
GraphQLSearch,
1213
Notification,
1314
Repository,
1415
User,
1516
} from '../../../typesGitHub';
17+
import type { FetchDiscussionsQuery } from '../graphql/generated/graphql';
1618

1719
export const mockNotificationUser: User = {
1820
login: 'octocat',
@@ -414,29 +416,30 @@ export const mockDiscussionLabels: DiscussionLabels = {
414416
],
415417
};
416418

417-
export const mockGraphQLResponse: GraphQLSearch<Discussion> = {
418-
data: {
419-
search: {
420-
nodes: [
421-
{
422-
number: 123,
423-
title: '1.16.0',
424-
isAnswered: false,
425-
stateReason: 'OPEN',
426-
url: 'https://github.com/gitify-app/notifications-test/discussions/612' as Link,
427-
author: {
428-
login: 'discussion-creator',
429-
url: 'https://github.com/discussion-creator' as Link,
430-
avatar_url:
431-
'https://avatars.githubusercontent.com/u/123456789?v=4' as Link,
432-
type: 'User',
419+
export const mockGraphQLResponse: GitHubGraphQLResponse<FetchDiscussionsQuery> =
420+
{
421+
data: {
422+
search: {
423+
nodes: [
424+
{
425+
number: 123,
426+
title: '1.16.0',
427+
isAnswered: false,
428+
stateReason: 'OPEN',
429+
url: 'https://github.com/gitify-app/notifications-test/discussions/612' as Link,
430+
author: {
431+
login: 'discussion-creator',
432+
url: 'https://github.com/discussion-creator' as Link,
433+
avatar_url:
434+
'https://avatars.githubusercontent.com/u/123456789?v=4' as Link,
435+
type: 'User',
436+
},
437+
comments: mockDiscussionComments,
438+
labels: mockDiscussionLabels,
433439
},
434-
comments: mockDiscussionComments,
435-
labels: mockDiscussionLabels,
436-
},
437-
],
440+
],
441+
},
438442
},
439-
},
440-
};
443+
};
441444

442445
export const mockSingleNotification: Notification = mockGitHubNotifications[0];

src/renderer/utils/api/client.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type {
1111
Commit,
1212
CommitComment,
1313
Discussion,
14-
GraphQLSearch,
14+
GitHubGraphQLResponse,
1515
Issue,
1616
IssueOrPullRequestComment,
1717
Notification,
@@ -24,6 +24,7 @@ import type {
2424
import { isAnsweredDiscussionFeatureSupported } from '../features';
2525
import { rendererLogError } from '../logger';
2626
import { QUERY_SEARCH_DISCUSSIONS } from './graphql/discussions';
27+
import type { FetchDiscussionsQuery } from './graphql/generated/graphql';
2728
import { formatAsGitHubSearchSyntax } from './graphql/utils';
2829
import { apiRequestAuth } from './request';
2930
import { getGitHubAPIBaseUrl, getGitHubGraphQLUrl } from './utils';
@@ -233,7 +234,7 @@ export async function getHtmlUrl(url: Link, token: Token): Promise<string> {
233234
*/
234235
export async function searchDiscussions(
235236
notification: Notification,
236-
): AxiosPromise<GraphQLSearch<Discussion>> {
237+
): AxiosPromise<GitHubGraphQLResponse<FetchDiscussionsQuery>> {
237238
const url = getGitHubGraphQLUrl(notification.account.hostname);
238239
return apiRequestAuth(
239240
url.toString() as Link,

0 commit comments

Comments
 (0)