Skip to content

Commit

Permalink
Merge pull request #291 from commercetools/gen-sdk-updates
Browse files Browse the repository at this point in the history
Update generated SDKs
  • Loading branch information
kodiakhq[bot] authored Jan 2, 2025
2 parents 28445c6 + d91a4b2 commit a1b7145
Show file tree
Hide file tree
Showing 32 changed files with 2,231 additions and 0 deletions.
20 changes: 20 additions & 0 deletions changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,29 @@

**History changes**

<details>
<summary>Added Resource(s)</summary>

- added resource `/{projectKey}/graphql`
</details>


<details>
<summary>Added Method(s)</summary>

- added method `$apiRoot->withProjectKeyValue()->graphql()->post()`
</details>


<details>
<summary>Added Type(s)</summary>

- added type `GraphQLRequest`
- added type `GraphQLResponse`
- added type `GraphQLError`
- added type `GraphQLErrorLocation`
- added type `GraphQLVariablesMap`
- added type `GraphQLErrorObject`
- added type `ChangeTargetPatternChangeValue`
- added type `PatternComponent`
</details>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
<?php

declare(strict_types=1);
/**
* This file has been auto generated
* Do not change it.
*/

namespace Commercetools\History\Test\Client\Resource;

use PHPUnit\Framework\TestCase;
use Commercetools\Exception\ApiClientException;
use Commercetools\Exception\ApiServerException;
use Commercetools\Client\ApiRequest;
use Commercetools\Base\JsonObject;
use Commercetools\History\Client\HistoryRequestBuilder;
use Psr\Http\Message\RequestInterface;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\ServerException;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Psr7\Response;

/**
* @covers \Commercetools\History\Client\Resource\ByProjectKeyGraphqlPost
* @covers \Commercetools\History\Client\Resource\ResourceByProjectKeyGraphql
*/
class ResourceByProjectKeyGraphqlTest extends TestCase
{
/**
* @dataProvider getRequests()
*/
public function testBuilder(callable $builderFunction, string $method, string $relativeUri, string $body = null)
{
$builder = new HistoryRequestBuilder();
$request = $builderFunction($builder);
$this->assertSame(strtolower($method), strtolower($request->getMethod()));
$this->assertSame($relativeUri, (string) $request->getUri());
if (!is_null($body)) {
$this->assertJsonStringEqualsJsonString($body, (string) $request->getBody());
} else {
$this->assertSame("", (string) $request->getBody());
}
}



/**
* @dataProvider getRequestBuilderResponses()
*/
public function testMapFromResponse(callable $builderFunction, $statusCode)
{
$builder = new HistoryRequestBuilder();
$request = $builderFunction($builder);
$this->assertInstanceOf(ApiRequest::class, $request);

$response = new Response($statusCode, [], "{}");
$this->assertInstanceOf(JsonObject::class, $request->mapFromResponse($response));
}

/**
* @dataProvider getRequestBuilders()
*/
public function testExecuteClientException(callable $builderFunction)
{
$client = $this->createMock(ClientInterface::class);

$builder = new HistoryRequestBuilder($client);
$request = $builderFunction($builder);
$client->method("send")->willThrowException(new ClientException("Oops!", $request, new Response(400)));

$this->expectException(ApiClientException::class);
$request->execute();
}

/**
* @dataProvider getRequestBuilders()
*/
public function testExecuteServerException(callable $builderFunction)
{
$client = $this->createMock(ClientInterface::class);

$builder = new HistoryRequestBuilder($client);
$request = $builderFunction($builder);
$client->method("send")->willThrowException(new ServerException("Oops!", $request, new Response(500)));

$this->expectException(ApiServerException::class);
$request->execute();
}

public function getRequests()
{
return [
'ByProjectKeyGraphqlPost' => [
function (HistoryRequestBuilder $builder): RequestInterface {
return $builder
->withProjectKeyValue("test_projectKey")
->graphql()
->post(null);
},
'post',
'test_projectKey/graphql',
]
];
}

public function getResources()
{
return [
];
}

public function getRequestBuilders()
{
return [
'ByProjectKeyGraphqlPost' => [
function (HistoryRequestBuilder $builder): RequestInterface {
return $builder
->withProjectKeyValue("projectKey")
->graphql()
->post(null);
}
]
];
}

public function getRequestBuilderResponses()
{
return [
'ByProjectKeyGraphqlPost_200' => [
function (HistoryRequestBuilder $builder): RequestInterface {
return $builder
->withProjectKeyValue("projectKey")
->graphql()
->post(null);
},
200
],
'ByProjectKeyGraphqlPost_599' => [
function (HistoryRequestBuilder $builder): RequestInterface {
return $builder
->withProjectKeyValue("projectKey")
->graphql()
->post(null);
},
599
]
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use GuzzleHttp\Exception\ServerException;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Psr7\Response;
use Commercetools\History\Client\Resource\ResourceByProjectKeyGraphql;
use Commercetools\History\Client\Resource\ResourceByProjectKeyByResourceType;

/**
Expand Down Expand Up @@ -295,6 +296,16 @@ function (HistoryRequestBuilder $builder): RequestInterface {
public function getResources()
{
return [
'ResourceByProjectKeyGraphql' => [
function (HistoryRequestBuilder $builder): ResourceByProjectKeyGraphql {
return $builder
->withProjectKeyValue("test_projectKey")
->graphql();
},
ResourceByProjectKeyGraphql::class,
['projectKey' => 'test_projectKey'],
'/{projectKey}/graphql'
],
'ResourceByProjectKeyByResourceType' => [
function (HistoryRequestBuilder $builder): ResourceByProjectKeyByResourceType {
return $builder
Expand Down
14 changes: 14 additions & 0 deletions lib/commercetools-history/docs/RequestBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,17 @@ $request = $builder
->withIDValue("ID")
->get();
```
## `withProjectKeyValue("projectKey")->graphql()->post(null)`

Execute a GraphQL request.

### Example
```php
use Commercetools\History\Client\HistoryRequestBuilder;

$builder = new HistoryRequestBuilder();
$request = $builder
->withProjectKeyValue("projectKey")
->graphql()
->post(null);
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<?php

declare(strict_types=1);
/**
* This file has been auto generated
* Do not change it.
*/

namespace Commercetools\History\Client\Resource;

use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Exception\ServerException;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Promise\PromiseInterface;
use Commercetools\Exception\ExceptionFactory;
use Commercetools\Exception\InvalidArgumentException;
use Commercetools\Exception\ApiServerException;
use Commercetools\Exception\ApiClientException;
use Commercetools\Client\ApiRequest;
use Commercetools\Base\JsonObject;
use Commercetools\Base\JsonObjectModel;
use Commercetools\History\Models\GraphQl\GraphQLResponse;
use Commercetools\History\Models\GraphQl\GraphQLResponseModel;

use Psr\Http\Message\ResponseInterface;

/**
* @psalm-suppress PropertyNotSetInConstructor
*
*/
class ByProjectKeyGraphqlPost extends ApiRequest
{
/**
* @param ?object|array|string $body
* @psalm-param array<string, scalar|scalar[]> $headers
*/
public function __construct(string $projectKey, $body = null, array $headers = [], ClientInterface $client = null)
{
$uri = str_replace(['{projectKey}'], [$projectKey], '{projectKey}/graphql');
parent::__construct($client, 'POST', $uri, $headers, is_object($body) || is_array($body) ? json_encode($body) : $body);
}

/**
* @template T of JsonObject
* @psalm-param ?class-string<T> $resultType
* @return GraphQLResponse|JsonObject|T|null
*/
public function mapFromResponse(?ResponseInterface $response, string $resultType = null)
{
if (is_null($response)) {
return null;
}
if (is_null($resultType)) {
switch ($response->getStatusCode()) {
case '200':
$resultType = GraphQLResponseModel::class;

break;
default:
$resultType = JsonObjectModel::class;

break;
}
}

return $resultType::of($this->responseData($response));
}

/**
* @template T of JsonObject
* @psalm-param ?class-string<T> $resultType
*
* @return null|T|GraphQLResponse|JsonObject
*/
public function execute(array $options = [], string $resultType = null)
{
try {
$response = $this->send($options);
} catch (ServerException $e) {
$response = $e->getResponse();
$e = ExceptionFactory::createServerException($e, $this, $response, $this->mapFromResponse($response, $resultType));
throw $e;
} catch (ClientException $e) {
$response = $e->getResponse();
$e = ExceptionFactory::createClientException($e, $this, $response, $this->mapFromResponse($response, $resultType));
throw $e;
}

return $this->mapFromResponse($response, $resultType);
}

/**
* @template T of JsonObject
* @psalm-param ?class-string<T> $resultType
*
* @return PromiseInterface
*/
public function executeAsync(array $options = [], string $resultType = null)
{
return $this->sendAsync($options)->then(
function(ResponseInterface $response) use ($resultType) {
return $this->mapFromResponse($response, $resultType);
},
function (RequestException $e) use ($resultType) {
$response = $e->getResponse();
if ($e instanceof ServerException) {
$e = ExceptionFactory::createServerException($e, $this, $response, $this->mapFromResponse($response, $resultType));
}
if ($e instanceof ClientException) {
$e = ExceptionFactory::createClientException($e, $this, $response, $this->mapFromResponse($response, $resultType));
}
throw $e;
}
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ public function __construct(array $args = [], ClientInterface $client = null) {
parent::__construct('/{projectKey}', $args, $client);
}

/**
*/
public function graphql(): ResourceByProjectKeyGraphql
{
$args = $this->getArgs();

return new ResourceByProjectKeyGraphql($args, $this->getClient());
}
/**
*/
public function withResourceTypeValue(string $resourceType = null): ResourceByProjectKeyByResourceType
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);
/**
* This file has been auto generated
* Do not change it.
*/

namespace Commercetools\History\Client\Resource;

use Commercetools\Client\ApiResource;
use GuzzleHttp\ClientInterface;
use Psr\Http\Message\UploadedFileInterface;
use Commercetools\History\Models\GraphQl\GraphQLRequest;

/**
* @psalm-suppress PropertyNotSetInConstructor
*/
class ResourceByProjectKeyGraphql extends ApiResource
{
/**
* @psalm-param array<string, string> $args
*/
public function __construct(array $args = [], ClientInterface $client = null) {
parent::__construct('/{projectKey}/graphql', $args, $client);
}

/**
* @psalm-param ?GraphQLRequest $body
* @psalm-param array<string, scalar|scalar[]> $headers
*/
public function post(?GraphQLRequest $body = null, array $headers = []): ByProjectKeyGraphqlPost
{
$args = $this->getArgs();

return new ByProjectKeyGraphqlPost($args['projectKey'], $body, $headers, $this->getClient());
}

}
Loading

0 comments on commit a1b7145

Please sign in to comment.