Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/org/kohsuke/github/GitHub.java
Original file line number Diff line number Diff line change
Expand Up @@ -1285,6 +1285,7 @@ protected GHUser getUser(GHUser orig) {
@Nonnull
Requester createGraphQLRequest(String query) {
return createRequest().method("POST")
.withApiUrl(getApiUrl().replace("/api/v3", "/api"))
Copy link
Member

@bitwiseman bitwiseman Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changed behavior isn't really tested by any existing test. Because of how it is written, code coverage doesn't catch it. On the plus side, we know this doesn't break the GitHub.com scenario, but we don't have any verification of the enterprise scenario.

Please add a test to the enterprise github tests that calls createGraphQLRequest and verifies the Requester has the new expected /api/graphql URL. You don't have actually make the http call, just check the value.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the review @bitwiseman!
I pushed the changes.
Meanwhile, could you please invite me to hub4j-test-org for later PRs that I want to make? I need to run the tests locally for those.

.rateLimit(RateLimitTarget.GRAPHQL)
.with("query", query)
.withUrlPath("/graphql");
Expand Down
29 changes: 29 additions & 0 deletions src/test/java/org/kohsuke/github/GitHubConnectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,35 @@ public void testGitHubBuilderFromEnvironment() throws IOException {

}

/**
* Test that GitHub.com GraphQL URL is correctly constructed.
*
* @throws Exception
* the exception
*/
@Test
public void testGitHubCloudGraphQLUrl() throws Exception {
GitHub hub = GitHub.connect("bogus", "bogus");
GitHubRequest request = hub.createGraphQLRequest("test query").build();
assertThat(request.url().toString(), equalTo("https://api.github.com/graphql"));
}

/**
* Test that GitHub Enterprise GraphQL URL is correctly constructed.
* <p>
* GitHub Enterprise Server has REST API at /api/v3 but GraphQL at /api/graphql.
* </p>
*
* @throws Exception
* the exception
*/
@Test
public void testGitHubEnterpriseGraphQLUrl() throws Exception {
GitHub hub = GitHub.connectToEnterpriseWithOAuth("https://enterprise.kohsuke.org/api/v3", "bogus", "bogus");
GitHubRequest request = hub.createGraphQLRequest("test query").build();
assertThat(request.url().toString(), equalTo("https://enterprise.kohsuke.org/api/graphql"));
}

/**
* Test git hub is api url valid.
*
Expand Down
Loading