@@ -67,6 +67,25 @@ public function postQuery(string $query, array $variables = [], string $operatio
67
67
$ responseBody = $ this ->curlClient ->post ($ url , $ postData , $ headers );
68
68
$ responseBodyArray = $ this ->json ->jsonDecode ($ responseBody );
69
69
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
+ {
70
89
if (isset ($ responseBodyArray ['errors ' ])) {
71
90
$ errorMessage = '' ;
72
91
if (is_array ($ responseBodyArray ['errors ' ])) {
@@ -85,12 +104,8 @@ public function postQuery(string $query, array $variables = [], string $operatio
85
104
86
105
throw new \Exception ('GraphQL response contains errors: ' . $ errorMessage );
87
106
}
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 ));
91
108
}
92
-
93
- return $ responseBodyArray ['data ' ];
94
109
}
95
110
96
111
/**
@@ -99,6 +114,6 @@ public function postQuery(string $query, array $variables = [], string $operatio
99
114
*/
100
115
public function getEndpointUrl ()
101
116
{
102
- return rtrim (TESTS_BASE_URL , '/ ' ) . '/graphql ' ;
117
+ return rtrim (TESTS_BASE_URL , '/ ' ) . '/graphql5 ' ;
103
118
}
104
119
}
0 commit comments