diff --git a/src/main/java/org/kohsuke/github/GitHub.java b/src/main/java/org/kohsuke/github/GitHub.java index cb47de47af..9204660a92 100644 --- a/src/main/java/org/kohsuke/github/GitHub.java +++ b/src/main/java/org/kohsuke/github/GitHub.java @@ -1285,6 +1285,7 @@ protected GHUser getUser(GHUser orig) { @Nonnull Requester createGraphQLRequest(String query) { return createRequest().method("POST") + .withApiUrl(getApiUrl().replace("/api/v3", "/api")) .rateLimit(RateLimitTarget.GRAPHQL) .with("query", query) .withUrlPath("/graphql"); diff --git a/src/test/java/org/kohsuke/github/GitHubConnectionTest.java b/src/test/java/org/kohsuke/github/GitHubConnectionTest.java index 148e06ec49..c79fdb3bd2 100644 --- a/src/test/java/org/kohsuke/github/GitHubConnectionTest.java +++ b/src/test/java/org/kohsuke/github/GitHubConnectionTest.java @@ -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. + *

+ * GitHub Enterprise Server has REST API at /api/v3 but GraphQL at /api/graphql. + *

+ * + * @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. *