Skip to content

Commit f8b9536

Browse files
committed
MAGETWO-87264: Finalizing - refactoring code for Pr
1 parent 7be91c1 commit f8b9536

File tree

1 file changed

+21
-6
lines changed
  • dev/tests/api-functional/framework/Magento/TestFramework/TestCase/GraphQl

1 file changed

+21
-6
lines changed

dev/tests/api-functional/framework/Magento/TestFramework/TestCase/GraphQl/Client.php

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,25 @@ public function postQuery(string $query, array $variables = [], string $operatio
6767
$responseBody = $this->curlClient->post($url, $postData, $headers);
6868
$responseBodyArray = $this->json->jsonDecode($responseBody);
6969

70+
if (!is_array($responseBodyArray)) {
71+
throw new \Exception('Unknown GraphQL response body: ' . json_encode($responseBodyArray));
72+
}
73+
74+
$this->processErrors($responseBodyArray);
75+
76+
if (!isset($responseBodyArray['data'])) {
77+
throw new \Exception('Unknown GraphQL response body: ' . json_encode($responseBodyArray));
78+
} else {
79+
return $responseBodyArray['data'];
80+
}
81+
}
82+
83+
/**
84+
* @param array $responseBodyArray
85+
* @throws \Exception
86+
*/
87+
private function processErrors($responseBodyArray)
88+
{
7089
if (isset($responseBodyArray['errors'])) {
7190
$errorMessage = '';
7291
if (is_array($responseBodyArray['errors'])) {
@@ -85,12 +104,8 @@ public function postQuery(string $query, array $variables = [], string $operatio
85104

86105
throw new \Exception('GraphQL response contains errors: ' . $errorMessage);
87106
}
88-
throw new \Exception('GraphQL responded with an unknown error: ' . $responseBody);
89-
} elseif (!isset($responseBodyArray['data'])) {
90-
throw new \Exception('Unknown GraphQL response body: ' . $responseBody);
107+
throw new \Exception('GraphQL responded with an unknown error: ' . json_encode($responseBodyArray));
91108
}
92-
93-
return $responseBodyArray['data'];
94109
}
95110

96111
/**
@@ -99,6 +114,6 @@ public function postQuery(string $query, array $variables = [], string $operatio
99114
*/
100115
public function getEndpointUrl()
101116
{
102-
return rtrim(TESTS_BASE_URL, '/') . '/graphql';
117+
return rtrim(TESTS_BASE_URL, '/') . '/graphql5';
103118
}
104119
}

0 commit comments

Comments
 (0)