Skip to content

Commit 36bc9ff

Browse files
committed
organize code
1 parent 5a90355 commit 36bc9ff

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

src/App.js

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ const axiosGitHubGraphQL = axios.create({
1313
const title = 'React GraphQL GitHub Client';
1414

1515
const issuesOfRepositoryQuery = `
16-
query ($organization: String!, $repository: String!, $cursor: String) {
16+
query (
17+
$organization: String!,
18+
$repository: String!,
19+
$cursor: String
20+
) {
1721
organization(login: $organization) {
1822
name
1923
url
@@ -81,6 +85,20 @@ const getIssuesOfRepository = (path, cursor) => {
8185
});
8286
};
8387

88+
const addStarToRepository = repositoryId => {
89+
return axiosGitHubGraphQL.post('', {
90+
query: addStarToRepositoryMutation,
91+
variables: { repositoryId },
92+
});
93+
};
94+
95+
const removeStarFromRepository = repositoryId => {
96+
return axiosGitHubGraphQL.post('', {
97+
query: removeStarToRepositoryMutation,
98+
variables: { repositoryId },
99+
});
100+
};
101+
84102
const resolveIssuesQuery = queryResult => state => {
85103
const oldIssues = state.organization
86104
? state.organization.repository.issues.edges
@@ -90,35 +108,23 @@ const resolveIssuesQuery = queryResult => state => {
90108
edges: newIssues,
91109
} = queryResult.data.data.organization.repository.issues;
92110

111+
const updatedIssues = [...oldIssues, ...newIssues];
112+
93113
return {
94114
organization: {
95115
...queryResult.data.data.organization,
96116
repository: {
97117
...queryResult.data.data.organization.repository,
98118
issues: {
99119
...queryResult.data.data.organization.repository.issues,
100-
edges: [...oldIssues, ...newIssues],
120+
edges: updatedIssues,
101121
},
102122
},
103123
},
104124
errors: queryResult.data.errors,
105125
};
106126
};
107127

108-
const addStarToRepository = repositoryId => {
109-
return axiosGitHubGraphQL.post('', {
110-
query: addStarToRepositoryMutation,
111-
variables: { repositoryId },
112-
});
113-
};
114-
115-
const removeStarFromRepository = repositoryId => {
116-
return axiosGitHubGraphQL.post('', {
117-
query: removeStarToRepositoryMutation,
118-
variables: { repositoryId },
119-
});
120-
};
121-
122128
const resolveAddStarMutation = mutationResult => state => {
123129
const {
124130
viewerHasStarred,

0 commit comments

Comments
 (0)