Skip to content

Commit db50b54

Browse files
committed
Simplify GraphQL mutations whose response we are not interested in
1 parent 886f5e0 commit db50b54

File tree

3 files changed

+15
-33
lines changed

3 files changed

+15
-33
lines changed

pkg/cmd/issue/edit/edit_test.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -437,26 +437,22 @@ func mockIssueUpdate(t *testing.T, reg *httpmock.Registry) {
437437
reg.Register(
438438
httpmock.GraphQL(`mutation IssueUpdate\b`),
439439
httpmock.GraphQLMutation(`
440-
{ "data": { "updateIssue": { "issue": {
441-
"id": "123"
442-
} } } }`,
440+
{ "data": { "updateIssue": { "__typename": "" } } }`,
443441
func(inputs map[string]interface{}) {}),
444442
)
445443
}
446444

447445
func mockIssueUpdateLabels(t *testing.T, reg *httpmock.Registry) {
448446
reg.Register(
449-
httpmock.GraphQL(`mutation AddLabels\b`),
447+
httpmock.GraphQL(`mutation LabelAdd\b`),
450448
httpmock.GraphQLMutation(`
451-
{ "data": { "addLabelsToLabelable": { "labelable": {
452-
} } } }`,
449+
{ "data": { "addLabelsToLabelable": { "__typename": "" } } }`,
453450
func(inputs map[string]interface{}) {}),
454451
)
455452
reg.Register(
456-
httpmock.GraphQL(`mutation RemoveLabels\b`),
453+
httpmock.GraphQL(`mutation LabelRemove\b`),
457454
httpmock.GraphQLMutation(`
458-
{ "data": { "removeLabelsFromLabelable": { "labelable": {
459-
} } } }`,
455+
{ "data": { "removeLabelsFromLabelable": { "__typename": "" } } }`,
460456
func(inputs map[string]interface{}) {}),
461457
)
462458
}

pkg/cmd/pr/edit/edit_test.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -559,17 +559,15 @@ func mockPullRequestReviewersUpdate(t *testing.T, reg *httpmock.Registry) {
559559

560560
func mockPullRequestUpdateLabels(t *testing.T, reg *httpmock.Registry) {
561561
reg.Register(
562-
httpmock.GraphQL(`mutation AddLabels\b`),
562+
httpmock.GraphQL(`mutation LabelAdd\b`),
563563
httpmock.GraphQLMutation(`
564-
{ "data": { "addLabelsToLabelable": { "labelable": {
565-
} } } }`,
564+
{ "data": { "addLabelsToLabelable": { "__typename": "" } } }`,
566565
func(inputs map[string]interface{}) {}),
567566
)
568567
reg.Register(
569-
httpmock.GraphQL(`mutation RemoveLabels\b`),
568+
httpmock.GraphQL(`mutation LabelRemove\b`),
570569
httpmock.GraphQLMutation(`
571-
{ "data": { "removeLabelsFromLabelable": { "labelable": {
572-
} } } }`,
570+
{ "data": { "removeLabelsFromLabelable": { "__typename": "" } } }`,
573571
func(inputs map[string]interface{}) {}),
574572
)
575573
}

pkg/cmd/pr/shared/editable_http.go

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,13 @@ func addLabels(httpClient *http.Client, id string, repo ghrepo.Interface, labels
108108

109109
var mutation struct {
110110
AddLabelsToLabelable struct {
111-
Labelable struct {
112-
Labels struct {
113-
TotalCount int
114-
}
115-
}
111+
Typename string `graphql:"__typename"`
116112
} `graphql:"addLabelsToLabelable(input: $input)"`
117113
}
118114

119115
variables := map[string]interface{}{"input": params}
120116
gql := graphql.NewClient(ghinstance.GraphQLEndpoint(repo.RepoHost()), httpClient)
121-
return gql.MutateNamed(context.Background(), "AddLabels", &mutation, variables)
117+
return gql.MutateNamed(context.Background(), "LabelAdd", &mutation, variables)
122118
}
123119

124120
func removeLabels(httpClient *http.Client, id string, repo ghrepo.Interface, labels []string) error {
@@ -129,25 +125,19 @@ func removeLabels(httpClient *http.Client, id string, repo ghrepo.Interface, lab
129125

130126
var mutation struct {
131127
RemoveLabelsFromLabelable struct {
132-
Labelable struct {
133-
Labels struct {
134-
TotalCount int
135-
}
136-
}
128+
Typename string `graphql:"__typename"`
137129
} `graphql:"removeLabelsFromLabelable(input: $input)"`
138130
}
139131

140132
variables := map[string]interface{}{"input": params}
141133
gql := graphql.NewClient(ghinstance.GraphQLEndpoint(repo.RepoHost()), httpClient)
142-
return gql.MutateNamed(context.Background(), "RemoveLabels", &mutation, variables)
134+
return gql.MutateNamed(context.Background(), "LabelRemove", &mutation, variables)
143135
}
144136

145137
func updateIssue(httpClient *http.Client, repo ghrepo.Interface, params githubv4.UpdateIssueInput) error {
146138
var mutation struct {
147139
UpdateIssue struct {
148-
Issue struct {
149-
ID string
150-
}
140+
Typename string `graphql:"__typename"`
151141
} `graphql:"updateIssue(input: $input)"`
152142
}
153143
variables := map[string]interface{}{"input": params}
@@ -158,9 +148,7 @@ func updateIssue(httpClient *http.Client, repo ghrepo.Interface, params githubv4
158148
func updatePullRequest(httpClient *http.Client, repo ghrepo.Interface, params githubv4.UpdatePullRequestInput) error {
159149
var mutation struct {
160150
UpdatePullRequest struct {
161-
PullRequest struct {
162-
ID string
163-
}
151+
Typename string `graphql:"__typename"`
164152
} `graphql:"updatePullRequest(input: $input)"`
165153
}
166154
variables := map[string]interface{}{"input": params}

0 commit comments

Comments
 (0)