Skip to content

Commit d91a4b2

Browse files
committed
build(codegen): updating SDK
1 parent 28445c6 commit d91a4b2

32 files changed

+2231
-0
lines changed

changes.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,29 @@
7575

7676
**History changes**
7777

78+
<details>
79+
<summary>Added Resource(s)</summary>
80+
81+
- added resource `/{projectKey}/graphql`
82+
</details>
83+
84+
85+
<details>
86+
<summary>Added Method(s)</summary>
87+
88+
- added method `$apiRoot->withProjectKeyValue()->graphql()->post()`
89+
</details>
90+
91+
7892
<details>
7993
<summary>Added Type(s)</summary>
8094

95+
- added type `GraphQLRequest`
96+
- added type `GraphQLResponse`
97+
- added type `GraphQLError`
98+
- added type `GraphQLErrorLocation`
99+
- added type `GraphQLVariablesMap`
100+
- added type `GraphQLErrorObject`
81101
- added type `ChangeTargetPatternChangeValue`
82102
- added type `PatternComponent`
83103
</details>
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* This file has been auto generated
6+
* Do not change it.
7+
*/
8+
9+
namespace Commercetools\History\Test\Client\Resource;
10+
11+
use PHPUnit\Framework\TestCase;
12+
use Commercetools\Exception\ApiClientException;
13+
use Commercetools\Exception\ApiServerException;
14+
use Commercetools\Client\ApiRequest;
15+
use Commercetools\Base\JsonObject;
16+
use Commercetools\History\Client\HistoryRequestBuilder;
17+
use Psr\Http\Message\RequestInterface;
18+
use GuzzleHttp\Exception\ClientException;
19+
use GuzzleHttp\Exception\ServerException;
20+
use GuzzleHttp\ClientInterface;
21+
use GuzzleHttp\Psr7\Response;
22+
23+
/**
24+
* @covers \Commercetools\History\Client\Resource\ByProjectKeyGraphqlPost
25+
* @covers \Commercetools\History\Client\Resource\ResourceByProjectKeyGraphql
26+
*/
27+
class ResourceByProjectKeyGraphqlTest extends TestCase
28+
{
29+
/**
30+
* @dataProvider getRequests()
31+
*/
32+
public function testBuilder(callable $builderFunction, string $method, string $relativeUri, string $body = null)
33+
{
34+
$builder = new HistoryRequestBuilder();
35+
$request = $builderFunction($builder);
36+
$this->assertSame(strtolower($method), strtolower($request->getMethod()));
37+
$this->assertSame($relativeUri, (string) $request->getUri());
38+
if (!is_null($body)) {
39+
$this->assertJsonStringEqualsJsonString($body, (string) $request->getBody());
40+
} else {
41+
$this->assertSame("", (string) $request->getBody());
42+
}
43+
}
44+
45+
46+
47+
/**
48+
* @dataProvider getRequestBuilderResponses()
49+
*/
50+
public function testMapFromResponse(callable $builderFunction, $statusCode)
51+
{
52+
$builder = new HistoryRequestBuilder();
53+
$request = $builderFunction($builder);
54+
$this->assertInstanceOf(ApiRequest::class, $request);
55+
56+
$response = new Response($statusCode, [], "{}");
57+
$this->assertInstanceOf(JsonObject::class, $request->mapFromResponse($response));
58+
}
59+
60+
/**
61+
* @dataProvider getRequestBuilders()
62+
*/
63+
public function testExecuteClientException(callable $builderFunction)
64+
{
65+
$client = $this->createMock(ClientInterface::class);
66+
67+
$builder = new HistoryRequestBuilder($client);
68+
$request = $builderFunction($builder);
69+
$client->method("send")->willThrowException(new ClientException("Oops!", $request, new Response(400)));
70+
71+
$this->expectException(ApiClientException::class);
72+
$request->execute();
73+
}
74+
75+
/**
76+
* @dataProvider getRequestBuilders()
77+
*/
78+
public function testExecuteServerException(callable $builderFunction)
79+
{
80+
$client = $this->createMock(ClientInterface::class);
81+
82+
$builder = new HistoryRequestBuilder($client);
83+
$request = $builderFunction($builder);
84+
$client->method("send")->willThrowException(new ServerException("Oops!", $request, new Response(500)));
85+
86+
$this->expectException(ApiServerException::class);
87+
$request->execute();
88+
}
89+
90+
public function getRequests()
91+
{
92+
return [
93+
'ByProjectKeyGraphqlPost' => [
94+
function (HistoryRequestBuilder $builder): RequestInterface {
95+
return $builder
96+
->withProjectKeyValue("test_projectKey")
97+
->graphql()
98+
->post(null);
99+
},
100+
'post',
101+
'test_projectKey/graphql',
102+
]
103+
];
104+
}
105+
106+
public function getResources()
107+
{
108+
return [
109+
];
110+
}
111+
112+
public function getRequestBuilders()
113+
{
114+
return [
115+
'ByProjectKeyGraphqlPost' => [
116+
function (HistoryRequestBuilder $builder): RequestInterface {
117+
return $builder
118+
->withProjectKeyValue("projectKey")
119+
->graphql()
120+
->post(null);
121+
}
122+
]
123+
];
124+
}
125+
126+
public function getRequestBuilderResponses()
127+
{
128+
return [
129+
'ByProjectKeyGraphqlPost_200' => [
130+
function (HistoryRequestBuilder $builder): RequestInterface {
131+
return $builder
132+
->withProjectKeyValue("projectKey")
133+
->graphql()
134+
->post(null);
135+
},
136+
200
137+
],
138+
'ByProjectKeyGraphqlPost_599' => [
139+
function (HistoryRequestBuilder $builder): RequestInterface {
140+
return $builder
141+
->withProjectKeyValue("projectKey")
142+
->graphql()
143+
->post(null);
144+
},
145+
599
146+
]
147+
];
148+
}
149+
}

lib/commercetools-history-tests/test/unit/Client/Resource/ResourceByProjectKeyTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use GuzzleHttp\Exception\ServerException;
2020
use GuzzleHttp\ClientInterface;
2121
use GuzzleHttp\Psr7\Response;
22+
use Commercetools\History\Client\Resource\ResourceByProjectKeyGraphql;
2223
use Commercetools\History\Client\Resource\ResourceByProjectKeyByResourceType;
2324

2425
/**
@@ -295,6 +296,16 @@ function (HistoryRequestBuilder $builder): RequestInterface {
295296
public function getResources()
296297
{
297298
return [
299+
'ResourceByProjectKeyGraphql' => [
300+
function (HistoryRequestBuilder $builder): ResourceByProjectKeyGraphql {
301+
return $builder
302+
->withProjectKeyValue("test_projectKey")
303+
->graphql();
304+
},
305+
ResourceByProjectKeyGraphql::class,
306+
['projectKey' => 'test_projectKey'],
307+
'/{projectKey}/graphql'
308+
],
298309
'ResourceByProjectKeyByResourceType' => [
299310
function (HistoryRequestBuilder $builder): ResourceByProjectKeyByResourceType {
300311
return $builder

lib/commercetools-history/docs/RequestBuilder.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,17 @@ $request = $builder
5050
->withIDValue("ID")
5151
->get();
5252
```
53+
## `withProjectKeyValue("projectKey")->graphql()->post(null)`
54+
55+
Execute a GraphQL request.
56+
57+
### Example
58+
```php
59+
use Commercetools\History\Client\HistoryRequestBuilder;
60+
61+
$builder = new HistoryRequestBuilder();
62+
$request = $builder
63+
->withProjectKeyValue("projectKey")
64+
->graphql()
65+
->post(null);
66+
```
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* This file has been auto generated
6+
* Do not change it.
7+
*/
8+
9+
namespace Commercetools\History\Client\Resource;
10+
11+
use GuzzleHttp\ClientInterface;
12+
use GuzzleHttp\Exception\RequestException;
13+
use GuzzleHttp\Exception\ServerException;
14+
use GuzzleHttp\Exception\ClientException;
15+
use GuzzleHttp\Promise\PromiseInterface;
16+
use Commercetools\Exception\ExceptionFactory;
17+
use Commercetools\Exception\InvalidArgumentException;
18+
use Commercetools\Exception\ApiServerException;
19+
use Commercetools\Exception\ApiClientException;
20+
use Commercetools\Client\ApiRequest;
21+
use Commercetools\Base\JsonObject;
22+
use Commercetools\Base\JsonObjectModel;
23+
use Commercetools\History\Models\GraphQl\GraphQLResponse;
24+
use Commercetools\History\Models\GraphQl\GraphQLResponseModel;
25+
26+
use Psr\Http\Message\ResponseInterface;
27+
28+
/**
29+
30+
* @psalm-suppress PropertyNotSetInConstructor
31+
*
32+
*/
33+
class ByProjectKeyGraphqlPost extends ApiRequest
34+
{
35+
/**
36+
* @param ?object|array|string $body
37+
* @psalm-param array<string, scalar|scalar[]> $headers
38+
*/
39+
public function __construct(string $projectKey, $body = null, array $headers = [], ClientInterface $client = null)
40+
{
41+
$uri = str_replace(['{projectKey}'], [$projectKey], '{projectKey}/graphql');
42+
parent::__construct($client, 'POST', $uri, $headers, is_object($body) || is_array($body) ? json_encode($body) : $body);
43+
}
44+
45+
/**
46+
* @template T of JsonObject
47+
* @psalm-param ?class-string<T> $resultType
48+
* @return GraphQLResponse|JsonObject|T|null
49+
*/
50+
public function mapFromResponse(?ResponseInterface $response, string $resultType = null)
51+
{
52+
if (is_null($response)) {
53+
return null;
54+
}
55+
if (is_null($resultType)) {
56+
switch ($response->getStatusCode()) {
57+
case '200':
58+
$resultType = GraphQLResponseModel::class;
59+
60+
break;
61+
default:
62+
$resultType = JsonObjectModel::class;
63+
64+
break;
65+
}
66+
}
67+
68+
return $resultType::of($this->responseData($response));
69+
}
70+
71+
/**
72+
* @template T of JsonObject
73+
* @psalm-param ?class-string<T> $resultType
74+
*
75+
* @return null|T|GraphQLResponse|JsonObject
76+
*/
77+
public function execute(array $options = [], string $resultType = null)
78+
{
79+
try {
80+
$response = $this->send($options);
81+
} catch (ServerException $e) {
82+
$response = $e->getResponse();
83+
$e = ExceptionFactory::createServerException($e, $this, $response, $this->mapFromResponse($response, $resultType));
84+
throw $e;
85+
} catch (ClientException $e) {
86+
$response = $e->getResponse();
87+
$e = ExceptionFactory::createClientException($e, $this, $response, $this->mapFromResponse($response, $resultType));
88+
throw $e;
89+
}
90+
91+
return $this->mapFromResponse($response, $resultType);
92+
}
93+
94+
/**
95+
* @template T of JsonObject
96+
* @psalm-param ?class-string<T> $resultType
97+
*
98+
* @return PromiseInterface
99+
*/
100+
public function executeAsync(array $options = [], string $resultType = null)
101+
{
102+
return $this->sendAsync($options)->then(
103+
function(ResponseInterface $response) use ($resultType) {
104+
return $this->mapFromResponse($response, $resultType);
105+
},
106+
function (RequestException $e) use ($resultType) {
107+
$response = $e->getResponse();
108+
if ($e instanceof ServerException) {
109+
$e = ExceptionFactory::createServerException($e, $this, $response, $this->mapFromResponse($response, $resultType));
110+
}
111+
if ($e instanceof ClientException) {
112+
$e = ExceptionFactory::createClientException($e, $this, $response, $this->mapFromResponse($response, $resultType));
113+
}
114+
throw $e;
115+
}
116+
);
117+
}
118+
119+
}

lib/commercetools-history/src/Client/Resource/ResourceByProjectKey.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ public function __construct(array $args = [], ClientInterface $client = null) {
2424
parent::__construct('/{projectKey}', $args, $client);
2525
}
2626

27+
/**
28+
*/
29+
public function graphql(): ResourceByProjectKeyGraphql
30+
{
31+
$args = $this->getArgs();
32+
33+
return new ResourceByProjectKeyGraphql($args, $this->getClient());
34+
}
2735
/**
2836
*/
2937
public function withResourceTypeValue(string $resourceType = null): ResourceByProjectKeyByResourceType
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* This file has been auto generated
6+
* Do not change it.
7+
*/
8+
9+
namespace Commercetools\History\Client\Resource;
10+
11+
use Commercetools\Client\ApiResource;
12+
use GuzzleHttp\ClientInterface;
13+
use Psr\Http\Message\UploadedFileInterface;
14+
use Commercetools\History\Models\GraphQl\GraphQLRequest;
15+
16+
/**
17+
* @psalm-suppress PropertyNotSetInConstructor
18+
*/
19+
class ResourceByProjectKeyGraphql extends ApiResource
20+
{
21+
/**
22+
* @psalm-param array<string, string> $args
23+
*/
24+
public function __construct(array $args = [], ClientInterface $client = null) {
25+
parent::__construct('/{projectKey}/graphql', $args, $client);
26+
}
27+
28+
/**
29+
* @psalm-param ?GraphQLRequest $body
30+
* @psalm-param array<string, scalar|scalar[]> $headers
31+
*/
32+
public function post(?GraphQLRequest $body = null, array $headers = []): ByProjectKeyGraphqlPost
33+
{
34+
$args = $this->getArgs();
35+
36+
return new ByProjectKeyGraphqlPost($args['projectKey'], $body, $headers, $this->getClient());
37+
}
38+
39+
}

0 commit comments

Comments
 (0)