Skip to content
Merged
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
9 changes: 8 additions & 1 deletion lib/Github/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,14 @@ private function setEnterpriseUrl($enterpriseUrl): void
$builder->removePlugin(PathPrepend::class);

$builder->addPlugin(new Plugin\AddHostPlugin(Psr17FactoryDiscovery::findUriFactory()->createUri($enterpriseUrl)));
$builder->addPlugin(new PathPrepend(sprintf('/api/%s', $this->getApiVersion())));

// For GHE, v4 API endpoint is at `api/graphql` so we don't want to add the version number
// For earlier versions add the version number after /api
if ($this->getApiVersion() === 'v4') {
$builder->addPlugin(new PathPrepend('/api'));
} else {
$builder->addPlugin(new PathPrepend(sprintf('/api/%s', $this->getApiVersion())));
}
}

/**
Expand Down
21 changes: 21 additions & 0 deletions test/Github/Tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,25 @@ public function testEnterpriseUrl()
$client = new Client($httpClientBuilder, null, 'https://foobar.com');
$client->enterprise()->stats()->show('all');
}

/**
* Make sure that the prepend is correct when using the v4 endpoint on Enterprise.
*/
public function testEnterprisePrependGraphQLV4()
{
$httpClientMock = $this->getMockBuilder(ClientInterface::class)
->setMethods(['sendRequest'])
->getMock();

$httpClientMock->expects($this->once())
->method('sendRequest')
->with($this->callback(function (RequestInterface $request) {
return (string) $request->getUri() === 'https://foobar.com/api/graphql';
}))
->willReturn(new Response(200, [], '[]'));

$httpClientBuilder = new Builder($httpClientMock);
$client = new Client($httpClientBuilder, 'v4', 'https://foobar.com');
$client->graphql()->execute('query');
}
}