Skip to content

Commit df92643

Browse files
committed
feat(api): codegen for discussions
Signed-off-by: Adam Setch <[email protected]>
1 parent bef371e commit df92643

File tree

8 files changed

+143
-308
lines changed

8 files changed

+143
-308
lines changed

codegen.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ const config: CodegenConfig = {
1717
generates: {
1818
'src/renderer/utils/api/graphql/generated/': {
1919
preset: 'client',
20+
presetConfig: {
21+
fragmentMasking: false, // Disables masking
22+
},
2023
config: {
2124
documentMode: 'string',
2225
useTypeImports: true,

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

Lines changed: 39 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -368,83 +368,54 @@ export const mockEnterpriseNotifications: Notification[] = [
368368
},
369369
];
370370

371-
const mockDiscussionAuthor = {
372-
__typename: 'User' as const,
373-
' $fragmentRefs': {
374-
AuthorFields_User_Fragment: {
375-
__typename: 'User' as const,
376-
login: 'comment-user',
377-
url: 'https://github.com/comment-user' as Link,
378-
avatar_url:
379-
'https://avatars.githubusercontent.com/u/123456789?v=4' as Link,
380-
type: 'User' as const,
381-
},
382-
},
383-
};
384-
385-
const mockDiscussionReplier = {
386-
__typename: 'User' as const,
387-
' $fragmentRefs': {
388-
AuthorFields_User_Fragment: {
389-
__typename: 'User' as const,
390-
login: 'reply-user',
391-
url: 'https://github.com/reply-user' as Link,
392-
avatar_url:
393-
'https://avatars.githubusercontent.com/u/123456789?v=4' as Link,
394-
type: 'User' as const,
395-
},
396-
},
397-
};
398-
399-
const mockDiscussionComments = {
400-
totalCount: 2,
401-
nodes: [
402-
{
403-
__typename: 'DiscussionComment' as const,
404-
databaseId: 2258799,
405-
createdAt: '2017-02-20T17:51:57Z',
406-
author: mockDiscussionAuthor,
407-
replies: {
408-
__typename: 'DiscussionCommentConnection' as const,
409-
nodes: [
410-
{
411-
__typename: 'DiscussionComment' as const,
412-
databaseId: 2300902,
413-
createdAt: '2017-05-20T17:51:57Z',
414-
author: mockDiscussionReplier,
415-
replies: {
416-
__typename: 'DiscussionCommentConnection' as const,
417-
nodes: [],
418-
},
419-
},
420-
],
421-
},
422-
},
423-
],
424-
};
425-
426-
const mockDiscussionLabels = {
427-
nodes: [
428-
{
429-
name: 'enhancement',
430-
},
431-
],
432-
};
433-
434371
export const mockDiscussionByNumberGraphQLResponse: FetchDiscussionByNumberQuery =
435372
{
436373
repository: {
437-
__typename: 'Repository',
438374
discussion: {
439-
__typename: 'Discussion' as const,
375+
__typename: 'Discussion',
440376
number: 123,
441377
title: '1.16.0',
442378
isAnswered: false,
443379
stateReason: null,
444380
url: 'https://github.com/gitify-app/notifications-test/discussions/612' as Link,
445-
author: mockDiscussionAuthor,
446-
comments: mockDiscussionComments,
447-
labels: mockDiscussionLabels,
381+
author: {
382+
login: 'comment-user',
383+
url: 'https://github.com/comment-user' as Link,
384+
avatar_url:
385+
'https://avatars.githubusercontent.com/u/123456789?v=4' as Link,
386+
type: 'User',
387+
},
388+
comments: {
389+
totalCount: 2,
390+
nodes: [
391+
{
392+
databaseId: 2258799,
393+
createdAt: '2017-02-20T17:51:57Z',
394+
author: {
395+
login: 'comment-user',
396+
url: 'https://github.com/comment-user' as Link,
397+
avatar_url:
398+
'https://avatars.githubusercontent.com/u/123456789?v=4' as Link,
399+
type: 'User',
400+
},
401+
replies: {
402+
nodes: [
403+
{
404+
databaseId: 2300902,
405+
createdAt: '2017-05-20T17:51:57Z',
406+
author: {
407+
login: 'reply-user',
408+
url: 'https://github.com/reply-user' as Link,
409+
avatar_url:
410+
'https://avatars.githubusercontent.com/u/123456789?v=4' as Link,
411+
type: 'User',
412+
},
413+
},
414+
],
415+
},
416+
},
417+
],
418+
},
448419
},
449420
},
450421
};

src/renderer/utils/api/graphql/discussions.graphql

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,4 @@
1-
fragment AuthorFields on Actor {
2-
login
3-
url
4-
avatar_url: avatarUrl
5-
type: __typename
6-
}
7-
8-
fragment CommentFields on DiscussionComment {
9-
databaseId
10-
createdAt
11-
author {
12-
...AuthorFields
13-
}
14-
}
15-
16-
query fetchDiscussionByNumber(
1+
query FetchDiscussionByNumber(
172
$owner: String!
183
$name: String!
194
$number: Int!
@@ -52,3 +37,18 @@ query fetchDiscussionByNumber(
5237
}
5338
}
5439
}
40+
41+
fragment AuthorFields on Actor {
42+
login
43+
url
44+
avatar_url: avatarUrl
45+
type: __typename
46+
}
47+
48+
fragment CommentFields on DiscussionComment {
49+
databaseId
50+
createdAt
51+
author {
52+
...AuthorFields
53+
}
54+
}

src/renderer/utils/api/graphql/generated/fragment-masking.ts

Lines changed: 0 additions & 83 deletions
This file was deleted.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ import * as types from './graphql';
1515
* Learn more about it here: https://the-guild.dev/graphql/codegen/plugins/presets/preset-client#reducing-bundle-size
1616
*/
1717
type Documents = {
18-
"fragment AuthorFields on Actor {\n login\n url\n avatar_url: avatarUrl\n type: __typename\n}\n\nfragment CommentFields on DiscussionComment {\n databaseId\n createdAt\n author {\n ...AuthorFields\n }\n}\n\nquery fetchDiscussionByNumber($owner: String!, $name: String!, $number: Int!, $lastComments: Int, $lastReplies: Int, $firstLabels: Int, $includeIsAnswered: Boolean!) {\n repository(owner: $owner, name: $name) {\n discussion(number: $number) {\n __typename\n number\n title\n stateReason\n isAnswered @include(if: $includeIsAnswered)\n url\n author {\n ...AuthorFields\n }\n comments(last: $lastComments) {\n totalCount\n nodes {\n ...CommentFields\n replies(last: $lastReplies) {\n nodes {\n ...CommentFields\n }\n }\n }\n }\n labels(first: $firstLabels) {\n nodes {\n name\n }\n }\n }\n }\n}": typeof types.AuthorFieldsFragmentDoc,
18+
"query FetchDiscussionByNumber($owner: String!, $name: String!, $number: Int!, $lastComments: Int, $lastReplies: Int, $firstLabels: Int, $includeIsAnswered: Boolean!) {\n repository(owner: $owner, name: $name) {\n discussion(number: $number) {\n __typename\n number\n title\n stateReason\n isAnswered @include(if: $includeIsAnswered)\n url\n author {\n ...AuthorFields\n }\n comments(last: $lastComments) {\n totalCount\n nodes {\n ...CommentFields\n replies(last: $lastReplies) {\n nodes {\n ...CommentFields\n }\n }\n }\n }\n labels(first: $firstLabels) {\n nodes {\n name\n }\n }\n }\n }\n}\n\nfragment AuthorFields on Actor {\n login\n url\n avatar_url: avatarUrl\n type: __typename\n}\n\nfragment CommentFields on DiscussionComment {\n databaseId\n createdAt\n author {\n ...AuthorFields\n }\n}": typeof types.FetchDiscussionByNumberDocument,
1919
};
2020
const documents: Documents = {
21-
"fragment AuthorFields on Actor {\n login\n url\n avatar_url: avatarUrl\n type: __typename\n}\n\nfragment CommentFields on DiscussionComment {\n databaseId\n createdAt\n author {\n ...AuthorFields\n }\n}\n\nquery fetchDiscussionByNumber($owner: String!, $name: String!, $number: Int!, $lastComments: Int, $lastReplies: Int, $firstLabels: Int, $includeIsAnswered: Boolean!) {\n repository(owner: $owner, name: $name) {\n discussion(number: $number) {\n __typename\n number\n title\n stateReason\n isAnswered @include(if: $includeIsAnswered)\n url\n author {\n ...AuthorFields\n }\n comments(last: $lastComments) {\n totalCount\n nodes {\n ...CommentFields\n replies(last: $lastReplies) {\n nodes {\n ...CommentFields\n }\n }\n }\n }\n labels(first: $firstLabels) {\n nodes {\n name\n }\n }\n }\n }\n}": types.AuthorFieldsFragmentDoc,
21+
"query FetchDiscussionByNumber($owner: String!, $name: String!, $number: Int!, $lastComments: Int, $lastReplies: Int, $firstLabels: Int, $includeIsAnswered: Boolean!) {\n repository(owner: $owner, name: $name) {\n discussion(number: $number) {\n __typename\n number\n title\n stateReason\n isAnswered @include(if: $includeIsAnswered)\n url\n author {\n ...AuthorFields\n }\n comments(last: $lastComments) {\n totalCount\n nodes {\n ...CommentFields\n replies(last: $lastReplies) {\n nodes {\n ...CommentFields\n }\n }\n }\n }\n labels(first: $firstLabels) {\n nodes {\n name\n }\n }\n }\n }\n}\n\nfragment AuthorFields on Actor {\n login\n url\n avatar_url: avatarUrl\n type: __typename\n}\n\nfragment CommentFields on DiscussionComment {\n databaseId\n createdAt\n author {\n ...AuthorFields\n }\n}": types.FetchDiscussionByNumberDocument,
2222
};
2323

2424
/**
2525
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
2626
*/
27-
export function graphql(source: "fragment AuthorFields on Actor {\n login\n url\n avatar_url: avatarUrl\n type: __typename\n}\n\nfragment CommentFields on DiscussionComment {\n databaseId\n createdAt\n author {\n ...AuthorFields\n }\n}\n\nquery fetchDiscussionByNumber($owner: String!, $name: String!, $number: Int!, $lastComments: Int, $lastReplies: Int, $firstLabels: Int, $includeIsAnswered: Boolean!) {\n repository(owner: $owner, name: $name) {\n discussion(number: $number) {\n __typename\n number\n title\n stateReason\n isAnswered @include(if: $includeIsAnswered)\n url\n author {\n ...AuthorFields\n }\n comments(last: $lastComments) {\n totalCount\n nodes {\n ...CommentFields\n replies(last: $lastReplies) {\n nodes {\n ...CommentFields\n }\n }\n }\n }\n labels(first: $firstLabels) {\n nodes {\n name\n }\n }\n }\n }\n}"): typeof import('./graphql').AuthorFieldsFragmentDoc;
27+
export function graphql(source: "query FetchDiscussionByNumber($owner: String!, $name: String!, $number: Int!, $lastComments: Int, $lastReplies: Int, $firstLabels: Int, $includeIsAnswered: Boolean!) {\n repository(owner: $owner, name: $name) {\n discussion(number: $number) {\n __typename\n number\n title\n stateReason\n isAnswered @include(if: $includeIsAnswered)\n url\n author {\n ...AuthorFields\n }\n comments(last: $lastComments) {\n totalCount\n nodes {\n ...CommentFields\n replies(last: $lastReplies) {\n nodes {\n ...CommentFields\n }\n }\n }\n }\n labels(first: $firstLabels) {\n nodes {\n name\n }\n }\n }\n }\n}\n\nfragment AuthorFields on Actor {\n login\n url\n avatar_url: avatarUrl\n type: __typename\n}\n\nfragment CommentFields on DiscussionComment {\n databaseId\n createdAt\n author {\n ...AuthorFields\n }\n}"): typeof import('./graphql').FetchDiscussionByNumberDocument;
2828

2929

3030
export function graphql(source: string) {

0 commit comments

Comments
 (0)