Skip to content

Commit f748642

Browse files
authored
fix: adjust enterprise api url for graphql use case (#2180)
* fix: adjust enterprise api url for graphql use case * chore: add tests to validate GraphQL url construction
1 parent 9d6e3fd commit f748642

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/main/java/org/kohsuke/github/GitHub.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,6 +1285,7 @@ protected GHUser getUser(GHUser orig) {
12851285
@Nonnull
12861286
Requester createGraphQLRequest(String query) {
12871287
return createRequest().method("POST")
1288+
.withApiUrl(getApiUrl().replace("/api/v3", "/api"))
12881289
.rateLimit(RateLimitTarget.GRAPHQL)
12891290
.with("query", query)
12901291
.withUrlPath("/graphql");

src/test/java/org/kohsuke/github/GitHubConnectionTest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,35 @@ public void testGitHubBuilderFromEnvironment() throws IOException {
207207

208208
}
209209

210+
/**
211+
* Test that GitHub.com GraphQL URL is correctly constructed.
212+
*
213+
* @throws Exception
214+
* the exception
215+
*/
216+
@Test
217+
public void testGitHubCloudGraphQLUrl() throws Exception {
218+
GitHub hub = GitHub.connect("bogus", "bogus");
219+
GitHubRequest request = hub.createGraphQLRequest("test query").build();
220+
assertThat(request.url().toString(), equalTo("https://api.github.com/graphql"));
221+
}
222+
223+
/**
224+
* Test that GitHub Enterprise GraphQL URL is correctly constructed.
225+
* <p>
226+
* GitHub Enterprise Server has REST API at /api/v3 but GraphQL at /api/graphql.
227+
* </p>
228+
*
229+
* @throws Exception
230+
* the exception
231+
*/
232+
@Test
233+
public void testGitHubEnterpriseGraphQLUrl() throws Exception {
234+
GitHub hub = GitHub.connectToEnterpriseWithOAuth("https://enterprise.kohsuke.org/api/v3", "bogus", "bogus");
235+
GitHubRequest request = hub.createGraphQLRequest("test query").build();
236+
assertThat(request.url().toString(), equalTo("https://enterprise.kohsuke.org/api/graphql"));
237+
}
238+
210239
/**
211240
* Test git hub is api url valid.
212241
*

0 commit comments

Comments
 (0)