File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -346,7 +346,14 @@ private function setEnterpriseUrl($enterpriseUrl): void
346346 $ builder ->removePlugin (PathPrepend::class);
347347
348348 $ builder ->addPlugin (new Plugin \AddHostPlugin (Psr17FactoryDiscovery::findUriFactory ()->createUri ($ enterpriseUrl )));
349- $ builder ->addPlugin (new PathPrepend (sprintf ('/api/%s ' , $ this ->getApiVersion ())));
349+
350+ // For GHE, v4 API endpoint is at `api/graphql` so we don't want to add the version number
351+ // For earlier versions add the version number after /api
352+ if ($ this ->getApiVersion () === 'v4 ' ) {
353+ $ builder ->addPlugin (new PathPrepend ('/api ' ));
354+ } else {
355+ $ builder ->addPlugin (new PathPrepend (sprintf ('/api/%s ' , $ this ->getApiVersion ())));
356+ }
350357 }
351358
352359 /**
Original file line number Diff line number Diff line change @@ -223,4 +223,25 @@ public function testEnterpriseUrl()
223223 $ client = new Client ($ httpClientBuilder , null , 'https://foobar.com ' );
224224 $ client ->enterprise ()->stats ()->show ('all ' );
225225 }
226+
227+ /**
228+ * Make sure that the prepend is correct when using the v4 endpoint on Enterprise
229+ */
230+ public function testEnterprisePrependGraphQLV4 ()
231+ {
232+ $ httpClientMock = $ this ->getMockBuilder (ClientInterface::class)
233+ ->setMethods (['sendRequest ' ])
234+ ->getMock ();
235+
236+ $ httpClientMock ->expects ($ this ->once ())
237+ ->method ('sendRequest ' )
238+ ->with ($ this ->callback (function (RequestInterface $ request ) {
239+ return (string ) $ request ->getUri () === 'https://foobar.com/api/graphql ' ;
240+ }))
241+ ->willReturn (new Response (200 , [], '[] ' ));
242+
243+ $ httpClientBuilder = new Builder ($ httpClientMock );
244+ $ client = new Client ($ httpClientBuilder , 'v4 ' , 'https://foobar.com ' );
245+ $ client ->graphql ()->execute ('query ' );
246+ }
226247}
You can’t perform that action at this time.
0 commit comments