Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update generated SDKs #291

Merged
merged 1 commit into from
Jan 2, 2025
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
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;

Check warning on line 53 in lib/commercetools-history/src/Client/Resource/ByProjectKeyGraphqlPost.php

View check run for this annotation

Codecov / codecov/patch

lib/commercetools-history/src/Client/Resource/ByProjectKeyGraphqlPost.php#L53

Added line #L53 was not covered by tests
}
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);

Check warning on line 91 in lib/commercetools-history/src/Client/Resource/ByProjectKeyGraphqlPost.php

View check run for this annotation

Codecov / codecov/patch

lib/commercetools-history/src/Client/Resource/ByProjectKeyGraphqlPost.php#L91

Added line #L91 was not covered by tests
}

/**
* @template T of JsonObject
* @psalm-param ?class-string<T> $resultType
*
* @return PromiseInterface
*/
public function executeAsync(array $options = [], string $resultType = null)

Check warning on line 100 in lib/commercetools-history/src/Client/Resource/ByProjectKeyGraphqlPost.php

View check run for this annotation

Codecov / codecov/patch

lib/commercetools-history/src/Client/Resource/ByProjectKeyGraphqlPost.php#L100

Added line #L100 was not covered by tests
{
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));

Check warning on line 109 in lib/commercetools-history/src/Client/Resource/ByProjectKeyGraphqlPost.php

View check run for this annotation

Codecov / codecov/patch

lib/commercetools-history/src/Client/Resource/ByProjectKeyGraphqlPost.php#L102-L109

Added lines #L102 - L109 were not covered by tests
}
if ($e instanceof ClientException) {
$e = ExceptionFactory::createClientException($e, $this, $response, $this->mapFromResponse($response, $resultType));

Check warning on line 112 in lib/commercetools-history/src/Client/Resource/ByProjectKeyGraphqlPost.php

View check run for this annotation

Codecov / codecov/patch

lib/commercetools-history/src/Client/Resource/ByProjectKeyGraphqlPost.php#L111-L112

Added lines #L111 - L112 were not covered by tests
}
throw $e;

Check warning on line 114 in lib/commercetools-history/src/Client/Resource/ByProjectKeyGraphqlPost.php

View check run for this annotation

Codecov / codecov/patch

lib/commercetools-history/src/Client/Resource/ByProjectKeyGraphqlPost.php#L114

Added line #L114 was not covered by tests
}
);
}

}
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
Loading